606
|
1 |
#
|
|
2 |
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# This package contains fuctions specific to data drive image generation
|
|
16 |
#
|
|
17 |
|
|
18 |
|
|
19 |
package datadriveimage;
|
|
20 |
|
|
21 |
require Exporter;
|
|
22 |
@ISA=qw(Exporter);
|
|
23 |
@EXPORT=qw(
|
|
24 |
createDirectory
|
|
25 |
deleteDirectory
|
|
26 |
checkInArray
|
|
27 |
setPath
|
|
28 |
locateStubsisfiles
|
|
29 |
copyFilesToFolders
|
|
30 |
checkForSisFile
|
|
31 |
copyNonSisFiles
|
|
32 |
invokeInterpretsis
|
|
33 |
invokeReadImage
|
|
34 |
compareArrays
|
|
35 |
dumpDatadriveObydata
|
|
36 |
TraverseDir
|
|
37 |
writeDataToFile
|
|
38 |
generate_datadriveheader
|
|
39 |
checkForWhiteSpace
|
|
40 |
reportError
|
|
41 |
);
|
|
42 |
|
|
43 |
use strict;
|
|
44 |
use File::Path; # Module to provide functions to remove or create directories in a convenient way.
|
|
45 |
use File::Copy; # Module to provide functions to copy file(s) from source to destination.
|
|
46 |
|
|
47 |
use Cwd; # Module to provide functions for determining the pathname of the current working directory.
|
|
48 |
|
|
49 |
use romutl;
|
|
50 |
use romosvariant;
|
|
51 |
|
|
52 |
# This fuction is used primiarly to check for whitespace in the location for "zdrive" / "datadrive" folder creation,
|
|
53 |
# specified by the user, if yes then it returns one, else zero
|
|
54 |
sub checkForWhiteSpace
|
|
55 |
{
|
|
56 |
my ($dirLoc,$dirName) = @_;
|
|
57 |
if( $dirLoc =~ m/ / )
|
|
58 |
{
|
|
59 |
print "* Warning: $dirLoc contains whitespace, hence $dirName will be created in default location \n";
|
|
60 |
return 1;
|
|
61 |
}
|
|
62 |
else
|
|
63 |
{
|
|
64 |
return 0;
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
# This function reports the appropriate meassage supplied to it
|
|
70 |
# and does a exit if and only if keepgoing option is disabled.
|
|
71 |
sub reportError
|
|
72 |
{
|
|
73 |
my( $message,$keepgoingOpt ) = @_;
|
|
74 |
# print the specified meassage.
|
|
75 |
print STDERR "$message \n";
|
|
76 |
# bail out, if keepgoing option is not set.
|
|
77 |
exit(1) if (!$keepgoingOpt);
|
|
78 |
}
|
|
79 |
|
|
80 |
# generate header for final datadrive oby file.
|
|
81 |
sub generate_datadriveheader
|
|
82 |
{
|
|
83 |
my ($idx,$datadriveimage) = @_;
|
|
84 |
my $header;
|
|
85 |
$header = "dataimagename=$$datadriveimage[$idx]{name}.img\n";
|
|
86 |
$header .= "dataimagefilesystem=$$datadriveimage[$idx]{fstype}\n";
|
|
87 |
|
|
88 |
# check whether the size of the image has been mentioned
|
|
89 |
if(defined($$datadriveimage[$idx]{size}))
|
|
90 |
{
|
|
91 |
$header .= "dataimagesize=$$datadriveimage[$idx]{size}\n\n";
|
|
92 |
}
|
|
93 |
return $header;
|
|
94 |
}
|
|
95 |
|
|
96 |
# Create the specified directory by making use of mkpath function
|
|
97 |
# from File::Path module.
|
|
98 |
sub createDirectory
|
|
99 |
{
|
|
100 |
my($dir) = @_;
|
|
101 |
if( !-d $dir )
|
|
102 |
{
|
|
103 |
mkpath($dir);
|
|
104 |
if (! -e $dir)
|
|
105 |
{
|
|
106 |
print ("ERROR: Couldn't create $dir\n");
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
# check if the given file is a reg file or ctl file or a txt file
|
|
112 |
# if it is any of these files then return true else false.
|
|
113 |
# This check is need since these three files or not valid not valid e32 file
|
|
114 |
# and hence needs to be placed as an data file inside the image.
|
|
115 |
sub checkRegCtlFiles
|
|
116 |
{
|
|
117 |
my ($fileName) = @_;
|
|
118 |
|
|
119 |
# check whether the file has "reg","ctl" or "txt" extension.
|
|
120 |
if( $fileName =~/\.(reg|ctl|txt)$/i )
|
|
121 |
{
|
|
122 |
return 1;
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
return 0;
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
# delete the given directory by making use of rmtree function
|
|
131 |
# from File::Path module.
|
|
132 |
sub deleteDirectory
|
|
133 |
{
|
|
134 |
my($dir,$verboseOpt) = @_;
|
|
135 |
# check whether the directory exists.
|
|
136 |
if( -d $dir )
|
|
137 |
{
|
|
138 |
print("found $dir directory \n") if($verboseOpt);
|
|
139 |
if(rmtree($dir))
|
|
140 |
{
|
|
141 |
print("$dir directory deleted \n") if($verboseOpt);
|
|
142 |
return 0;
|
|
143 |
}
|
|
144 |
else
|
|
145 |
{
|
|
146 |
print("$dir directory could'nt be deleted \n") if($verboseOpt);
|
|
147 |
return 1;
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
# check for processed data drive image index.
|
|
153 |
# if there is a match return one else return zero.
|
|
154 |
# this check is done in order to ensure data drive image index is not repeated.
|
|
155 |
sub checkInArray
|
|
156 |
{
|
|
157 |
my($array, $value) = @_;
|
|
158 |
foreach my $aLine(@$array)
|
|
159 |
{
|
|
160 |
if( $aLine eq $value )
|
|
161 |
{
|
|
162 |
return 0;
|
|
163 |
}
|
|
164 |
}
|
|
165 |
return 1;
|
|
166 |
}
|
|
167 |
|
|
168 |
# set the path for the given directory.
|
|
169 |
sub setPath
|
|
170 |
{
|
|
171 |
my($dirName) = @_;
|
|
172 |
# get the working directory.
|
|
173 |
my $curWorkingDir = getcwd;
|
|
174 |
# substitute slash with double backward slash.
|
|
175 |
$curWorkingDir =~ s/\\/\//g;
|
|
176 |
#if $curWorkingDir already has trailing '\', don't include it again
|
|
177 |
if( $curWorkingDir =~ /\/$/)
|
|
178 |
{
|
|
179 |
return $curWorkingDir.$dirName;
|
|
180 |
}
|
|
181 |
else
|
|
182 |
{
|
|
183 |
return $curWorkingDir."\/".$dirName;
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
# create directory and copy respective file on to that directory.
|
|
188 |
# is there is a problem while copying files from source to destination
|
|
189 |
# then bail out if and only if keep going option is disabled.
|
|
190 |
sub copyFilesToFolders
|
|
191 |
{
|
|
192 |
my ($source,$dest,$dir,$verboseOpt) = @_;
|
|
193 |
$source =~ s/\"//g; # remove double quotes from the string.
|
|
194 |
my $destFileName = ""; # name of the destination file.
|
|
195 |
$dest =~ s/\"//g; # remove double quotes from the string.
|
|
196 |
my $destDirectory = $dest;
|
|
197 |
# strip the last substring to get destination file
|
|
198 |
if ($dest=~/.*[\/\\](\S+)/)
|
|
199 |
{
|
|
200 |
$destFileName = $1;
|
|
201 |
}
|
|
202 |
else
|
|
203 |
{
|
|
204 |
$destFileName = $dest;
|
|
205 |
}
|
|
206 |
#get the destination directory along with full path
|
|
207 |
#when "[" and "]" appear in the file name we need add "\" before "[" or "]"
|
|
208 |
#like this: [filename].exe translate to \[filename\].exe
|
|
209 |
if($destFileName =~ /\[|\]/)
|
|
210 |
{
|
|
211 |
my $tempFileName = $destFileName;
|
|
212 |
$tempFileName =~ s/(\[|\])/\\$1/g;
|
|
213 |
$destDirectory =~ s/$tempFileName//;
|
|
214 |
}
|
|
215 |
else
|
|
216 |
{
|
|
217 |
$destDirectory =~ s/$destFileName//;
|
|
218 |
}
|
|
219 |
my $destfile = $dir."\/".$dest;
|
|
220 |
my $createdir = $dir."\/".$destDirectory ;
|
|
221 |
|
|
222 |
# create the specified directory.
|
|
223 |
&createDirectory($createdir);
|
|
224 |
if (!copy($source,$destfile))
|
|
225 |
{
|
|
226 |
warn "warning : $source file could not found \n";
|
|
227 |
return 0;
|
|
228 |
}
|
|
229 |
else
|
|
230 |
{
|
|
231 |
print "$source copied to $destfile\n" if($verboseOpt);
|
|
232 |
return "\"".$destfile."\"";
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
# Make a check for sisfile keyword by reading the specified iby/oby file,
|
|
237 |
# if sisfile keyword is found then push the respective image on to the respective array
|
|
238 |
# and return true.
|
|
239 |
sub checkForSisFile
|
|
240 |
{
|
|
241 |
my($obyfile,$sisFileArray,$sisFilePrestent) = @_;
|
|
242 |
# open the oby file in read only mode.
|
|
243 |
open (DATA, "< $obyfile") or die("* Can't open $obyfile\n");
|
|
244 |
while (my $line =<DATA>)
|
|
245 |
{
|
|
246 |
if($line =~ /^\s*sisfile\s*=\s*(\S+)/i )
|
|
247 |
{
|
|
248 |
# found a sis file.
|
|
249 |
$$sisFilePrestent = 1;
|
|
250 |
# push sis file on to stack.
|
|
251 |
push(@$sisFileArray,$1);
|
|
252 |
next;
|
|
253 |
}
|
|
254 |
}
|
|
255 |
close(DATA);
|
|
256 |
return $$sisFilePrestent;
|
|
257 |
}
|
|
258 |
|
|
259 |
# Make a check for zdriveimagename keyword by reading the specified iby/oby file,
|
|
260 |
# if zdriveimagename keyword is found then push the respective image on to the respective array
|
|
261 |
# and return true.
|
|
262 |
sub checkForZDriveImageKeyword
|
|
263 |
{
|
|
264 |
#$ZDriveImageFilePresent
|
|
265 |
my($obyfile,$ZDriveImageKeywordArray,$ImageFilePresent) = @_;
|
|
266 |
# open the oby file in read only mode.
|
|
267 |
open (DATA, "< $obyfile") or die("* Can't open $obyfile\n");
|
|
268 |
while (my $line =<DATA>)
|
|
269 |
{
|
|
270 |
if($line =~ /^\s*zdriveimagename\s*=\s*(\S+)/i )
|
|
271 |
{
|
|
272 |
# found a Z Drive Image file.
|
|
273 |
$$ImageFilePresent = 1;
|
|
274 |
# push sis file on to stack.
|
|
275 |
push(@$ZDriveImageKeywordArray,$1);
|
|
276 |
next;
|
|
277 |
}
|
|
278 |
}
|
|
279 |
close(DATA);
|
|
280 |
return $$ImageFilePresent;
|
|
281 |
}
|
|
282 |
|
|
283 |
# copy all non-sis file(s) on to prototype data drive folder
|
|
284 |
# which are mentioned under input data drive iby/oby file.
|
|
285 |
sub copyNonSisFiles
|
|
286 |
{
|
|
287 |
my($dir,$obyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt) = @_;
|
|
288 |
open (OBEY ,$obyfile) or die($obyfile."\n");
|
|
289 |
while(my $line =<OBEY>)
|
|
290 |
{
|
|
291 |
if( $line =~ /^(file|data)\s*=\s*(\"[^"]+\")\s+(\"[^"]+\")/i ||
|
|
292 |
$line =~ /^(file|data)\s*=\s*(\"[^"]+\")\s+(\S+)/i ||
|
|
293 |
$line =~ /^(file|data)\s*=\s*(\S+)\s+(\"[^"]+\")/i ||
|
|
294 |
$line =~ /^(file|data)\s*=\s*(\S+)\s+(\S+)/i )
|
|
295 |
{
|
|
296 |
my $keyWord=$1;
|
|
297 |
my $source=$2;
|
|
298 |
my $dest=$3;
|
|
299 |
|
|
300 |
if( $source !~ /(\S+):([^"]+)/ )
|
|
301 |
{
|
|
302 |
$source = get_drive().$2;
|
|
303 |
}
|
|
304 |
my $var = ©FilesToFolders( $source,$dest,$dir,$verboseOpt);
|
|
305 |
if($var)
|
|
306 |
{
|
|
307 |
$line = $keyWord."=".$var."\t".$dest."\n";
|
|
308 |
push(@$nonsisFileArray,$line);
|
|
309 |
}
|
|
310 |
else
|
|
311 |
{
|
|
312 |
exit(1)if(!$keepgoingOpt);
|
|
313 |
}
|
|
314 |
}
|
|
315 |
elsif($line =~ /^rename\s+(\S+)\s+(\S+)/i)
|
|
316 |
{
|
|
317 |
my $oldFile = $dir.$1; # existing-file
|
|
318 |
my $newFile = $dir.$2; # destination-file
|
|
319 |
print"found rename keyword\nrenaming $oldFile to $newFile\n" if ($verboseOpt);
|
|
320 |
if ( rename($oldFile, $newFile) )
|
|
321 |
{
|
|
322 |
# push the line on to the stack.
|
|
323 |
push(@$renameArray,$1."\t".$2."\n");
|
|
324 |
}
|
|
325 |
else
|
|
326 |
{
|
|
327 |
&datadriveimage::reportError("* Warning : can't rename $oldFile to $newFile: $!",$keepgoingOpt);
|
|
328 |
}
|
|
329 |
}
|
|
330 |
elsif($line =~ /^alias\s+(\S+)\s+(\S+)/i)
|
|
331 |
{
|
|
332 |
my $exFile = $dir.$1; # existing-file
|
|
333 |
my $destFile = $dir.$2; # destination-file
|
|
334 |
print"found alias keyword\n" if ($verboseOpt);
|
|
335 |
if(!copy($exFile,$destFile))
|
|
336 |
{
|
|
337 |
&datadriveimage::reportError("* warning : couldnt create alias of $1 to $2 ",$keepgoingOpt);
|
|
338 |
}
|
|
339 |
else
|
|
340 |
{
|
|
341 |
# push the line on to the stack.
|
|
342 |
push(@$aliasArray,$1."\t".$2."\n");
|
|
343 |
}
|
|
344 |
}
|
|
345 |
elsif($line =~ /^hide\s+(\S+)/i)
|
|
346 |
{
|
|
347 |
print"found hide keyword\n" if ($verboseOpt);
|
|
348 |
print "$1 is marked as hidden, hence will not be part of the image\n" if($verboseOpt);
|
|
349 |
if( unlink($dir.$1) )
|
|
350 |
{
|
|
351 |
# push the line on to the stack.
|
|
352 |
push(@$hideArray,$1);
|
|
353 |
}
|
|
354 |
else
|
|
355 |
{
|
|
356 |
&datadriveimage::reportError("* Warning : Can't delete $1: $! ",$keepgoingOpt);
|
|
357 |
}
|
|
358 |
}
|
|
359 |
}
|
|
360 |
close(OBEY);
|
|
361 |
}
|
|
362 |
|
|
363 |
# invoke the INTERPRETSIS tool with appropriate parameters.
|
|
364 |
sub invokeInterpretsis
|
|
365 |
{
|
|
366 |
my($sisFileArray,$dataDrivePath,$verboseOpt,$zDrivePath,$parafile,$keepgoingOpt,$interpretsisOptList) = @_;
|
|
367 |
my $sisfile = "";
|
|
368 |
# default system drive letter is specified since interpretsis doesnt allow overloading of options unless default
|
|
369 |
# options are specified.
|
|
370 |
my $basicOption = "-d C: "; # default system drive letter
|
|
371 |
my $command = "interpretsis ";
|
|
372 |
my $vOption = "-w info" if ($verboseOpt);
|
|
373 |
|
|
374 |
is_existinpath("interpretsis", romutl::DIE_NOT_FOUND);
|
|
375 |
|
|
376 |
# do a check if the path has a white space.
|
|
377 |
if( $dataDrivePath =~ m/ /)
|
|
378 |
{
|
|
379 |
$dataDrivePath = '"'.$dataDrivePath.'"';
|
|
380 |
}
|
|
381 |
|
|
382 |
# find out size of the array
|
|
383 |
my $sisarraysize = scalar(@$sisFileArray);
|
|
384 |
for( my $i=0; $i<$sisarraysize; $i++ )
|
|
385 |
{
|
|
386 |
if($sisfile ne "")
|
|
387 |
{
|
|
388 |
$sisfile = pop(@$sisFileArray).",".$sisfile;
|
|
389 |
}
|
|
390 |
else
|
|
391 |
{
|
|
392 |
$sisfile = pop(@$sisFileArray);
|
|
393 |
}
|
|
394 |
}
|
|
395 |
|
|
396 |
# check whether the directory exists or not
|
|
397 |
if( -d $zDrivePath )
|
|
398 |
{
|
|
399 |
# do a check if the path has a white space.
|
|
400 |
if( $zDrivePath =~ m/ /)
|
|
401 |
{
|
|
402 |
$zDrivePath = '"'.$zDrivePath.'"';
|
|
403 |
}
|
|
404 |
$basicOption .= "-z $zDrivePath ";
|
|
405 |
}
|
|
406 |
|
|
407 |
$basicOption .= "-c $dataDrivePath -s $sisfile $vOption";
|
|
408 |
|
|
409 |
# if parameter file is specified then invoke the INTERPRETSIS
|
|
410 |
# with the specified parameter file with "-p" option.
|
|
411 |
if( defined($parafile) )
|
|
412 |
{
|
|
413 |
# do a check if the path has a white space.
|
|
414 |
if( $parafile =~ m/ /)
|
|
415 |
{
|
|
416 |
$parafile = '"'.$parafile.'"';
|
|
417 |
}
|
|
418 |
$command .= "-p $parafile ";
|
|
419 |
}
|
|
420 |
# else invoke the INTERPRETSIS with default parameter file with "-p" option.
|
|
421 |
else
|
|
422 |
{
|
|
423 |
# Truncate and open the parameter file for writing..
|
|
424 |
open( OPTDATA, "> parameterfile.txt" ) or die "can't open parameterfile.txt";
|
|
425 |
print OPTDATA $basicOption."\n";
|
|
426 |
close( OPTDATA );
|
|
427 |
$command .= "-p parameterfile.txt ";
|
|
428 |
}
|
|
429 |
|
|
430 |
if( $interpretsisOptList )
|
|
431 |
{
|
|
432 |
# find out size of the array
|
|
433 |
my $arraysize = scalar( @$interpretsisOptList );
|
|
434 |
for( my $i = 0; $i < $arraysize; $i++ )
|
|
435 |
{
|
|
436 |
$command .= $$interpretsisOptList[$i]." ";
|
|
437 |
}
|
|
438 |
}
|
|
439 |
|
|
440 |
print "* Executing $command\n" if ( $verboseOpt );
|
|
441 |
system ( $command );
|
|
442 |
|
|
443 |
if ($? != 0)
|
|
444 |
{
|
|
445 |
&datadriveimage::reportError("* ERROR: INTERPRETSIS failed",$keepgoingOpt);
|
|
446 |
}
|
|
447 |
}
|
|
448 |
|
|
449 |
# invoke the READIMAGE tool with appropriate parameters.
|
|
450 |
sub invokeReadImage
|
|
451 |
{
|
|
452 |
my($imageName,$loc,$verboseOpt,$logFile,$keepgoingOpt) = @_;
|
|
453 |
my $command = "readimage ";
|
|
454 |
|
|
455 |
is_existinpath("readimage", romutl::DIE_NOT_FOUND);
|
|
456 |
|
|
457 |
# check if log file has been supplied.
|
|
458 |
if(defined($logFile))
|
|
459 |
{
|
|
460 |
if( $logFile =~ m/ /)
|
|
461 |
{
|
|
462 |
$logFile = '"'.$logFile.'"';
|
|
463 |
}
|
|
464 |
$command .= "-l $logFile ";
|
|
465 |
}
|
|
466 |
|
|
467 |
# do a check if the path has a white space.
|
|
468 |
if( $loc =~ m/ /)
|
|
469 |
{
|
|
470 |
$loc = '"'.$loc.'"';
|
|
471 |
}
|
|
472 |
$command .= "-z ".$loc." ".$imageName;
|
|
473 |
print "* Executing $command\n" if ($verboseOpt);
|
|
474 |
system ($command);
|
|
475 |
if ($? != 0)
|
|
476 |
{
|
|
477 |
&datadriveimage::reportError("* ERROR: READIMAGE failed to read the image",$keepgoingOpt);
|
|
478 |
return 0;
|
|
479 |
}
|
|
480 |
return 1;
|
|
481 |
}
|
|
482 |
|
|
483 |
# Each line from the OBY file is read and if any of the line contains "rename"/ "alias" keyword
|
|
484 |
# then that corresponding line source and line destination is obtained and is passed to this function as one of the parameters.
|
|
485 |
# This fuction compares given array with non-sis file(s) array, when an given line destination matches with the destination of an
|
|
486 |
# element in the rename array/alias array(array holding list of file(s) that are renamed / made alias) then,
|
|
487 |
# that respective element is removed from the rename array and a further check is made to see whether the given
|
|
488 |
# line source matches with the destination of an element in the rename array/alias array.If a match is found then
|
|
489 |
# a keyword check is done,if the keyword is "rename" then corresponding element's source and destination file is replaced
|
|
490 |
# with given line destination file and if the keyword is "alias" then a new element will be added to non sis file array
|
|
491 |
# with line destination file as the source and destination file.
|
|
492 |
sub compareArrays
|
|
493 |
{
|
|
494 |
my ( $firstarray,$nonsisArray,$linesource,$linedest,$linekeyword ) = @_;
|
|
495 |
# count of array element(s).
|
|
496 |
my $firstArrayCount = 0;
|
|
497 |
# source file.
|
|
498 |
my $linesourceFile;
|
|
499 |
# destination file.
|
|
500 |
my $linedestFile;
|
|
501 |
# get source file.
|
|
502 |
|
|
503 |
# strip first occurrence of back slash
|
|
504 |
$linesource =~ s/[\/\\]//;
|
|
505 |
|
|
506 |
# get source file.
|
|
507 |
if ($linesource =~ /.*[\/\\](\S+)/ )
|
|
508 |
{
|
|
509 |
$linesourceFile = $1;
|
|
510 |
}
|
|
511 |
# get destination file.
|
|
512 |
if ($linedest =~ /.*[\/\\](\S+)/ )
|
|
513 |
{
|
|
514 |
$linedestFile = $1;
|
|
515 |
}
|
|
516 |
# iterate trough all
|
|
517 |
foreach my $firstarrayEntry (@$firstarray)
|
|
518 |
{
|
|
519 |
if( $firstarrayEntry =~ /(\S+)\s+(\S+)/ )
|
|
520 |
{
|
|
521 |
my $firstarrayEntrydest = $2;
|
|
522 |
|
|
523 |
if( $linedest eq $firstarrayEntrydest )
|
|
524 |
{
|
|
525 |
# remove the specified element from the array.
|
|
526 |
splice(@$firstarray,$firstArrayCount,1);
|
|
527 |
# initialize the nonsisFileListCount to zero.
|
|
528 |
my $nonsisFileListCount = 0;
|
|
529 |
foreach my $nonsisEntry ( @$nonsisArray )
|
|
530 |
{
|
|
531 |
if( $nonsisEntry =~ /^(\S+)=(\S+)\s+(\S+)/ )
|
|
532 |
{
|
|
533 |
my $nonsisEntryDest = $3;
|
|
534 |
# remove double quotes.
|
|
535 |
$nonsisEntryDest =~ s/\"//g;
|
|
536 |
my $nonsisEntryDestFile;
|
|
537 |
if ($nonsisEntryDest =~ /.*[\/\\](\S+)/ )
|
|
538 |
{
|
|
539 |
$nonsisEntryDestFile = $1;
|
|
540 |
}
|
|
541 |
if( $nonsisEntryDest eq $linesource )
|
|
542 |
{
|
|
543 |
if($linekeyword eq "rename")
|
|
544 |
{
|
|
545 |
# remove the specified element from the array.
|
|
546 |
splice(@$nonsisArray,$nonsisFileListCount,1);
|
|
547 |
$nonsisEntry =~ s/$nonsisEntryDestFile/$linedestFile/g;
|
|
548 |
push(@$nonsisArray,$nonsisEntry);
|
|
549 |
}
|
|
550 |
elsif($linekeyword eq "alias")
|
|
551 |
{
|
|
552 |
my $newLine = $nonsisEntry;
|
|
553 |
$newLine =~ s/$nonsisEntryDestFile/$linedestFile/g;
|
|
554 |
push(@$nonsisArray,$newLine);
|
|
555 |
}
|
|
556 |
}
|
|
557 |
}
|
|
558 |
$nonsisFileListCount++;
|
|
559 |
}#end of loop foreach my $newLine ( @nonsisArray )
|
|
560 |
}
|
|
561 |
$firstArrayCount++;
|
|
562 |
}#end of loop foreach my $newLine ( @firstarray)
|
|
563 |
}
|
|
564 |
}
|
|
565 |
|
|
566 |
# Traverse the entire directory and log the folder contents on to a file.
|
|
567 |
sub dumpDatadriveObydata
|
|
568 |
{
|
|
569 |
#assign a temporary name and extension to the new oby file.
|
|
570 |
my $newobyfile = "temp.$$";
|
|
571 |
my ($datadir,$oldobyfile,$size,$nonsisFileArray,$renameArray,$aliasArray,
|
|
572 |
$hideArray,$sisobyArray,$datadriveArray,$keepgoingOpt,$verboseOpt) = @_;
|
|
573 |
# get the working directory.
|
|
574 |
my $curWorkingDir = getcwd;
|
|
575 |
# traverse the updated data drive directory structure.
|
|
576 |
&TraverseDir($datadir,"",$sisobyArray,$datadir);
|
|
577 |
# change the directrory to the Working directory.
|
|
578 |
chdir($curWorkingDir);
|
|
579 |
# copy non-sis file(s) on to prototype data drive folder.
|
|
580 |
copyNonSisFiles($datadir,$oldobyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt);
|
|
581 |
#open the oby file in read-only mode.
|
|
582 |
open (OLDDATA, "< $oldobyfile") or die("* Can't open $oldobyfile\n");
|
|
583 |
# Truncate and open the new oby file for writing..
|
|
584 |
open(NEWDATA, "> $newobyfile") or die "can't open $newobyfile";
|
|
585 |
while (my $line =<OLDDATA>)
|
|
586 |
{
|
|
587 |
if( $line =~ /^hide\s+(\S+)/i)
|
|
588 |
{
|
|
589 |
my $lineToSearch = $1;
|
|
590 |
my $hideListCount = 0;
|
|
591 |
foreach my $newLine ( @$hideArray )
|
|
592 |
{
|
|
593 |
if( $newLine eq $lineToSearch )
|
|
594 |
{
|
|
595 |
splice(@$hideArray,$hideListCount,1);
|
|
596 |
my $nonsisFileListCount = 0;
|
|
597 |
foreach my $newLine ( @$nonsisFileArray )
|
|
598 |
{
|
|
599 |
if( $newLine =~ /^(\S+)=(\S+)\s+(\S+)/ )
|
|
600 |
{
|
|
601 |
my $newLineKeyword = $1;
|
|
602 |
my $newLinesource = $2;
|
|
603 |
my $newLinedest = $3;
|
|
604 |
$newLinedest =~ s/\"//g;
|
|
605 |
$newLinedest = "\/".$newLinedest;
|
|
606 |
if( $newLinedest eq $lineToSearch )
|
|
607 |
{
|
|
608 |
# remove the specified element from the array.
|
|
609 |
splice(@$nonsisFileArray,$nonsisFileListCount,1);
|
|
610 |
}
|
|
611 |
}
|
|
612 |
# increment the non sis file list count.
|
|
613 |
$nonsisFileListCount++;
|
|
614 |
}
|
|
615 |
}
|
|
616 |
# increment the hide file list count.
|
|
617 |
$hideListCount++;
|
|
618 |
}
|
|
619 |
}
|
|
620 |
elsif( $line =~ /^rename\s+(\S+)\s+(\S+)/i)
|
|
621 |
{
|
|
622 |
my $linesource = $1 ;
|
|
623 |
my $linedest = $2;
|
|
624 |
my $linekeyword = "rename";
|
|
625 |
&compareArrays($renameArray,$nonsisFileArray,$linesource,$linedest,$linekeyword);
|
|
626 |
}
|
|
627 |
elsif( $line =~ /^alias\s+(\S+)\s+(\S+)/i )
|
|
628 |
{
|
|
629 |
my $linesource = $1 ;
|
|
630 |
my $linedest = $2;
|
|
631 |
my $linekeyword = "alias";
|
|
632 |
&compareArrays($aliasArray,$nonsisFileArray,$linesource,$linedest,$linekeyword);
|
|
633 |
}
|
|
634 |
elsif( $line =~ /^(file|data)\s*=\s*/i || $line =~ /^\s*(zdriveimagename|sisfile)\s*=\s*/i )
|
|
635 |
{
|
|
636 |
# skip to next line.
|
|
637 |
next;
|
|
638 |
}
|
|
639 |
else
|
|
640 |
{
|
|
641 |
# push it on to the array.
|
|
642 |
unshift(@$datadriveArray,$line);
|
|
643 |
}
|
|
644 |
next;
|
|
645 |
}
|
|
646 |
# close the old oby files.
|
|
647 |
close(OLDDATA)or die "can't close $oldobyfile";
|
|
648 |
#write the array contents on to the file
|
|
649 |
print"* Updating $oldobyfile - final OBY file\n";
|
|
650 |
&writeDataToFile( $datadriveArray );
|
|
651 |
&writeDataToFile( $sisobyArray );
|
|
652 |
&writeDataToFile( $nonsisFileArray );
|
|
653 |
# close the new oby file.
|
|
654 |
close(NEWDATA)or die "can't close $newobyfile";
|
|
655 |
#rename the file.
|
|
656 |
rename( $newobyfile, $oldobyfile )or die "can't rename $newobyfile to $oldobyfile: $!";
|
|
657 |
}
|
|
658 |
|
|
659 |
|
|
660 |
# Traverse the entire given directory
|
|
661 |
# push all the folder contents on to an array.
|
|
662 |
sub TraverseDir
|
|
663 |
{
|
|
664 |
my($dir,$folderList,$sisFileContent,$rootdir) = @_;
|
|
665 |
#check the specified directory
|
|
666 |
chdir($dir) || die "Cannot chdir to $dir\n";
|
|
667 |
local(*DIR);
|
|
668 |
opendir(DIR, ".");#open current directory.
|
|
669 |
my $sourcedir;
|
|
670 |
my $destdir;
|
|
671 |
while (my $entry=readdir(DIR))
|
|
672 |
{
|
|
673 |
#skip, parent directory and current directory.
|
|
674 |
next if ($entry eq "." || $entry eq "..");
|
|
675 |
#check if it is a file
|
|
676 |
if( -f $entry )
|
|
677 |
{
|
|
678 |
my $sourcedir = $rootdir."\/".$folderList.$entry;
|
|
679 |
my $destdir = "$folderList".$entry;
|
|
680 |
my $sisSource;
|
|
681 |
my $sisdestination;
|
|
682 |
if(&checkRegCtlFiles($entry))
|
|
683 |
{
|
|
684 |
# check for any whitespace
|
|
685 |
if($sourcedir =~ m/ /)
|
|
686 |
{
|
|
687 |
# if yes, then append double quotes
|
|
688 |
$sisSource = "data="."\"".$sourcedir."\"";
|
|
689 |
}
|
|
690 |
else
|
|
691 |
{
|
|
692 |
# else dont append any double quotes for destination
|
|
693 |
$sisSource = "data=".$sourcedir;
|
|
694 |
}
|
|
695 |
# push the line on to the array.
|
|
696 |
push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"');
|
|
697 |
}
|
|
698 |
else
|
|
699 |
{
|
|
700 |
# check for any white space
|
|
701 |
if($sourcedir =~ m/ /)
|
|
702 |
{
|
|
703 |
# if yes, then append double quotes
|
|
704 |
$sisSource = "file="."\"".$sourcedir."\"";
|
|
705 |
}
|
|
706 |
else
|
|
707 |
{
|
|
708 |
# else dont append any double quotes for destination
|
|
709 |
$sisSource = "file=".$sourcedir;
|
|
710 |
}
|
|
711 |
# push the line on to the array.
|
|
712 |
push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"');
|
|
713 |
}
|
|
714 |
}
|
|
715 |
#else it's a directory
|
|
716 |
else
|
|
717 |
{
|
|
718 |
&TraverseDir($entry,$folderList.$entry."\/",$sisFileContent,$rootdir);
|
|
719 |
}
|
|
720 |
}
|
|
721 |
closedir(DIR);
|
|
722 |
chdir("..");
|
|
723 |
}
|
|
724 |
|
|
725 |
# write the data in to oby file by accessing appropriate array.
|
|
726 |
sub writeDataToFile
|
|
727 |
{
|
|
728 |
my ($array) = @_;
|
|
729 |
#get the array size.
|
|
730 |
my $arraySize = scalar(@$array);
|
|
731 |
for(my $i=0; $i<$arraySize ; $i++ )
|
|
732 |
{
|
|
733 |
#pop out the element to the respective obey file.
|
|
734 |
my $line=pop(@$array);
|
|
735 |
if (&is_windows){
|
|
736 |
$line =~ s-\/-\\-g;
|
|
737 |
}else{
|
|
738 |
$line =~ s-\\-\/-g;
|
|
739 |
}
|
|
740 |
print NEWDATA $line."\n";
|
|
741 |
}
|
|
742 |
}
|