602
|
1 |
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
#
|
|
15 |
#
|
|
16 |
# Description:
|
|
17 |
# Symbian::CBR::CreateDelta.pm
|
|
18 |
#
|
|
19 |
|
|
20 |
package Symbian::CBR::CreateDelta;
|
|
21 |
|
|
22 |
use File::Basename;
|
|
23 |
use File::Spec;
|
|
24 |
use File::Path;
|
|
25 |
use File::Copy;
|
|
26 |
use XML::Simple;
|
|
27 |
use Carp;
|
|
28 |
use Digest::Md5;
|
|
29 |
use ExportData;
|
|
30 |
use EnvDb;
|
|
31 |
use Utils;
|
|
32 |
use Symbian::CBR::DeltaRelease::Manifest qw(ADDED_ZIPS META_FILES);
|
|
33 |
use Symbian::CBR::Component::Manifest;
|
|
34 |
|
|
35 |
|
|
36 |
sub new {
|
|
37 |
my $pkg = shift;
|
|
38 |
my $iniData = shift;
|
|
39 |
my $pgpkey = shift;
|
|
40 |
my $releaseManifest = shift;
|
|
41 |
my $verbose = shift;
|
|
42 |
my $noevalid = shift;
|
|
43 |
my $nodelta = shift;
|
|
44 |
my $maxdelta = shift;
|
|
45 |
|
|
46 |
my $self;
|
|
47 |
$self->{iniData} = $iniData;
|
|
48 |
$self->{pgpKey} = $pgpkey;
|
|
49 |
$self->{releaseManifest} = $releaseManifest;
|
|
50 |
$self->{verbose} = $verbose;
|
|
51 |
$self->{noevalid} = $noevalid;
|
|
52 |
$self->{nodelta} = $nodelta;
|
|
53 |
$self->{maxdelta} = $maxdelta;
|
|
54 |
bless $self, $pkg;
|
|
55 |
return $self;
|
|
56 |
}
|
|
57 |
|
|
58 |
sub compareEnvironments {
|
|
59 |
my $self = shift;
|
|
60 |
my $referenceComp = shift;
|
|
61 |
my $referenceVer = shift;
|
|
62 |
my $nominatedComp = shift;
|
|
63 |
my $nominatedVer = shift;
|
|
64 |
|
|
65 |
print "Comparing reldata files\n" if($self->{verbose});
|
|
66 |
my $referenceRelData = RelData->Open($self->{iniData}, $referenceComp, $referenceVer, $self->{verbose});
|
|
67 |
my $nominatedRelData = RelData->Open($self->{iniData}, $nominatedComp, $nominatedVer, $self->{verbose});
|
|
68 |
|
|
69 |
my $referenceEnv = $referenceRelData->Environment();
|
|
70 |
my $nominatedEnv = $nominatedRelData->Environment();
|
|
71 |
|
|
72 |
foreach my $thisComp ( sort keys %{$nominatedEnv}){
|
|
73 |
if (defined $referenceEnv->{$thisComp}) {
|
|
74 |
if ($referenceEnv->{$thisComp} ne $nominatedEnv->{$thisComp}) {
|
|
75 |
$self->{diffComps}{modified}{$thisComp}{$referenceEnv->{$thisComp}} = $nominatedEnv->{$thisComp};
|
|
76 |
}
|
|
77 |
else {
|
|
78 |
$self->{diffComps}{identical}{$thisComp} = $nominatedEnv->{$thisComp};
|
|
79 |
}
|
|
80 |
}
|
|
81 |
else {
|
|
82 |
$self->{diffComps}{added}{$thisComp} = $nominatedEnv->{$thisComp};
|
|
83 |
}
|
|
84 |
}
|
|
85 |
foreach my $thisComp( sort keys %{$referenceEnv}){
|
|
86 |
unless (defined $nominatedEnv->{$thisComp}) {
|
|
87 |
$self->{diffComps}{deleted}{$thisComp} = $referenceEnv->{$thisComp};
|
|
88 |
}
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
sub compareFiles {
|
|
93 |
my $self = shift;
|
|
94 |
my $comp = shift;
|
|
95 |
my $referenceVersion = shift;
|
|
96 |
my $nominatedVersion = shift;
|
|
97 |
my $diffFiles;
|
|
98 |
my $referenceComp = $self->{iniData}->PathData->LocalArchivePathForExistingOrNewComponent($comp, $referenceVersion);
|
|
99 |
my $nominatedComp = $self->{iniData}->PathData->LocalArchivePathForExistingOrNewComponent($comp, $nominatedVersion);
|
|
100 |
my $referenceManifest = File::Spec->catdir($referenceComp,MANIFEST_FILE);
|
|
101 |
my $nominatedManifest = File::Spec->catdir($nominatedComp,MANIFEST_FILE);
|
|
102 |
if (-e $referenceManifest and -e $nominatedManifest) {
|
|
103 |
$diffFiles = $self->compareManifestFiles($referenceManifest,$nominatedManifest);
|
|
104 |
}
|
|
105 |
else {
|
|
106 |
$diffFiles = $self->compareAllZipFiles($comp, $nominatedComp, $referenceComp);
|
|
107 |
}
|
|
108 |
#List meta files (reldata, manifest and exports.txt files).
|
|
109 |
foreach my $thisFile (@{Utils::ReadDir($nominatedComp)}) {
|
|
110 |
unless ($thisFile =~ /\.zip$/) {
|
|
111 |
$diffFiles->{$comp}{files}{$thisFile} = 1;
|
|
112 |
}
|
|
113 |
}
|
|
114 |
return $diffFiles;
|
|
115 |
}
|
|
116 |
|
|
117 |
sub compareAllZipFiles {
|
|
118 |
my $self = shift;
|
|
119 |
my $comp = shift;
|
|
120 |
my $nominatedComp = shift;
|
|
121 |
my $referenceComp = shift;
|
|
122 |
my $tempRefPath = File::Spec->catdir($self->{tempDir},"ref");
|
|
123 |
my $tempNomPath = File::Spec->catdir($self->{tempDir},"nom");
|
|
124 |
print "Manifest file is not available for $comp\n";
|
|
125 |
my $nominatedCompFiles = Utils::ReadDir($nominatedComp);
|
|
126 |
my $referenceCompFiles = Utils::ReadDir($referenceComp);
|
|
127 |
my $nominatedZipFiles ;
|
|
128 |
my $referenceZipFiles ;
|
|
129 |
my %diffFiles;
|
|
130 |
foreach my $thisFile (@{$nominatedCompFiles}) {
|
|
131 |
$nominatedZipFiles->{$thisFile} = 1 if ($thisFile =~ /\.zip$/) ;
|
|
132 |
}
|
|
133 |
foreach my $thisFile (@{$referenceCompFiles}) {
|
|
134 |
$referenceZipFiles->{$thisFile} = 1 if ($thisFile =~ /\.zip$/) ;
|
|
135 |
}
|
|
136 |
foreach my $thisZip (keys %{$nominatedZipFiles}) {
|
|
137 |
next unless ( $self->isExportableCat($comp, $thisZip) );
|
|
138 |
if (defined $referenceZipFiles->{$thisZip}) {
|
|
139 |
#Modified zip file
|
|
140 |
my $refZipFile = File::Spec->catdir($referenceComp, $thisZip);
|
|
141 |
my $nomZipFile = File::Spec->catdir($nominatedComp, $thisZip);
|
|
142 |
print "Extracting $thisZip.\n" if($self->{verbose});
|
|
143 |
Utils::Unzip($refZipFile ,$tempNomPath,0,1); # 0 = verbose, 1 = overwrite.
|
|
144 |
Utils::Unzip($nomZipFile,$tempRefPath,0,1);
|
|
145 |
my @referenceFiles;
|
|
146 |
my @nominatedFiles;
|
|
147 |
Utils::ListAllFiles($tempRefPath, \@referenceFiles);
|
|
148 |
Utils::ListAllFiles($tempNomPath, \@nominatedFiles);
|
|
149 |
foreach my $thisnomFile (@nominatedFiles) {
|
|
150 |
my $file1 = $thisnomFile;
|
|
151 |
$thisnomFile = substr($thisnomFile, (length( $tempNomPath)+1));
|
|
152 |
my $file2 = File::Spec->catfile($tempRefPath,$thisnomFile);
|
|
153 |
if (-e $file2) {
|
|
154 |
unless ($self->compareFile($file1 ,$file2)) {
|
|
155 |
$diffFiles->{$comp}{zips}{$thisZip}{modified}{$thisnomFile} = 1; #modified file.
|
|
156 |
unlink($file1) or print "Warning: Couldn't delete $file1 : $!\n";
|
|
157 |
unlink($file2) or print "Warning: Couldn't delete $file2 : $!\n";
|
|
158 |
}
|
|
159 |
}
|
|
160 |
else {
|
|
161 |
$diffFiles{$comp}{zips}{$thisZip}{added}{$thisnomFile} = 1; #added file.
|
|
162 |
unlink($file1) or print "Warning: Couldn't delete $file1 : $!\n";
|
|
163 |
}
|
|
164 |
}
|
|
165 |
foreach my $thisFile (@referenceFiles) {
|
|
166 |
my $file1 = substr($thisFile, (length( $tempRefPath)+1));
|
|
167 |
$file1 = File::Spec->catfile($tempNomPath,$file1);
|
|
168 |
unless (-e $file1) {
|
|
169 |
$diffFiles{$comp}{zips}{$thisZip}{deleted}{$file1} = 1 ; #deleted file for zip file.
|
|
170 |
unlink($thisFile) or print "Warning: Couldn't delete $thisFile : $!\n";
|
|
171 |
}
|
|
172 |
}
|
|
173 |
}
|
|
174 |
else {
|
|
175 |
#Newly added zip file.
|
|
176 |
my $nomZipFile = File::Spec->catdir($nominatedComp, $thisZip);
|
|
177 |
print "Extracting $thisZip.\n" if($self->{verbose});
|
|
178 |
Utils::Unzip($nomZipFile,$tempNomPath,0,1); # 0 = verbose, 1 = overwrite.
|
|
179 |
my @nominatedCompFiles;
|
|
180 |
Utils::ListAllFiles($tempNomPath, \@nominatedCompFiles);
|
|
181 |
foreach my $thisFile (@nominatedCompFiles) {
|
|
182 |
my $file = substr($thisFile, (length( $tempNomPath)+1));
|
|
183 |
$diffFiles{$comp}{zips}{$thisZip}{added}{$thisFile} = 1;
|
|
184 |
unlink($thisFile) or print "Warning: Couldn't delete $thisFile : $!\n";
|
|
185 |
}
|
|
186 |
}
|
|
187 |
}
|
|
188 |
#check for deleted zip files.
|
|
189 |
foreach my $thisZip (keys %{$referenceZipFiles}) {
|
|
190 |
unless (defined $nominatedZipFiles->{$thisZip}) {
|
|
191 |
my @referenceCompFiles;
|
|
192 |
my $refZipFile = File::Spec->catdir($referenceComp, $thisZip);
|
|
193 |
print "Extracting $thisZip.\n" if($self->{verbose});
|
|
194 |
Utils::Unzip($refZipFile ,$tempRefPath,0,1); # 0 = verbose, 1 = overwrite.
|
|
195 |
Utils::ListAllFiles($tempRefPath, \@referenceCompFiles);
|
|
196 |
foreach my $thisFile (@referenceCompFiles) {
|
|
197 |
my $file = substr($thisFile , (length( $tempRefPath)+1));
|
|
198 |
$diffFiles{$comp}{zips}{$thisZip}{deleted}{$file} = 1;
|
|
199 |
unlink($thisFile) or print "Warning: Couldn't delete $thisFile : $!\n";
|
|
200 |
}
|
|
201 |
}
|
|
202 |
}
|
|
203 |
return \%diffFiles;
|
|
204 |
}
|
|
205 |
|
|
206 |
sub compareFile {
|
|
207 |
my $self = shift;
|
|
208 |
my $file1 = shift;
|
|
209 |
my $file2 = shift;
|
|
210 |
my $Checksum1;
|
|
211 |
my $Checksum2;
|
|
212 |
unless ($self->{noevalid}) {
|
|
213 |
my $type1;
|
|
214 |
my $type2;
|
|
215 |
($Checksum1, $type1) = EvalidCompare::GenerateSignature($file1);
|
|
216 |
($Checksum2, $type2) = EvalidCompare::GenerateSignature($file2);
|
|
217 |
}
|
|
218 |
else {
|
|
219 |
open(FILEHANDLE1,"$file1");
|
|
220 |
open(FILEHANDLE2,"$file2");
|
|
221 |
my $ctx1 = Digest::MD5->new;
|
|
222 |
my $ctx2 = Digest::MD5->new;
|
|
223 |
$ctx1->addfile(FILEHANDLE1);
|
|
224 |
$ctx2->addfile(FILEHANDLE2);
|
|
225 |
$Checksum1 = $ctx1->hexdigest;
|
|
226 |
$Checksum2 = $ctx2->hexdigest;
|
|
227 |
close FILEHANDLE1;
|
|
228 |
close FILEHANDLE2;
|
|
229 |
}
|
|
230 |
return 1 if ($Checksum1 eq $Checksum2);
|
|
231 |
return 0;
|
|
232 |
}
|
|
233 |
|
|
234 |
|
|
235 |
sub compareManifestFiles {
|
|
236 |
my $self = shift ;
|
|
237 |
my $referenceManifest = shift;
|
|
238 |
my $nominatedManifest = shift;
|
|
239 |
my %diffFiles;
|
|
240 |
my $referenceManifestObj = Symbian::CBR::Component::Manifest->new($referenceManifest);
|
|
241 |
my $nominatedManifestObj = Symbian::CBR::Component::Manifest->new($nominatedManifest);
|
|
242 |
my $comp = lc($referenceManifestObj->{componentName});
|
|
243 |
$nominatedManifestObj->Compare($referenceManifestObj,1,1); # 1 = validatesource, 1 = keepgoing
|
|
244 |
foreach my $zipName (keys %{$nominatedManifestObj->GetDiffZipFiles()}) {
|
|
245 |
foreach my $thisFile (keys %{$nominatedManifestObj->GetDiffFilesForZip($zipName)}) {
|
|
246 |
my $fileStatus = $nominatedManifestObj->GetFileStatus($zipName, $thisFile);
|
|
247 |
$diffFiles{$comp}{zips}{$zipName}{$fileStatus}{$thisFile} = 1;
|
|
248 |
}
|
|
249 |
}
|
|
250 |
return \%diffFiles;
|
|
251 |
}
|
|
252 |
|
|
253 |
sub isExportableCat {
|
|
254 |
my $self = shift;
|
|
255 |
my $comp = shift;
|
|
256 |
my $zipFile = shift;
|
|
257 |
my $exportPgp = [ ];
|
|
258 |
return 1 if($self->{exportAll});
|
|
259 |
if ($zipFile =~ /^source([a-z])\.zip$/i) {
|
|
260 |
$exportPgp = $self->{exportData}->PgpKeysForSource($comp,$1);
|
|
261 |
}
|
|
262 |
elsif ($zipFile =~ /^exports([A-Z])\.zip$/i) {
|
|
263 |
$exportPgp = $self->{exportData}->PgpKeysForExports($comp,$1);
|
|
264 |
}
|
|
265 |
elsif ($zipFile =~ /^binaries/i) {
|
|
266 |
$exportPgp = $self->{exportData}->PgpKeysForBinaries($comp);
|
|
267 |
}
|
|
268 |
if (scalar @{$exportPgp} > 0) {
|
|
269 |
foreach my $thisKey (@{$exportPgp}) {
|
|
270 |
return 1 if ($self->{pgpKey} eq $thisKey);
|
|
271 |
}
|
|
272 |
}
|
|
273 |
return 0;
|
|
274 |
}
|
|
275 |
|
|
276 |
sub createDeltaEnv {
|
|
277 |
my $self = shift;
|
|
278 |
my $referenceComp = shift;
|
|
279 |
my $referenceVersion = shift;
|
|
280 |
my $nominatedComp = shift;
|
|
281 |
my $nominatedVersion = shift;
|
|
282 |
my $destination = shift;
|
|
283 |
Utils::InitialiseTempDir($self->{iniData});
|
|
284 |
$self->{tempDir} = Utils::TempDir();
|
|
285 |
my $deltaDestination = File::Spec->catdir($self->{tempDir},"modified");
|
|
286 |
my $newCompPath = File::Spec->catdir($self->{tempDir}, "new");
|
|
287 |
$self->{exportData} = ExportData->New(exports_file => $self->{iniData}->ExportDataFile(),verbose => $self->{verbose}) unless ($self->{exportAll});
|
|
288 |
my $referenceRelData = RelData->Open($self->{iniData}, $referenceComp, $referenceVersion, $self->{verbose});
|
|
289 |
my $nominatedRelData = RelData->Open($self->{iniData}, $nominatedComp, $nominatedVersion, $self->{verbose});
|
|
290 |
my $referenceEnv = $referenceRelData->Environment();
|
|
291 |
my $nominatedEnv = $nominatedRelData->Environment();
|
|
292 |
unless ($self->{exportAll}) {
|
|
293 |
my $foundPgpKey = 0;
|
|
294 |
foreach my $thisPgpKeys (@{$self->{exportData}->AllPgpKeys()}) {
|
|
295 |
if ($thisPgpKeys eq $self->{pgpKey}) {
|
|
296 |
$foundPgpKey = 1;
|
|
297 |
last;
|
|
298 |
}
|
|
299 |
}
|
|
300 |
croak "Error: PGP key ".$self->{pgpKey}." is not defined in ".$self->{iniData}->ExportDataFile()." file.\n" unless($foundPgpKey);
|
|
301 |
|
|
302 |
foreach my $thisComp (keys %{$nominatedEnv}) {
|
|
303 |
unless ($self->{exportData}->ComponentIsExportable($thisComp)) {
|
|
304 |
print "Warning: component \"$thisComp\" is not defined in export table.\n";
|
|
305 |
}
|
|
306 |
}
|
|
307 |
}
|
|
308 |
|
|
309 |
unless ($self->{noevalid} or eval { require EvalidCompare }) {
|
|
310 |
print "Warning: EvalidCompare is not installed. Setting --noevalid option. ($@)\n";
|
|
311 |
$self->{noevalid} = 1;
|
|
312 |
}
|
|
313 |
|
|
314 |
$self->{DeltaManifest} = Symbian::CBR::DeltaRelease::Manifest->new();
|
|
315 |
|
|
316 |
$self->{DeltaManifest}->SetReferenceBaselineComp($referenceComp);
|
|
317 |
$self->{DeltaManifest}->SetReferenceBaselineVer($referenceVersion);
|
|
318 |
$self->{DeltaManifest}->SetNominatedBaselineComp($nominatedComp);
|
|
319 |
$self->{DeltaManifest}->SetNominatedBaselineVer($nominatedVersion);
|
|
320 |
|
|
321 |
$self->compareEnvironments($referenceComp,$referenceVersion,$nominatedComp,$nominatedVersion);
|
|
322 |
|
|
323 |
foreach my $thisComp ( sort keys %{$self->{diffComps}{modified}} ) {
|
|
324 |
eval{ $self->createDeltaForComp($thisComp,$$referenceEnv{$thisComp},$$nominatedEnv{$thisComp}, $deltaDestination) };
|
|
325 |
print "Error: Unable to create Deltas for $thisComp,$$referenceEnv{$thisComp},$$nominatedEnv{$thisComp} $@\n" if($@);
|
|
326 |
}
|
|
327 |
|
|
328 |
foreach my $thisComp (sort keys %{$self->{diffComps}{added}}) {
|
|
329 |
$self->addComponent($thisComp, $newCompPath);
|
|
330 |
}
|
|
331 |
|
|
332 |
foreach my $thisComp (sort keys %{$self->{diffComps}{identical}}) {
|
|
333 |
$self->recordIdenticalOrDeletedComponent($thisComp, "identical");
|
|
334 |
}
|
|
335 |
foreach my $thisComp (sort keys %{$self->{diffComps}{deleted}}) {
|
|
336 |
$self->recordIdenticalOrDeletedComponent($thisComp, "deleted");
|
|
337 |
}
|
|
338 |
$self->{DeltaManifest}->Save($self->{tempDir}); # Write delta manifest file.
|
|
339 |
|
|
340 |
#Package modified, new directories and delta manifest file into zip files
|
|
341 |
my @filesToBeZipped ;
|
|
342 |
my @allFiles;
|
|
343 |
my $tempRefPath = File::Spec->catdir($self->{tempDir},"ref");
|
|
344 |
my $tempNomPath = File::Spec->catdir($self->{tempDir},"nom");
|
|
345 |
rmtree($tempRefPath) if($tempRefPath);
|
|
346 |
rmtree($tempNomPath) if($tempNomPath);
|
|
347 |
Utils::ListAllFiles($self->{tempDir}, \@allFiles);
|
|
348 |
foreach my $thisFile (@allFiles) {
|
|
349 |
my $file = substr($thisFile, (length($self->{tempDir})+1));
|
|
350 |
push @filesToBeZipped, $file;
|
|
351 |
}
|
|
352 |
my $tempPackageZipFile = $referenceVersion."_".$nominatedVersion.".tmp";
|
|
353 |
$tempPackageZipFile = File::Spec->catfile($destination, $tempPackageZipFile );
|
|
354 |
my $packageZipFile = $referenceVersion."_".$nominatedVersion.".zip";
|
|
355 |
$packageZipFile = File::Spec->catfile($destination, $packageZipFile );
|
|
356 |
if (-e $packageZipFile) {
|
|
357 |
print "Overwriting $packageZipFile.\n";
|
|
358 |
unlink ($packageZipFile);
|
|
359 |
}
|
|
360 |
print "Packaging all files into $packageZipFile.\n";
|
|
361 |
Utils::ZipList( $tempPackageZipFile, \@filesToBeZipped, $self->{verbose}, 0,$self->{tempDir});
|
|
362 |
rename ($tempPackageZipFile, $packageZipFile) or croak "Error: Couldn't rename $tempPackageZipFile to $packageZipFile.\n ";
|
|
363 |
rmtree ($self->{tempDir});
|
|
364 |
}
|
|
365 |
|
|
366 |
sub recordIdenticalOrDeletedComponent {
|
|
367 |
my $self = shift;
|
|
368 |
my $comp = shift;
|
|
369 |
my $compStatus = shift;
|
|
370 |
$self->{DeltaManifest}->SetComponentDetails($comp, $compStatus, $self->{diffComps}{$compStatus}{$comp}, undef); # undef for nominated version.
|
|
371 |
print "$comp is $compStatus.\n" if ($self->{verbose});
|
|
372 |
}
|
|
373 |
|
|
374 |
sub addComponent {
|
|
375 |
my $self = shift;
|
|
376 |
my $comp = shift;
|
|
377 |
my $newCompPath = shift;
|
|
378 |
print "$comp is newly added.\n";
|
|
379 |
$self->{DeltaManifest}->SetComponentDetails($comp, "added", undef, $self->{diffComps}{added}{$comp}); # undef for reference version.
|
|
380 |
|
|
381 |
$newCompPath = File::Spec->catdir($newCompPath,$comp);
|
|
382 |
mkpath($newCompPath) unless (-e $newCompPath);
|
|
383 |
|
|
384 |
my $archiveForComp = $self->{iniData}->PathData->LocalArchivePathForExistingOrNewComponent($comp, $self->{diffComps}{added}{$comp});
|
|
385 |
my $archiveFiles = Utils::ReadDir($archiveForComp);
|
|
386 |
|
|
387 |
foreach my $thisFile (@{$archiveFiles}) {
|
|
388 |
my $archiveFilePath = File::Spec->catdir($archiveForComp,$thisFile);
|
|
389 |
my $destFilePath = File::Spec->catfile($newCompPath,$thisFile);
|
|
390 |
if ($thisFile =~ /\.zip$/) {
|
|
391 |
if ($self->isExportableCat($comp,$thisFile)) {
|
|
392 |
$self->{DeltaManifest}->SetZipfileDetails($comp, $thisFile, "added");
|
|
393 |
eval{ copy($archiveFilePath,$destFilePath) ;};
|
|
394 |
croak "Error: File $archiveFilePath cannot be copied to $destFilePath. $@" if($@);
|
|
395 |
}
|
|
396 |
}
|
|
397 |
else {
|
|
398 |
eval{ copy($archiveFilePath,$destFilePath) ;};
|
|
399 |
croak "Error: File $archiveFilePath cannot be copied to $destFilePath. $@" if($@);
|
|
400 |
$self->{DeltaManifest}->RecordMetaFile($comp, $thisFile);
|
|
401 |
}
|
|
402 |
}
|
|
403 |
}
|
|
404 |
|
|
405 |
sub createDeltaForComp {
|
|
406 |
my $self = shift;
|
|
407 |
my $comp = shift;
|
|
408 |
my $referenceVersion = shift;
|
|
409 |
my $nominatedVersion = shift;
|
|
410 |
my $deltaDestination = shift;
|
|
411 |
print "Creating Delta for $comp component.\n";
|
|
412 |
|
|
413 |
my $referenceCompPath = $self->{iniData}->PathData->LocalArchivePathForExistingOrNewComponent($comp, $referenceVersion);
|
|
414 |
my $nominatedCompPath = $self->{iniData}->PathData->LocalArchivePathForExistingOrNewComponent($comp, $nominatedVersion);
|
|
415 |
|
|
416 |
my $relDataManifestDestination = File::Spec->catdir($self->{tempDir},META_FILES);
|
|
417 |
$self->{DeltaManifest}->SetComponentDetails($comp, "modified", $referenceVersion, $nominatedVersion);
|
|
418 |
my $filesList = $self->compareFiles($comp,$referenceVersion,$nominatedVersion);
|
|
419 |
foreach my $zipFile (keys %{$filesList->{$comp}{zips}}) { #Iterate through all zip files.
|
|
420 |
if ($self->isExportableCat($comp,$zipFile)) {
|
|
421 |
if ($self->{deltaAllFiles} or $self->{releaseManifest}->FileExists($comp, $zipFile)) { #Check whether zip file is present at receiving site or.
|
|
422 |
$self->{DeltaManifest}->SetZipfileDetails($comp, $zipFile, "modified");
|
|
423 |
$self->createDeltaForZip($comp, $referenceCompPath, $nominatedCompPath, $zipFile, $deltaDestination, $filesList);
|
|
424 |
}
|
|
425 |
else {
|
|
426 |
$self->{DeltaManifest}->SetZipfileDetails($comp, $zipFile, "added"); #added zip file for the component.
|
|
427 |
my $newZipFilePath = File::Spec->catdir($deltaDestination, ADDED_ZIPS, $comp);
|
|
428 |
mkpath ($newZipFilePath) unless(-d $newZipFilePath);
|
|
429 |
my $addedZipFile = File::Spec->catfile($newZipFilePath, $zipFile);
|
|
430 |
my $archiveFile = File::Spec->catfile($nominatedCompPath,$zipFile);
|
|
431 |
copy($archiveFile,$addedZipFile) or print "Warning: Couldn't copy $zipFile\n";
|
|
432 |
}
|
|
433 |
}
|
|
434 |
else {
|
|
435 |
print "Warning: $zipFile is not exportable.\n" if ($self->{verbose});
|
|
436 |
}
|
|
437 |
}
|
|
438 |
foreach my $thisFile (@{Utils::ReadDir($referenceCompPath)}) {
|
|
439 |
if ($thisFile =~/\.zip$/ and $self->isExportableCat($comp,$thisFile)) {
|
|
440 |
unless (defined $filesList->{$comp}{zips}{$thisFile}) {
|
|
441 |
$self->{DeltaManifest}->SetZipfileDetails($comp, $thisFile, "identical");
|
|
442 |
}
|
|
443 |
}
|
|
444 |
}
|
|
445 |
|
|
446 |
#Process reldata manifest and export.txt files.
|
|
447 |
foreach my $thisFile (keys %{$filesList->{$comp}{files}}) {
|
|
448 |
$self->{DeltaManifest}->RecordMetaFile($comp, $thisFile);
|
|
449 |
my $archiveFile = File::Spec->catfile($nominatedCompPath, $thisFile);
|
|
450 |
my $destinationFile = $comp."_".$thisFile;
|
|
451 |
mkpath($relDataManifestDestination) unless(-d $relDataManifestDestination);
|
|
452 |
$destinationFile = File::Spec->catfile($relDataManifestDestination, $destinationFile);
|
|
453 |
copy($archiveFile,$destinationFile) or print "Warning: Couldn't copy $thisFile\n";
|
|
454 |
}
|
|
455 |
}
|
|
456 |
|
|
457 |
sub createDeltaForZip {
|
|
458 |
my $self = shift;
|
|
459 |
my $comp = shift;
|
|
460 |
my $referenceCompPath = shift;
|
|
461 |
my $nominatedCompPath = shift;
|
|
462 |
my $zipFile = shift;
|
|
463 |
my $deltaDestination = shift;
|
|
464 |
my $filesList = shift;
|
|
465 |
|
|
466 |
my $refZipFilePath = File::Spec->catfile($referenceCompPath, $zipFile);
|
|
467 |
my $nomZipFilePath = File::Spec->catfile($nominatedCompPath, $zipFile);
|
|
468 |
my $tempRefPath = File::Spec->catdir($self->{tempDir},"ref");
|
|
469 |
my $tempNomPath = File::Spec->catdir($self->{tempDir},"nom");
|
|
470 |
print "Creating delta for $zipFile\n" if($self->{verbose});
|
|
471 |
|
|
472 |
#Process all files of a zip file.
|
|
473 |
foreach my $file (keys %{$filesList->{$comp}{zips}{$zipFile}{'modified'}}) {
|
|
474 |
#create delta for a file if it is modified.
|
|
475 |
unless ($self->{nodelta}) {
|
|
476 |
#Extract and create delta for a file.
|
|
477 |
print "Extracting $file from nominated $zipFile.\n" if($self->{verbose});
|
|
478 |
eval{Utils::UnzipSingleFile($nomZipFilePath,$file,$tempNomPath,0,1, $comp)}; # 0 = verbose. 1 = overwrite.
|
|
479 |
croak "Error: Couldn't Extract File $file $@\n" if($@);
|
|
480 |
my $file2 = File::Spec->catfile($tempNomPath,$file);
|
|
481 |
|
|
482 |
my $outputDeltaPath = File::Spec->catdir($deltaDestination, dirname($file));
|
|
483 |
|
|
484 |
my $size = -s $file2;
|
|
485 |
if (!defined $self->{maxdelta} or $size <= $self->{maxdelta}) {
|
|
486 |
print "Extracting $file from reference $zipFile.\n" if($self->{verbose});
|
|
487 |
eval{Utils::UnzipSingleFile($refZipFilePath,$file,$tempRefPath,0,1, $comp)};
|
|
488 |
croak "Error: Couldn't Extract File $file $@\n" if($@);
|
|
489 |
my $file1 = File::Spec->catfile($tempRefPath,$file);
|
|
490 |
|
|
491 |
$self->{DeltaManifest}->SetFileDetails($comp, $zipFile, $file, "modified", "delta");
|
|
492 |
|
|
493 |
$self->generateFileDelta($file1,$file2,$outputDeltaPath);
|
|
494 |
} else {
|
|
495 |
# File is too big to delta
|
|
496 |
$self->{DeltaManifest}->SetFileDetails($comp, $zipFile, $file, "modified", "file");
|
|
497 |
print "Not creating a delta of $file due to it being $size bytes\n" if ($self->{verbose});
|
|
498 |
if (! -d $outputDeltaPath) {
|
|
499 |
mkpath($outputDeltaPath) or croak "Error: Couldn't create directory for large file $file2 in delta\n";
|
|
500 |
}
|
|
501 |
system("move /Y \"".$file2."\" \"".$outputDeltaPath."\"") and croak "Error: Couldn't move large file $file2 into delta\n";
|
|
502 |
}
|
|
503 |
} else {
|
|
504 |
#add file to output delta package.
|
|
505 |
$self->{DeltaManifest}->SetFileDetails($comp, $zipFile, $file, "modified", "file");
|
|
506 |
print "Extracting $file from $zipFile.\n" if($self->{verbose});
|
|
507 |
eval{Utils::UnzipSingleFile($nomZipFilePath,$file,$deltaDestination,0,1, $comp); # 0 = verbose. 1 = overwrite.
|
|
508 |
};
|
|
509 |
croak "Error: Couldn't Extract File $file $@\n" if($@);
|
|
510 |
}
|
|
511 |
}
|
|
512 |
|
|
513 |
foreach my $file (keys %{$filesList->{$comp}{zips}{$zipFile}{'added'}}) {
|
|
514 |
#Newly added file to component.
|
|
515 |
print "$file is newly added.\n" if ($self->{verbose});
|
|
516 |
$self->{DeltaManifest}->SetFileDetails($comp, $zipFile, $file, "added", "file");
|
|
517 |
print "Extracting $file from $zipFile\n" if($self->{verbose});
|
|
518 |
eval{Utils::UnzipSingleFile($nomZipFilePath,$file,$deltaDestination,0, 1, $comp)};
|
|
519 |
croak "Error: Couldn't Extract File $file:$@\n" if($@);
|
|
520 |
}
|
|
521 |
|
|
522 |
foreach my $file (keys %{$filesList->{$comp}{zips}{$zipFile}{'deleted'}}) {
|
|
523 |
#deleted file.
|
|
524 |
print "$file is deleted.\n" if ($self->{verbose});
|
|
525 |
$self->{DeltaManifest}->SetFileDetails($comp, $zipFile, $file, "deleted", "file");
|
|
526 |
}
|
|
527 |
}
|
|
528 |
|
|
529 |
sub generateFileDelta {
|
|
530 |
my $self = shift;
|
|
531 |
my $file1 = shift;
|
|
532 |
my $file2 = shift;
|
|
533 |
my $destination = shift;
|
|
534 |
my $deltaFile = shift;
|
|
535 |
mkpath($destination) unless (-e $destination);
|
|
536 |
$deltaFile = basename($file2).".delta" unless(defined $deltaFile);
|
|
537 |
$deltaFile = File::Spec->catfile($destination,$deltaFile);
|
|
538 |
|
|
539 |
$file1 =~ s/^\\/\\\\/g; # Replace leading \ by \\.
|
|
540 |
$file2 =~ s/^\\/\\\\/g;
|
|
541 |
|
|
542 |
print "Creating delta for file ". basename($file1). "\n" if ($self->{verbose});
|
|
543 |
my $status = system "zdc \"$file1\" \"$file2\" \"$deltaFile\"" ;
|
|
544 |
if( $status != 0 ) {
|
|
545 |
$status = system "zdc" ;
|
|
546 |
$! = $? >> 8;
|
|
547 |
if ($status != 0) {
|
|
548 |
$! = $? >> 8;
|
|
549 |
print "Error: The zdelta tool is not installed. Please install zdelta, or use the --nodelta option to skip delta creation.\n";
|
|
550 |
croak;
|
|
551 |
}
|
|
552 |
else {
|
|
553 |
print "Error: The zdelta tool is not installed properly. Please install zdelta once again, or use the --nodelta option to skip delta creation.\n";
|
|
554 |
croak;
|
|
555 |
}
|
|
556 |
}
|
|
557 |
}
|
|
558 |
|
|
559 |
1;
|
|
560 |
|
|
561 |
__END__
|
|
562 |
|
|
563 |
|
|
564 |
=head1 NAME
|
|
565 |
|
|
566 |
Symbian::CBR::CreateDelta.pm - Creates deltas for modified files from reference baseline to the nominated baseline.
|
|
567 |
|
|
568 |
=head2 new
|
|
569 |
|
|
570 |
Creates a CreateDelta object. Expects to be passed:
|
|
571 |
|
|
572 |
=over 4
|
|
573 |
|
|
574 |
=item *
|
|
575 |
an C<IniData> reference
|
|
576 |
|
|
577 |
=item *
|
|
578 |
a C<Release manifest> reference
|
|
579 |
|
|
580 |
=item *
|
|
581 |
a verbosity level
|
|
582 |
|
|
583 |
=item *
|
|
584 |
a flag to indicate not to use evalid for comparision
|
|
585 |
|
|
586 |
=item *
|
|
587 |
a flag to skip delta creation
|
|
588 |
|
|
589 |
=item *
|
|
590 |
a maximum file size (in bytes) above which the tool won't create a delta of the file (assuming the flag to skip delta creating in all cases is not used).
|
|
591 |
|
|
592 |
=back
|
|
593 |
|
|
594 |
=head2 compareEnvironments
|
|
595 |
|
|
596 |
Expects to be passed a reference component name, a reference component version, a nominated component name and a nominated component version. Compares these environments to list identical, modified, added and deleted components.
|
|
597 |
|
|
598 |
=head2 compareFiles
|
|
599 |
|
|
600 |
Expects to be passed a full path for a reference version and a nominated version of a component. Lists modified, added and deleted files for the component between the two versions. If the manifest file is present for both versions, then it compares using manifest objects. Otherwise it extracts all zip files and compares each file, one at a time.
|
|
601 |
|
|
602 |
=head2 compareFile
|
|
603 |
|
|
604 |
Expects to be passed full paths for two versions of a file. Compares them using EvalidCompare if noevalid is not specified, otherwise uses Digest::MD5 for the file comparison. Returns 1 if checksum for both the files matches, otherwise 0.
|
|
605 |
|
|
606 |
=head2 createDeltaEnv
|
|
607 |
|
|
608 |
Expects to be passed a reference component name, a reference component version, a nominated component name, a nominated component version, and a destination. Creates the deltas for the modified files between two baselines, adds newly added files and components and packages these files into a zip file at the path provided as a destination.
|
|
609 |
|
|
610 |
=head2 createDeltaForComp
|
|
611 |
|
|
612 |
Expects to be passed a component name, reference version of component, nominated version of a component, and path where deltas to be stored. Compares the modified, added and deleted files from reference version to nominated version and creates the deltas for modified files, then copies the newly added files.
|
|
613 |
|
|
614 |
=head2 generateFileDelta
|
|
615 |
|
|
616 |
Expects to be passed a full path for two versions of a file, destination path where delta file should be stored, and optionally delta file name. Makes use of zdelta third party tool to create delta for a file.
|
|
617 |
|
|
618 |
=head1 KNOWN BUGS
|
|
619 |
|
|
620 |
None.
|
|
621 |
|
|
622 |
=head1 COPYRIGHT
|
|
623 |
|
|
624 |
Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
625 |
All rights reserved.
|
|
626 |
This component and the accompanying materials are made available
|
|
627 |
under the terms of the License "Eclipse Public License v1.0"
|
|
628 |
which accompanies this distribution, and is available
|
|
629 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
630 |
|
|
631 |
Initial Contributors:
|
|
632 |
Nokia Corporation - initial contribution.
|
|
633 |
|
|
634 |
Contributors:
|
|
635 |
|
|
636 |
Description:
|
|
637 |
|
|
638 |
|
|
639 |
=cut
|