19780544fSAndrew Rist#************************************************************** 2cdf0e10cSrcweir# 39780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 49780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 59780544fSAndrew Rist# distributed with this work for additional information 69780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 79780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 89780544fSAndrew Rist# "License"); you may not use this file except in compliance 99780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir# 119780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir# 139780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 149780544fSAndrew Rist# software distributed under the License is distributed on an 159780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169780544fSAndrew Rist# KIND, either express or implied. See the License for the 179780544fSAndrew Rist# specific language governing permissions and limitations 189780544fSAndrew Rist# under the License. 19cdf0e10cSrcweir# 209780544fSAndrew Rist#************************************************************** 219780544fSAndrew Rist 229780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweirpackage installer::packagepool; 25cdf0e10cSrcweir 26cdf0e10cSrcweiruse Digest::MD5; 27cdf0e10cSrcweiruse installer::exiter; 28cdf0e10cSrcweiruse installer::globals; 29cdf0e10cSrcweiruse installer::logger; 30cdf0e10cSrcweiruse installer::pathanalyzer; 31cdf0e10cSrcweiruse installer::worker; 32cdf0e10cSrcweir 33cdf0e10cSrcweir###################################################### 34cdf0e10cSrcweir# Checking the md5sum of a file 35cdf0e10cSrcweir###################################################### 36cdf0e10cSrcweir 37cdf0e10cSrcweirsub get_md5sum 38cdf0e10cSrcweir{ 39cdf0e10cSrcweir my ($filename) = @_; 40cdf0e10cSrcweir 41cdf0e10cSrcweir open(FILE, "<$filename") or die "ERROR: Can't open $filename for creating file hash"; 42cdf0e10cSrcweir binmode(FILE); 43cdf0e10cSrcweir my $digest = Digest::MD5->new->addfile(*FILE)->hexdigest; 44cdf0e10cSrcweir close(FILE); 45cdf0e10cSrcweir 46cdf0e10cSrcweir return $digest; 47cdf0e10cSrcweir} 48cdf0e10cSrcweir 49cdf0e10cSrcweir#################################################### 50cdf0e10cSrcweir# Setting a unique sessionid to identify this 51cdf0e10cSrcweir# packaging process. 52cdf0e10cSrcweir#################################################### 53cdf0e10cSrcweir 54cdf0e10cSrcweirsub set_sessionid 55cdf0e10cSrcweir{ 56cdf0e10cSrcweir my $pid = $$; # process id 57cdf0e10cSrcweir my $timer = time(); # time 58cdf0e10cSrcweir $installer::globals::sessionid = $pid . $timer; 59cdf0e10cSrcweir $installer::globals::sessionidset = 1; 60b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 61b274bc22SAndre Fischer $installer::logger::Lang->print("Pool: Setting session id: $installer::globals::sessionid.\n"); 62cdf0e10cSrcweir} 63cdf0e10cSrcweir 64cdf0e10cSrcweir#################################################### 65cdf0e10cSrcweir# Setting and creating pool path. 66cdf0e10cSrcweir#################################################### 67cdf0e10cSrcweir 68cdf0e10cSrcweirsub set_pool_path 69cdf0e10cSrcweir{ 70cdf0e10cSrcweir $installer::globals::unpackpath =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes 71cdf0e10cSrcweir $installer::globals::poolpath = $installer::globals::unpackpath . $installer::globals::separator . "pool_" . $installer::globals::packageformat; 72cdf0e10cSrcweir installer::systemactions::create_directory($installer::globals::poolpath); 73cdf0e10cSrcweir $installer::globals::poolpathset = 1; 74cdf0e10cSrcweir} 75cdf0e10cSrcweir 76cdf0e10cSrcweir#################################################### 77cdf0e10cSrcweir# Comparing the content of two epm files. 78cdf0e10cSrcweir#################################################### 79cdf0e10cSrcweir 80cdf0e10cSrcweirsub compare_epm_content 81cdf0e10cSrcweir{ 82cdf0e10cSrcweir my ($oldcontent, $newcontent) = @_; 83cdf0e10cSrcweir 84cdf0e10cSrcweir my $identical = 1; 85cdf0e10cSrcweir my $diffinfo = ""; 86cdf0e10cSrcweir 87cdf0e10cSrcweir # Removing empty lines and files from $newcontent 88cdf0e10cSrcweir 89cdf0e10cSrcweir my @newlocalcontent = (); 90cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$newcontent}; $i++ ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir if ( ${$newcontent}[$i] =~ /^\s*$/ ) { next; } # Removing empty lines from $newcontent. Empty lines are also not included into pcf file, from where $oldcontent was read. 93cdf0e10cSrcweir if ( ${$newcontent}[$i] =~ /^\s*f\s+/ ) { next; } # Ignoring files, they can contain temporary pathes 94cdf0e10cSrcweir if (( ${$newcontent}[$i] =~ /^\s*%readme\s+/ ) || ( ${$newcontent}[$i] =~ /^\s*%license\s+/ )) { next; } # ignoring license and readme (language specific!) 95cdf0e10cSrcweir my $oneline = ${$newcontent}[$i]; 96cdf0e10cSrcweir $oneline =~ s/\s*$//; # Removing line ends. Also not included in old epm file, that is read from pcf file. 97cdf0e10cSrcweir push(@newlocalcontent, $oneline); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir my $oldmember = $#{$oldcontent} + 1; 101cdf0e10cSrcweir my $newmember = $#newlocalcontent + 1; 102cdf0e10cSrcweir 103cdf0e10cSrcweir # comparing the count 104cdf0e10cSrcweir if ( $oldmember != $newmember ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir $identical = 0; 107b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 108b274bc22SAndre Fischer $installer::logger::Info->print("...... changed length of EPM file\n"); 109cdf0e10cSrcweir $diffinfo = "Pool: EPM, different line count: old epm file: $oldmember, new epm file: $newmember\n"; 110cdf0e10cSrcweir push(@installer::globals::epmdifflist, $diffinfo); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir # comparing the content line for line, so the order must not change 114cdf0e10cSrcweir 115cdf0e10cSrcweir if ( $identical ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$oldcontent}; $i++ ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir if ( ${$oldcontent}[$i] ne $newlocalcontent[$i] ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir $identical = 0; 122cdf0e10cSrcweir my $line = $i + 1; 123b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 124b274bc22SAndre Fischer $installer::logger::Info->print("...... different content in EPM file\n"); 125cdf0e10cSrcweir $diffinfo = "Pool: EPM, line $line changed from \"${$oldcontent}[$i]\" to \"$newlocalcontent[$i]\".\n"; 126cdf0e10cSrcweir push(@installer::globals::epmdifflist, $diffinfo); 127cdf0e10cSrcweir last; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir return $identical; 133cdf0e10cSrcweir} 134cdf0e10cSrcweir 135cdf0e10cSrcweir#################################################### 136cdf0e10cSrcweir# Comparing the content of two pcf files. 137cdf0e10cSrcweir#################################################### 138cdf0e10cSrcweir 139cdf0e10cSrcweirsub compare_package_content 140cdf0e10cSrcweir{ 141cdf0e10cSrcweir my ($oldcontent, $newcontent) = @_; 142cdf0e10cSrcweir 143cdf0e10cSrcweir my $identical = 1; 144cdf0e10cSrcweir my $infoline = ""; 145cdf0e10cSrcweir 146cdf0e10cSrcweir my $oldmember = scalar keys %{$oldcontent}; 147cdf0e10cSrcweir my $newmember = scalar keys %{$newcontent}; 148cdf0e10cSrcweir 149cdf0e10cSrcweir # comparing the count 150cdf0e10cSrcweir 151cdf0e10cSrcweir if ( $oldmember != $newmember ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir # Logging the difference 154cdf0e10cSrcweir $identical = 0; 155b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 156b274bc22SAndre Fischer $installer::logger::Info->printf("...... different number of files in packages. New number: %s, old number: %s\n", $newmember, $oldmember); 157cdf0e10cSrcweir $infoline = "Different number of files in packages. New number: $newmember, old number: $oldmember\n"; 158cdf0e10cSrcweir push(@installer::globals::pcfdiffcomment, $infoline); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir # comparing the keys 162cdf0e10cSrcweir 163cdf0e10cSrcweir if ( $identical ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir my $first = 1; 166cdf0e10cSrcweir foreach my $dest ( keys %{$newcontent} ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if ( ! exists($oldcontent->{$dest}) ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir $identical = 0; 171*155d5090SAndre Fischer $installer::logger::Info->print("\n") if $first; 172*155d5090SAndre Fischer $installer::logger::Info->printf("...... file only in one package (A): %s\n", $dest); 173cdf0e10cSrcweir $infoline = "File only in existing pool package: $dest\n"; 174cdf0e10cSrcweir push(@installer::globals::pcfdiffcomment, $infoline); 175cdf0e10cSrcweir $first = 0; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir # collecting all differences 180cdf0e10cSrcweir if ( ! $identical ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir foreach my $dest ( keys %{$oldcontent} ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if ( ! exists($newcontent->{$dest}) ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir $identical = 0; 187*155d5090SAndre Fischer $installer::logger::Info->print("\n") if $first; 188*155d5090SAndre Fischer $installer::logger::Info->printf("...... file only in one package (B): %s\n", $dest); 189cdf0e10cSrcweir $infoline = "File only in new package: $dest\n"; 190cdf0e10cSrcweir push(@installer::globals::pcfdiffcomment, $infoline); 191cdf0e10cSrcweir $first = 0; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir # comparing the checksum 198cdf0e10cSrcweir 199cdf0e10cSrcweir if ( $identical ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir my $first = 1; 202cdf0e10cSrcweir 203cdf0e10cSrcweir foreach my $dest ( keys %{$newcontent} ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir if ( $newcontent->{$dest}->{'md5sum'} ne $oldcontent->{$dest}->{'md5sum'} ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir $identical = 0; 208cdf0e10cSrcweir if ( $first == 1 ) 209cdf0e10cSrcweir { 210b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 211cdf0e10cSrcweir $first = 0; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir $installer::globals::pcfdifflist{$dest} = 1; 214b274bc22SAndre Fischer $installer::logger::Info->printf("...... different file: %s\n", $dest); 215cdf0e10cSrcweir # last; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir if ( $installer::globals::iswindowsbuild ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir if ( $newcontent->{$dest}->{'uniquename'} ne $oldcontent->{$dest}->{'uniquename'} ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir $identical = 0; 223cdf0e10cSrcweir $installer::globals::pcfdifflist{$dest} = 1; 224b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 225b274bc22SAndre Fischer $installer::logger::Info->printf("...... different file: %s", $dest); 226cdf0e10cSrcweir # last; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir } 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir return $identical; 233cdf0e10cSrcweir} 234cdf0e10cSrcweir 235cdf0e10cSrcweir#################################################### 236cdf0e10cSrcweir# Calculating content of pcf file. 237cdf0e10cSrcweir#################################################### 238cdf0e10cSrcweir 239cdf0e10cSrcweirsub calculate_current_content 240cdf0e10cSrcweir{ 241cdf0e10cSrcweir my ($filesarray, $packagename) = @_; 242cdf0e10cSrcweir 243b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 244b274bc22SAndre Fischer $installer::logger::Lang->add_timestamp("Calculating content for package content file ($packagename), start"); 245cdf0e10cSrcweir 246cdf0e10cSrcweir my %globalcontent = (); 247cdf0e10cSrcweir 248cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filesarray}; $i++ ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir my %onefilehash = (); 251cdf0e10cSrcweir 252cdf0e10cSrcweir my $onefile = ${$filesarray}[$i]; 253cdf0e10cSrcweir if ( ! $onefile->{'sourcepath'} ) { installer::exiter::exit_program("ERROR: No sourcepath found for file $onefile->{'gid'}", "calculate_current_content"); } 254cdf0e10cSrcweir my $source = $onefile->{'sourcepath'}; 255cdf0e10cSrcweir if ( $onefile->{'zipfilesource'} ) { $source = $onefile->{'zipfilesource'}; } 256cdf0e10cSrcweir if ( ! -f $source ) { installer::exiter::exit_program("ERROR: Sourcefile not found: $source ($onefile->{'gid'})", "calculate_current_content"); } 257cdf0e10cSrcweir 258cdf0e10cSrcweir # For Windows the unique name inside the cabinet file also has to be saved 259cdf0e10cSrcweir my $uniquename = ""; 260cdf0e10cSrcweir if ( $installer::globals::iswindowsbuild ) { $uniquename = $onefile->{'uniquename'};} 261cdf0e10cSrcweir 262cdf0e10cSrcweir my $destination = $onefile->{'destination'}; 263cdf0e10cSrcweir my $checksum = get_md5sum($source); 264cdf0e10cSrcweir 265cdf0e10cSrcweir $onefilehash{'md5sum'} = $checksum; 266cdf0e10cSrcweir $onefilehash{'uniquename'} = $uniquename; 267cdf0e10cSrcweir 268cdf0e10cSrcweir if ( exists($globalcontent{$destination}) ) { installer::exiter::exit_program("ERROR: Destination not unique: $destination ($onefile->{'gid'})", "calculate_current_content"); } 269cdf0e10cSrcweir $globalcontent{$destination} = \%onefilehash; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 273b274bc22SAndre Fischer $installer::logger::Lang->add_timestamp("Calculating content for package content file ($packagename), start"); 274cdf0e10cSrcweir 275cdf0e10cSrcweir return \%globalcontent; 276cdf0e10cSrcweir} 277cdf0e10cSrcweir 278cdf0e10cSrcweir#################################################### 279cdf0e10cSrcweir# Writing pcf file. 280cdf0e10cSrcweir#################################################### 281cdf0e10cSrcweir 282cdf0e10cSrcweirsub create_pcfcontent_file 283cdf0e10cSrcweir{ 284cdf0e10cSrcweir my ($realpackagename, $md5sum, $filesize, $fullpackagename, $pkgversion, $epmfilecontent, $pcffilename) = @_; 285cdf0e10cSrcweir 286cdf0e10cSrcweir my @content = (); 287cdf0e10cSrcweir my $oneline = "PackageName: $realpackagename\n"; 288cdf0e10cSrcweir push(@content, $oneline); 289cdf0e10cSrcweir 290cdf0e10cSrcweir $oneline = "md5sum: $md5sum\n"; 291cdf0e10cSrcweir push(@content, $oneline); 292cdf0e10cSrcweir 293cdf0e10cSrcweir $oneline = "FileSize: $filesize\n"; 294cdf0e10cSrcweir push(@content, $oneline); 295cdf0e10cSrcweir 296cdf0e10cSrcweir $oneline = "FullPackageName: $fullpackagename\n"; 297cdf0e10cSrcweir push(@content, $oneline); 298cdf0e10cSrcweir 299cdf0e10cSrcweir $oneline = "PkgVersion: $pkgversion\n"; 300cdf0e10cSrcweir push(@content, $oneline); 301cdf0e10cSrcweir 302cdf0e10cSrcweir foreach my $dest (keys %{$installer::globals::newpcfcontent} ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir $oneline = "Files:\t$dest\t$installer::globals::newpcfcontent->{$dest}->{'md5sum'}\t$installer::globals::newpcfcontent->{$dest}->{'uniquename'}\n"; 305cdf0e10cSrcweir push(@content, $oneline); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$epmfilecontent}; $i++ ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir if ( ${$epmfilecontent}[$i] =~ /^\s*$/ ) { next; } # avoiding empty lines 311cdf0e10cSrcweir if ( ${$epmfilecontent}[$i] =~ /^\s*f\s+/ ) { next; } # ignoring files, because they can contain temporary pathes 312cdf0e10cSrcweir if (( ${$epmfilecontent}[$i] =~ /^\s*%readme\s+/ ) || ( ${$epmfilecontent}[$i] =~ /^\s*%license\s+/ )) { next; } # ignoring license and readme (language specific!) 313cdf0e10cSrcweir $oneline = "EPM:\t${$epmfilecontent}[$i]"; 314cdf0e10cSrcweir push(@content, $oneline); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir 317cdf0e10cSrcweir installer::files::save_file($pcffilename, \@content); 318cdf0e10cSrcweir} 319cdf0e10cSrcweir 320cdf0e10cSrcweir####################################################### 321cdf0e10cSrcweir# Reading the content of the package content file. 322cdf0e10cSrcweir####################################################### 323cdf0e10cSrcweir 324cdf0e10cSrcweirsub read_pcf_content 325cdf0e10cSrcweir{ 326cdf0e10cSrcweir my ($pcffilename) = @_; 327cdf0e10cSrcweir 328cdf0e10cSrcweir my %allcontent = (); 329cdf0e10cSrcweir my @epmfile = (); 330cdf0e10cSrcweir my $realpackagename = ""; 331cdf0e10cSrcweir 332cdf0e10cSrcweir my $content = installer::files::read_file($pcffilename); 333cdf0e10cSrcweir 334cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$content}; $i++ ) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir my $line = ${$content}[$i]; 337cdf0e10cSrcweir 338cdf0e10cSrcweir if ( $line =~ /^\s*PackageName\:\s*(.*?)\s*$/ ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir $realpackagename = $1; 341cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'RealPackageName'} = $realpackagename; 342cdf0e10cSrcweir next; 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir if ( $line =~ /^\s*FullPackageName\:\s*(.*?)\s*$/ ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'FullPackageName'} = $1; 348cdf0e10cSrcweir next; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir 351cdf0e10cSrcweir if ( $line =~ /^\s*FileSize\:\s*(.*?)\s*$/ ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'FileSize'} = $1; 354cdf0e10cSrcweir next; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir if ( $line =~ /^\s*PkgVersion\:\s*(.*?)\s*$/ ) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'PkgVersion'} = $1; 360cdf0e10cSrcweir next; 361cdf0e10cSrcweir } 362cdf0e10cSrcweir 363cdf0e10cSrcweir if ( $line =~ /^\s*md5sum\:\s*(.*?)\s*$/ ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'md5sum'} = $1; 366cdf0e10cSrcweir next; 367cdf0e10cSrcweir } 368cdf0e10cSrcweir 369cdf0e10cSrcweir if ( $line =~ /^\s*Files:\t(.+?)\t(.+?)\t(.*?)\s*$/ ) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir my $destination = $1; 372cdf0e10cSrcweir my $checksum = $2; 373cdf0e10cSrcweir my $uniquename = $3; 374cdf0e10cSrcweir 375cdf0e10cSrcweir my %onefilehash = (); 376cdf0e10cSrcweir $onefilehash{'md5sum'} = $checksum; 377cdf0e10cSrcweir $onefilehash{'uniquename'} = $uniquename; 378cdf0e10cSrcweir 379cdf0e10cSrcweir $allcontent{$destination} = \%onefilehash; 380cdf0e10cSrcweir next; 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir if ( $line =~ /^\s*EPM:\t(.*?)\s*$/ ) # A line can be empty in epm file 384cdf0e10cSrcweir { 385cdf0e10cSrcweir my $epmcontent = $1; 386cdf0e10cSrcweir push(@epmfile, $epmcontent); 387cdf0e10cSrcweir next; 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir if ( $realpackagename eq "" ) { installer::exiter::exit_program("ERROR: Real package name not found in pcf file: \"$pcffilename\"", "read_pcf_content"); } 392cdf0e10cSrcweir 393cdf0e10cSrcweir return ($realpackagename, \%allcontent, \@epmfile); 394cdf0e10cSrcweir} 395cdf0e10cSrcweir 396cdf0e10cSrcweir#################################################### 397cdf0e10cSrcweir# Checking, if a specific package can be 398cdf0e10cSrcweir# created at the moment. 399cdf0e10cSrcweir#################################################### 400cdf0e10cSrcweir 401cdf0e10cSrcweirsub check_package_availability 402cdf0e10cSrcweir{ 403cdf0e10cSrcweir my ($packagename) = @_; 404cdf0e10cSrcweir 405cdf0e10cSrcweir my $package_is_available = 1; 406cdf0e10cSrcweir 407cdf0e10cSrcweir my $checkfilename = $installer::globals::poolpath . $installer::globals::separator . $packagename . ".pcf.check"; 408cdf0e10cSrcweir my $lockfilename = $installer::globals::poolpath . $installer::globals::separator . $packagename . ".pcf.lock"; 409cdf0e10cSrcweir 410cdf0e10cSrcweir if (( -f $checkfilename ) || ( -f $lockfilename )) { $package_is_available = 0; } 411cdf0e10cSrcweir 412cdf0e10cSrcweir return $package_is_available; 413cdf0e10cSrcweir} 414cdf0e10cSrcweir 415cdf0e10cSrcweir#################################################### 416cdf0e10cSrcweir# Check, if the existence of the check or lock 417cdf0e10cSrcweir# file requires an exit of packaging process. 418cdf0e10cSrcweir#################################################### 419cdf0e10cSrcweir 420cdf0e10cSrcweirsub check_pool_exit 421cdf0e10cSrcweir{ 422cdf0e10cSrcweir my ( $lockfilename, $timecounter ) = @_; 423cdf0e10cSrcweir 424cdf0e10cSrcweir # How old is this lock file? 425cdf0e10cSrcweir my $timeage = installer::logger::get_file_age($lockfilename); 426cdf0e10cSrcweir 427cdf0e10cSrcweir # if ( $timeage > 1800 ) # file is older than half an hour 428cdf0e10cSrcweir if ( $timeage > 3600 ) # file is older than an hour 429cdf0e10cSrcweir { 430cdf0e10cSrcweir my $timestring = installer::logger::convert_timestring($timeage); 431cdf0e10cSrcweir my $infoline = "\nPool: Attention: \"$lockfilename\" is too old ($timestring). Removing file!\n"; 432b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 433b274bc22SAndre Fischer $installer::logger::Info->printf("... %s", $infoline); 434b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 435b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 436cdf0e10cSrcweir unlink $lockfilename; 437cdf0e10cSrcweir # installer::exiter::exit_program("ERROR: Waiting too long for removal of lock file \"$lockfilename\"", "check_pool_exit (packagepool)"); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir else 440cdf0e10cSrcweir { 441cdf0e10cSrcweir my $filecontent = installer::files::read_file($lockfilename); 442cdf0e10cSrcweir my $waittime = $timecounter * 10; 443cdf0e10cSrcweir $waittime = installer::logger::convert_timestring($waittime); 444b274bc22SAndre Fischer my $infoline = "Pool: Warning: \"$lockfilename\" blocks this process for $waittime. Lock content: \"${$filecontent}[0]\"\n"; 445b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 446b274bc22SAndre Fischer $installer::logger::Info->printf("... %s", $infoline); 447b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 448b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir} 451cdf0e10cSrcweir 452cdf0e10cSrcweir############################################################################ 453cdf0e10cSrcweir# This function logs some information, that can be used to find 454cdf0e10cSrcweir# pool problems. 455cdf0e10cSrcweir############################################################################ 456cdf0e10cSrcweir 457cdf0e10cSrcweirsub log_pool_info 458cdf0e10cSrcweir{ 459cdf0e10cSrcweir my ( $file_exists ) = @_; 460cdf0e10cSrcweir 461cdf0e10cSrcweir my $infoline = ""; 462cdf0e10cSrcweir 463cdf0e10cSrcweir # Content saved in 464cdf0e10cSrcweir # $installer::globals::savelockfilecontent = installer::files::read_file($filename); 465cdf0e10cSrcweir # $installer::globals::savelockfilename = $filename; 466cdf0e10cSrcweir 467cdf0e10cSrcweir if ( $file_exists ) 468cdf0e10cSrcweir { 469b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 470b274bc22SAndre Fischer $installer::logger::Lang->printf( 471b274bc22SAndre Fischer "Pool Problem: Lock file \"%s\" belongs to another process. This process has session id: %s.\n", 472b274bc22SAndre Fischer $installer::globals::savelockfilename, 473b274bc22SAndre Fischer $installer::globals::sessionid); 474b274bc22SAndre Fischer $installer::logger::Lang->print("Content of Lock file:\n"); 475b274bc22SAndre Fischer foreach my $line ( @{$installer::globals::savelockfilecontent} ) 476b274bc22SAndre Fischer { 477b274bc22SAndre Fischer $installer::logger::Lang->print($line); 478b274bc22SAndre Fischer } 479cdf0e10cSrcweir } 480cdf0e10cSrcweir else 481cdf0e10cSrcweir { 482b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 483b274bc22SAndre Fischer $installer::logger::Lang->printf( 484b274bc22SAndre Fischer "Pool Problem: Lock file \"%s\" does not exist anymore (this process has session id: %s).\n", 485b274bc22SAndre Fischer $installer::globals::savelockfilename, 486b274bc22SAndre Fischer $installer::globals::sessionid); 487cdf0e10cSrcweir } 488cdf0e10cSrcweir} 489cdf0e10cSrcweir 490cdf0e10cSrcweir############################################################################ 491cdf0e10cSrcweir# Checking, if this process is the owner of the lock file in the pool. 492cdf0e10cSrcweir# This can be determined by the Process ID, that is written at the 493cdf0e10cSrcweir# beginning of the first line into the lock file. 494cdf0e10cSrcweir############################################################################ 495cdf0e10cSrcweir 496cdf0e10cSrcweirsub process_is_owner 497cdf0e10cSrcweir{ 498cdf0e10cSrcweir my ( $filename ) = @_; 499cdf0e10cSrcweir 500cdf0e10cSrcweir my $process_is_owner = 0; 501cdf0e10cSrcweir 502cdf0e10cSrcweir $installer::globals::savelockfilecontent = installer::files::read_file($filename); 503cdf0e10cSrcweir $installer::globals::savelockfilename = $filename; 504cdf0e10cSrcweir 505cdf0e10cSrcweir if ( ${$installer::globals::savelockfilecontent}[0] =~ /^\s*\Q$installer::globals::sessionid\E\s+/ ) { $process_is_owner = 1; } 506cdf0e10cSrcweir 507cdf0e10cSrcweir return $process_is_owner; 508cdf0e10cSrcweir} 509cdf0e10cSrcweir 510cdf0e10cSrcweir#################################################### 511cdf0e10cSrcweir# Removing a package from installation set, if 512cdf0e10cSrcweir# there were pooling problems. 513cdf0e10cSrcweir#################################################### 514cdf0e10cSrcweir 515cdf0e10cSrcweirsub remove_package_from_installset 516cdf0e10cSrcweir{ 517cdf0e10cSrcweir my ($newpackagepath) = @_; 518cdf0e10cSrcweir 519b274bc22SAndre Fischer $installer::logger::Lang->printf("Pool problem: Removing package \"%s\" from installation set!\n", 520b274bc22SAndre Fischer $newpackagepath); 521cdf0e10cSrcweir 522cdf0e10cSrcweir if ( -f $newpackagepath ) { unlink $newpackagepath; } 523cdf0e10cSrcweir if ( -d $newpackagepath ) { installer::systemactions::remove_complete_directory($newpackagepath, 1); } 524cdf0e10cSrcweir 525cdf0e10cSrcweir # Keeping the content of @installer::globals::installsetcontent up to date. Removing the last package. 526cdf0e10cSrcweir pop(@installer::globals::installsetcontent); 527cdf0e10cSrcweir} 528cdf0e10cSrcweir 529cdf0e10cSrcweir#################################################### 530cdf0e10cSrcweir# Check, if the package is in the pool and if 531cdf0e10cSrcweir# there are no changes in the package. 532cdf0e10cSrcweir#################################################### 533cdf0e10cSrcweir 534cdf0e10cSrcweirsub package_is_up_to_date 535cdf0e10cSrcweir{ 536cdf0e10cSrcweir my ($allvariables, $onepackage, $packagename, $newepmcontent, $filesinpackage, $installdir, $subdir, $languagestringref) = @_; 537cdf0e10cSrcweir 538b274bc22SAndre Fischer $installer::logger::Info->printf("... checking pool package ...\n", $packagename); 539cdf0e10cSrcweir 540cdf0e10cSrcweir installer::logger::include_header_into_logfile("Checking package in pool: $packagename"); 541cdf0e10cSrcweir 542cdf0e10cSrcweir if ( ! $installer::globals::poolpathset ) { installer::packagepool::set_pool_path(); } 543cdf0e10cSrcweir if ( ! $installer::globals::sessionidset ) { installer::packagepool::set_sessionid(); } 544cdf0e10cSrcweir 545cdf0e10cSrcweir my $infoline = ""; 546cdf0e10cSrcweir # Resetting some variables for this package 547cdf0e10cSrcweir my $package_is_up_to_date = 0; 548cdf0e10cSrcweir my $realpackagename = ""; 549cdf0e10cSrcweir my $oldepmcontent = ""; 550cdf0e10cSrcweir my $waited_for_check = 0; 551cdf0e10cSrcweir my $waited_for_lock = 0; 552cdf0e10cSrcweir $installer::globals::newpcfcontentcalculated = 0; 553cdf0e10cSrcweir %installer::globals::pcfdifflist = (); 554cdf0e10cSrcweir @installer::globals::pcfdiffcomment = (); 555cdf0e10cSrcweir @installer::globals::epmdifflist = (); 556cdf0e10cSrcweir 557cdf0e10cSrcweir # Reading the package content file, if this file exists (extension *.pcf) 558cdf0e10cSrcweir my $filename = $installer::globals::poolpath . $installer::globals::separator . $packagename . ".pcf"; 559cdf0e10cSrcweir my $checkfilename = $installer::globals::poolpath . $installer::globals::separator . $packagename . ".pcf.check"; 560cdf0e10cSrcweir my $lockfilename = $installer::globals::poolpath . $installer::globals::separator . $packagename . ".pcf.lock"; 561cdf0e10cSrcweir # Saving name in global variable, so that this file can be removed somewhere else (at the end of "put_content_into_pool"). 562cdf0e10cSrcweir $installer::globals::poolcheckfilename = $checkfilename; 563cdf0e10cSrcweir $installer::globals::poollockfilename = $lockfilename; 564cdf0e10cSrcweir 565cdf0e10cSrcweir my @checkfilecontent = ("$installer::globals::sessionid $installer::globals::product $$languagestringref $checkfilename"); # $$ is the process id 566cdf0e10cSrcweir my @lockfilecontent = ("$installer::globals::sessionid $installer::globals::product $$languagestringref $lockfilename"); # $$ is the process id 567cdf0e10cSrcweir 568cdf0e10cSrcweir # Waiting, step 1 569cdf0e10cSrcweir # Checking, if another process checks this package at the moment 570cdf0e10cSrcweir my $timecounter = 0; 571cdf0e10cSrcweir while ( -f $checkfilename ) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir $timecounter++; 574cdf0e10cSrcweir 575cdf0e10cSrcweir # including an exit to enable creation of other packages 576cdf0e10cSrcweir if (( $timecounter == 1 ) && ( ! exists($installer::globals::poolshiftedpackages{$packagename}) )) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir $package_is_up_to_date = 3; # repeat this package later 579cdf0e10cSrcweir return $package_is_up_to_date; 580cdf0e10cSrcweir } 581cdf0e10cSrcweir 582cdf0e10cSrcweir $infoline = "Pool: $checkfilename exists. WAITING 10 seconds ($timecounter).\n"; 583b274bc22SAndre Fischer if ( $timecounter == 1 ) 584b274bc22SAndre Fischer { 585b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 586b274bc22SAndre Fischer } 587b274bc22SAndre Fischer $installer::logger::Info->printf("... %s", $infoline); 588b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 589cdf0e10cSrcweir if ( $timecounter % 100 == 0 ) { check_pool_exit($checkfilename, $timecounter); } 590cdf0e10cSrcweir sleep 10; # process sleeps 10 seconds 591cdf0e10cSrcweir $waited_for_check = 1; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir 594cdf0e10cSrcweir # Creating file, showing that this package is checked at the moment by this process. No other process can reach this. 595cdf0e10cSrcweir installer::files::save_file($checkfilename, \@checkfilecontent); # Creating the Lock, to check this package. This blocks all other processes. 596cdf0e10cSrcweir $installer::globals::processhaspoolcheckfile = 1; 597cdf0e10cSrcweir 598cdf0e10cSrcweir # Check, if the Lock file creation was really successful 599cdf0e10cSrcweir if ( ! -f $checkfilename ) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$checkfilename\" could not be created successfully or was removed by another process (A)!\n"; 602b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 603cdf0e10cSrcweir log_pool_info(0); 604cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 605cdf0e10cSrcweir return $package_is_up_to_date; 606cdf0e10cSrcweir } 607cdf0e10cSrcweir 608cdf0e10cSrcweir if ( ! process_is_owner($checkfilename) ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$checkfilename\" belongs to another process (A)!\n"; 611b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 612cdf0e10cSrcweir log_pool_info(1); 613cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 614cdf0e10cSrcweir return $package_is_up_to_date; 615cdf0e10cSrcweir } 616cdf0e10cSrcweir 617cdf0e10cSrcweir $infoline = "Pool: Created file: $checkfilename\n"; 618b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 619b274bc22SAndre Fischer if ( $waited_for_check ) 620b274bc22SAndre Fischer { 621b274bc22SAndre Fischer $installer::logger::Info->printf("... %s", $infoline); 622b274bc22SAndre Fischer } 623cdf0e10cSrcweir 624cdf0e10cSrcweir # Waiting, step 2 625cdf0e10cSrcweir # Checking, if another process creates this package at the moment 626cdf0e10cSrcweir $timecounter = 0; 627cdf0e10cSrcweir while ( -f $lockfilename ) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir $timecounter++; 630cdf0e10cSrcweir $infoline = "Pool: $lockfilename exists. WAITING 10 seconds ($timecounter).\n"; 631b274bc22SAndre Fischer if ( $timecounter == 1 ) 632b274bc22SAndre Fischer { 633b274bc22SAndre Fischer $installer::logger::Info->print("\n"); 634b274bc22SAndre Fischer } 635b274bc22SAndre Fischer $installer::logger::Info->printf("... %s", $infoline); 636b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 637cdf0e10cSrcweir if ( $timecounter % 100 == 0 ) { check_pool_exit($lockfilename, $timecounter); } 638cdf0e10cSrcweir sleep 10; # process sleeps 10 seconds 639cdf0e10cSrcweir $waited_for_lock = 1; 640cdf0e10cSrcweir } 641cdf0e10cSrcweir 642cdf0e10cSrcweir # No lock file exists, therefore no process creates this package at the moment. Check can be done now. 643b274bc22SAndre Fischer if ( $waited_for_lock ) 644b274bc22SAndre Fischer { 645b274bc22SAndre Fischer $installer::logger::Info->printf("... Pool: Proceeding, %s was removed.\n", $lockfilename); 646b274bc22SAndre Fischer } 647cdf0e10cSrcweir 648cdf0e10cSrcweir my $package_already_exists = 0; 649cdf0e10cSrcweir 650cdf0e10cSrcweir if ( -f $filename ) 651cdf0e10cSrcweir { 652cdf0e10cSrcweir # Calculating content for pcf file 653cdf0e10cSrcweir $installer::globals::newpcfcontent = calculate_current_content($filesinpackage, $packagename); 654cdf0e10cSrcweir $installer::globals::newpcfcontentcalculated = 1; 655cdf0e10cSrcweir 656cdf0e10cSrcweir # reading the existing pcf file 657cdf0e10cSrcweir ($realpackagename, $oldpcfcontent, $oldepmcontent) = read_pcf_content($filename); 658cdf0e10cSrcweir 659cdf0e10cSrcweir # First check: Package has to exist in pool (directories on Solaris) 660cdf0e10cSrcweir my $fullpackage = $installer::globals::poolpath . $installer::globals::separator . $realpackagename; 661cdf0e10cSrcweir if ( $installer::globals::issolarisbuild ) { $fullpackage = $fullpackage . ".tar"; } 662cdf0e10cSrcweir if ( -f $fullpackage ) 663cdf0e10cSrcweir { 664cdf0e10cSrcweir $package_already_exists = 1; 665cdf0e10cSrcweir # Second check: Only files 666cdf0e10cSrcweir my $content_is_identical = compare_package_content($oldpcfcontent, $installer::globals::newpcfcontent); 667cdf0e10cSrcweir 668cdf0e10cSrcweir # Third check for Unix: Changes in the epm file? 669cdf0e10cSrcweir if (( $content_is_identical ) && ( ! $installer::globals::iswindowsbuild )) 670cdf0e10cSrcweir { 671cdf0e10cSrcweir $content_is_identical = compare_epm_content($oldepmcontent, $newepmcontent); 672cdf0e10cSrcweir } 673cdf0e10cSrcweir 674cdf0e10cSrcweir if ( $content_is_identical ) { $package_is_up_to_date = 1; } 675cdf0e10cSrcweir } 676cdf0e10cSrcweir } 677cdf0e10cSrcweir 678cdf0e10cSrcweir if ( $package_is_up_to_date ) 679cdf0e10cSrcweir { 680cdf0e10cSrcweir $infoline = "Pool: $packagename: No new content, using existing package\n"; 681b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 682b274bc22SAndre Fischer $installer::logger::Info->printf("... using package from pool\n"); 683cdf0e10cSrcweir } 684cdf0e10cSrcweir else 685cdf0e10cSrcweir { 686cdf0e10cSrcweir if ( $package_already_exists ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir $infoline = "Pool: $packagename: Contains new content, creating new package. Differences:\n"; 689b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 690b274bc22SAndre Fischer foreach my $dest ( sort keys %installer::globals::pcfdifflist ) 691b274bc22SAndre Fischer { 692b274bc22SAndre Fischer $installer::logger::Lang->printf("%s\n", $dest); 693b274bc22SAndre Fischer } 694b274bc22SAndre Fischer foreach my $dest ( @installer::globals::pcfdiffcomment ) 695b274bc22SAndre Fischer { 696b274bc22SAndre Fischer $installer::logger::Lang->printf("%s\n", $dest); 697b274bc22SAndre Fischer } 698b274bc22SAndre Fischer foreach my $dest ( @installer::globals::epmdifflist ) 699b274bc22SAndre Fischer { 700b274bc22SAndre Fischer $installer::logger::Lang->printf("%s\n", $dest); 701b274bc22SAndre Fischer } 702cdf0e10cSrcweir } 703cdf0e10cSrcweir else 704cdf0e10cSrcweir { 705cdf0e10cSrcweir $infoline = "Pool: $packagename: Does not exist in pool.\n"; 706b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 707cdf0e10cSrcweir } 708cdf0e10cSrcweir 709b274bc22SAndre Fischer $installer::logger::Info->printf("... packaging required\n"); 710cdf0e10cSrcweir %installer::globals::xpdpackageinfo = (); # reset the filled hash, because the package cannot be used. 711cdf0e10cSrcweir 712cdf0e10cSrcweir # Creating lock mechanism, so that other processes do not create this package, too. 713cdf0e10cSrcweir installer::files::save_file($lockfilename, \@lockfilecontent); # Creating the Lock, to create this package (Lock for check still exists). 714cdf0e10cSrcweir $installer::globals::processhaspoollockfile = 1; 715cdf0e10cSrcweir 716cdf0e10cSrcweir # Check if creation of Lock file was really successful 717cdf0e10cSrcweir 718cdf0e10cSrcweir if ( ! -f $lockfilename ) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$lockfilename\" could not be created successfully or was removed by another process (D)!\n"; 721b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 722cdf0e10cSrcweir log_pool_info(0); 723cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 724cdf0e10cSrcweir return $package_is_up_to_date; 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir if ( ! process_is_owner($lockfilename) ) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$lockfilename\" belongs to another process (D)!\n"; 730b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 731cdf0e10cSrcweir log_pool_info(1); 732cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 733cdf0e10cSrcweir return $package_is_up_to_date; 734cdf0e10cSrcweir } 735cdf0e10cSrcweir 736cdf0e10cSrcweir $infoline = "Pool: Created file: $lockfilename\n"; 737b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 738cdf0e10cSrcweir } 739cdf0e10cSrcweir 740cdf0e10cSrcweir my $newpackagepath = ""; 741cdf0e10cSrcweir 742cdf0e10cSrcweir if ( $package_is_up_to_date ) 743cdf0e10cSrcweir { 744cdf0e10cSrcweir # Before the package is copied into the installation set, it has to be checked, if this process is really the owner of this lock file.. 745cdf0e10cSrcweir # Check, if lock file still exists and if this process is the owner. 746cdf0e10cSrcweir 747cdf0e10cSrcweir if ( ! -f $checkfilename ) 748cdf0e10cSrcweir { 749cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$checkfilename\" was removed by another process (B)!\n"; 750b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 751cdf0e10cSrcweir log_pool_info(0); 752cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 753cdf0e10cSrcweir return $package_is_up_to_date; 754cdf0e10cSrcweir } 755cdf0e10cSrcweir 756cdf0e10cSrcweir if ( ! process_is_owner($checkfilename) ) 757cdf0e10cSrcweir { 758cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$checkfilename\" belongs to another process (B)!\n"; 759b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 760cdf0e10cSrcweir log_pool_info(1); 761cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 762cdf0e10cSrcweir return $package_is_up_to_date; 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir # Copying the package from the pool into the installation set 766cdf0e10cSrcweir $newpackagepath = copy_package_from_pool($installdir, $subdir, $realpackagename); 767cdf0e10cSrcweir } 768cdf0e10cSrcweir 769cdf0e10cSrcweir # Before the lock file in the pool can be removed, it has to be checked, if this process is still the owner of this lock file. 770cdf0e10cSrcweir # Check, if lock file still exists and if this process is the owner. 771cdf0e10cSrcweir if ( ! -f $checkfilename ) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$checkfilename\" was removed by another process (C)!\n"; 774b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 775cdf0e10cSrcweir log_pool_info(0); 776cdf0e10cSrcweir 777cdf0e10cSrcweir # removing new package from installation set 778cdf0e10cSrcweir if ( $newpackagepath ne "" ) { remove_package_from_installset($newpackagepath); } # A file was copied and a problem occured with pooling 779cdf0e10cSrcweir 780cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 781cdf0e10cSrcweir return $package_is_up_to_date; 782cdf0e10cSrcweir } 783cdf0e10cSrcweir 784cdf0e10cSrcweir if ( ! process_is_owner($checkfilename) ) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$checkfilename\" belongs to another process (C)!\n"; 787b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 788cdf0e10cSrcweir log_pool_info(1); 789cdf0e10cSrcweir 790cdf0e10cSrcweir # removing new package from installation set 791cdf0e10cSrcweir if ( $newpackagepath ne "" ) { remove_package_from_installset($newpackagepath); } # A file was copied and a problem occured with pooling 792cdf0e10cSrcweir 793cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 794cdf0e10cSrcweir return $package_is_up_to_date; 795cdf0e10cSrcweir } 796cdf0e10cSrcweir 797cdf0e10cSrcweir # Removing the check file, releasing this package for the next process. 798cdf0e10cSrcweir # The Lock to create this package still exists, if required. 799cdf0e10cSrcweir unlink $checkfilename; 800cdf0e10cSrcweir $installer::globals::processhaspoolcheckfile = 0; 801cdf0e10cSrcweir $infoline = "Pool: Removing file: $checkfilename\n"; 802b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 803cdf0e10cSrcweir 804cdf0e10cSrcweir # Last chance before packaging starts, to check, if this process is really still owner 805cdf0e10cSrcweir # of the packaging lock file. If not, this packaging process can be repeated. 806cdf0e10cSrcweir if ( $installer::globals::processhaspoollockfile ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir if ( ! -f $lockfilename ) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$lockfilename\" was removed by another process (E)!\n"; 811b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 812cdf0e10cSrcweir log_pool_info(0); 813cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 814cdf0e10cSrcweir return $package_is_up_to_date; 815cdf0e10cSrcweir } 816cdf0e10cSrcweir 817cdf0e10cSrcweir if ( ! process_is_owner($lockfilename) ) 818cdf0e10cSrcweir { 819cdf0e10cSrcweir $infoline = "Pool problem: Pool lock file \"$lockfilename\" belongs to another process (E)!\n"; 820b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 821cdf0e10cSrcweir log_pool_info(1); 822cdf0e10cSrcweir $package_is_up_to_date = 4; # repeat this package 823cdf0e10cSrcweir return $package_is_up_to_date; 824cdf0e10cSrcweir } 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir # Collecting log information 828cdf0e10cSrcweir if ( $package_is_up_to_date == 1 ) { $installer::globals::poolpackages{$packagename} = 1; } 829cdf0e10cSrcweir if ( $package_is_up_to_date == 0 ) 830cdf0e10cSrcweir { 831cdf0e10cSrcweir my @packreasons = (); 832cdf0e10cSrcweir if ( $package_already_exists ) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir $infoline = "\t\tPool: $packagename: Contains new content, creating new package. Differences:\n"; 835cdf0e10cSrcweir push( @packreasons, $infoline); 836cdf0e10cSrcweir foreach my $dest ( sort keys %installer::globals::pcfdifflist ) { push( @packreasons, "\t\t$dest\n"); } 837cdf0e10cSrcweir foreach my $dest ( @installer::globals::pcfdiffcomment ) { push( @packreasons, "\t\t$dest"); } 838cdf0e10cSrcweir foreach my $dest ( @installer::globals::epmdifflist ) { push( @packreasons, "\t\t$dest"); } 839cdf0e10cSrcweir } 840cdf0e10cSrcweir else 841cdf0e10cSrcweir { 842cdf0e10cSrcweir $infoline = "\t\tPool: $packagename: Does not exist in pool.\n"; 843cdf0e10cSrcweir push( @packreasons, $infoline); 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir $installer::globals::createpackages{$packagename} = \@packreasons; 847cdf0e10cSrcweir } 848cdf0e10cSrcweir 849cdf0e10cSrcweir return $package_is_up_to_date; 850cdf0e10cSrcweir} 851cdf0e10cSrcweir 852cdf0e10cSrcweir################################################### 853cdf0e10cSrcweir# Determine, which package was created newly 854cdf0e10cSrcweir################################################### 855cdf0e10cSrcweir 856cdf0e10cSrcweirsub determine_new_packagename 857cdf0e10cSrcweir{ 858cdf0e10cSrcweir my ( $dir ) = @_; 859cdf0e10cSrcweir 860cdf0e10cSrcweir my ($newcontent, $allcontent) = installer::systemactions::find_new_content_in_directory($dir, \@installer::globals::installsetcontent); 861cdf0e10cSrcweir @installer::globals::installsetcontent = (); 862cdf0e10cSrcweir foreach my $element ( @{$allcontent} ) { push(@installer::globals::installsetcontent, $element); } 863cdf0e10cSrcweir 864cdf0e10cSrcweir my $newentriesnumber = $#{$newcontent} + 1; 865cdf0e10cSrcweir if ( $newentriesnumber > 1 ) 866cdf0e10cSrcweir { 867cdf0e10cSrcweir my $newpackages = ""; 868cdf0e10cSrcweir foreach my $onepackage ( @{$newcontent} ) { $newpackages = $newpackages . " " . $onepackage; } 869cdf0e10cSrcweir installer::exiter::exit_program("ERROR: More than one new package in directory $dir ($newpackages)", "determine_new_packagename (packagepool)"); 870cdf0e10cSrcweir } 871cdf0e10cSrcweir elsif ( $newentriesnumber < 1 ) 872cdf0e10cSrcweir { 873cdf0e10cSrcweir installer::exiter::exit_program("ERROR: No new package in directory $dir", "determine_new_packagename (packagepool)"); 874cdf0e10cSrcweir } 875cdf0e10cSrcweir my $newpackage = ${$newcontent}[0]; 876cdf0e10cSrcweir 877cdf0e10cSrcweir return $newpackage; 878cdf0e10cSrcweir} 879cdf0e10cSrcweir 880cdf0e10cSrcweir#################################################### 881cdf0e10cSrcweir# Including content into the package pool 882cdf0e10cSrcweir#################################################### 883cdf0e10cSrcweir 884cdf0e10cSrcweirsub put_content_into_pool 885cdf0e10cSrcweir{ 886cdf0e10cSrcweir my ($packagename, $installdir, $subdir, $filesinpackage, $epmfilecontent) = @_; 887cdf0e10cSrcweir 888cdf0e10cSrcweir my $infoline = ""; 889cdf0e10cSrcweir 890cdf0e10cSrcweir my $fullinstalldir = $installdir . $installer::globals::separator . $subdir; 891cdf0e10cSrcweir my $fullrealpackagename = determine_new_packagename($fullinstalldir); 892cdf0e10cSrcweir my $realpackagename = $fullrealpackagename; 893cdf0e10cSrcweir installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$realpackagename); 894cdf0e10cSrcweir 895cdf0e10cSrcweir installer::logger::include_header_into_logfile("Adding content into the package pool: $realpackagename (PackageName: $packagename)"); 896cdf0e10cSrcweir 897cdf0e10cSrcweir # Calculating content for pcf file, if not already done in "package_is_up_to_date" 898cdf0e10cSrcweir if ( ! $installer::globals::newpcfcontentcalculated ) 899cdf0e10cSrcweir { 900cdf0e10cSrcweir $installer::globals::newpcfcontent = calculate_current_content($filesinpackage, $packagename); 901cdf0e10cSrcweir $installer::globals::newpcfcontentcalculated = 1; 902cdf0e10cSrcweir } 903cdf0e10cSrcweir 904cdf0e10cSrcweir # Determining md5sum and FileSize for the new package and saving in pcf file 905cdf0e10cSrcweir my $md5sum = installer::xpdinstaller::get_md5_value($fullrealpackagename); 906cdf0e10cSrcweir my $filesize = installer::xpdinstaller::get_size_value($fullrealpackagename); 907cdf0e10cSrcweir my $fullpackagename = installer::xpdinstaller::get_fullpkgname_value($fullrealpackagename); 908cdf0e10cSrcweir my $pkgversion = installer::xpdinstaller::get_pkgversion_value($fullrealpackagename); 909cdf0e10cSrcweir 910cdf0e10cSrcweir # Put package content file (pcf) into pool 911cdf0e10cSrcweir my $pcffilename = $installer::globals::poolpath . $installer::globals::separator . $packagename . ".pcf"; 912cdf0e10cSrcweir create_pcfcontent_file($realpackagename, $md5sum, $filesize, $fullpackagename, $pkgversion, $epmfilecontent, $pcffilename); 913cdf0e10cSrcweir 914cdf0e10cSrcweir # Creating xpd info 915cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'FileSize'} = $filesize; 916cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'FullPackageName'} = $fullpackagename; 917cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'md5sum'} = $md5sum; 918cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'RealPackageName'} = $realpackagename; 919cdf0e10cSrcweir $installer::globals::xpdpackageinfo{'PkgVersion'} = $pkgversion; 920cdf0e10cSrcweir 921cdf0e10cSrcweir # Put package into pool 922cdf0e10cSrcweir $infoline = "Pool: Adding package \"$packagename\" into pool.\n"; 923b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 924cdf0e10cSrcweir 925cdf0e10cSrcweir # Copying with unique name, containing PID. Only renaming if everything was fine. 926cdf0e10cSrcweir my $realdestination = ""; 927cdf0e10cSrcweir my $uniquedestination = ""; 928cdf0e10cSrcweir if ( -f $fullrealpackagename ) 929cdf0e10cSrcweir { 930cdf0e10cSrcweir $realdestination = $installer::globals::poolpath . $installer::globals::separator . $realpackagename; 931cdf0e10cSrcweir $uniquedestination = $realdestination . "." . $installer::globals::sessionid; 932cdf0e10cSrcweir installer::systemactions::copy_one_file($fullrealpackagename, $uniquedestination); 933cdf0e10cSrcweir } 934cdf0e10cSrcweir 935cdf0e10cSrcweir # Copying Solaris packages (as tar files) 936cdf0e10cSrcweir if ( -d $fullrealpackagename ) 937cdf0e10cSrcweir { 938cdf0e10cSrcweir my $tarfilename = $packagename . ".tar"; 939cdf0e10cSrcweir my $fulltarfilename = $fullinstalldir . $installer::globals::separator . $tarfilename; 940cdf0e10cSrcweir my $size = installer::worker::tar_package($fullinstalldir, $packagename, $tarfilename, $installer::globals::getuidpath); 941cdf0e10cSrcweir if (( ! -f $fulltarfilename ) || ( ! ( $size > 0 ))) { installer::exiter::exit_program("ERROR: Missing file: $fulltarfilename", "put_content_into_pool"); } 942cdf0e10cSrcweir $realdestination = $installer::globals::poolpath . $installer::globals::separator . $tarfilename; 943cdf0e10cSrcweir $uniquedestination = $realdestination . "." . $installer::globals::sessionid; 944cdf0e10cSrcweir installer::systemactions::copy_one_file($fulltarfilename, $uniquedestination); 945cdf0e10cSrcweir unlink $fulltarfilename; 946cdf0e10cSrcweir } 947cdf0e10cSrcweir 948cdf0e10cSrcweir # Before the new package is renamed in the pool, it has to be checked, if this process still has the lock for this package. 949cdf0e10cSrcweir # Check, if lock file still exists and if this process is the owner. Otherwise a pool error occured. 950cdf0e10cSrcweir if ( ! -f $installer::globals::poollockfilename ) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir unlink $uniquedestination; # removing file from pool 953cdf0e10cSrcweir log_pool_info(0); 954cdf0e10cSrcweir installer::exiter::exit_program("ERROR: Pool lock file \"$installer::globals::poollockfilename\" was removed by another process (F)!", "put_content_into_pool"); 955cdf0e10cSrcweir } 956cdf0e10cSrcweir 957cdf0e10cSrcweir if ( ! process_is_owner($installer::globals::poollockfilename) ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir unlink $uniquedestination; # removing file from pool 960cdf0e10cSrcweir log_pool_info(1); 961cdf0e10cSrcweir installer::exiter::exit_program("ERROR: Pool lock file \"$installer::globals::poollockfilename\" belongs to another process (F)!", "put_content_into_pool"); 962cdf0e10cSrcweir } 963cdf0e10cSrcweir 964cdf0e10cSrcweir # Renaming the file in the pool (atomic step) 965cdf0e10cSrcweir rename($uniquedestination, $realdestination); 966cdf0e10cSrcweir 967cdf0e10cSrcweir $infoline = "Pool: Renamed file: \"$uniquedestination\" to \"$realdestination\".\n"; 968b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 969cdf0e10cSrcweir 970cdf0e10cSrcweir # Before the lock file in the pool can be removed, it has to be checked, if this process is still the owner of this lock file. 971cdf0e10cSrcweir # Check, if lock file still exists and if this process is the owner. Otherwise a pool error occured. 972cdf0e10cSrcweir if ( ! -f $installer::globals::poollockfilename ) 973cdf0e10cSrcweir { 974cdf0e10cSrcweir log_pool_info(0); 975cdf0e10cSrcweir installer::exiter::exit_program("ERROR: Pool lock file \"$installer::globals::poollockfilename\" was removed by another process (G)!", "put_content_into_pool"); 976cdf0e10cSrcweir } 977cdf0e10cSrcweir 978cdf0e10cSrcweir if ( ! process_is_owner($installer::globals::poollockfilename) ) 979cdf0e10cSrcweir { 980cdf0e10cSrcweir log_pool_info(1); 981cdf0e10cSrcweir installer::exiter::exit_program("ERROR: Pool lock file \"$installer::globals::poollockfilename\" belongs to another process (G)!", "put_content_into_pool"); 982cdf0e10cSrcweir } 983cdf0e10cSrcweir 984cdf0e10cSrcweir # Removing lock file, so that other processes can use this package now 985cdf0e10cSrcweir unlink $installer::globals::poollockfilename; 986cdf0e10cSrcweir $installer::globals::processhaspoollockfile = 0; 987cdf0e10cSrcweir $infoline = "Pool: Removing file: $installer::globals::poollockfilename\n"; 988b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 989cdf0e10cSrcweir} 990cdf0e10cSrcweir 991cdf0e10cSrcweir################################################################### 992cdf0e10cSrcweir# Copying a package from the pool into the installation set 993cdf0e10cSrcweir################################################################### 994cdf0e10cSrcweir 995cdf0e10cSrcweirsub copy_package_from_pool 996cdf0e10cSrcweir{ 997cdf0e10cSrcweir my ($installdir, $subdir, $packagename) = @_; 998cdf0e10cSrcweir 999cdf0e10cSrcweir my $infoline = "Pool: Using package \"$packagename\" from pool.\n"; 1000b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 1001cdf0e10cSrcweir my $sourcefile = $installer::globals::poolpath . $installer::globals::separator . $packagename; 1002cdf0e10cSrcweir if ( $installer::globals::issolarisbuild ) { $sourcefile = $sourcefile . ".tar"; } 1003cdf0e10cSrcweir if ( ! -f $sourcefile ) { installer::exiter::exit_program("ERROR: Missing package in package pool: \"$sourcefile\"", "copy_package_from_pool"); } 1004cdf0e10cSrcweir my $destination = $installdir . $installer::globals::separator . $subdir; 1005cdf0e10cSrcweir if ( ! -d $destination ) { installer::systemactions::create_directory($destination); } 1006cdf0e10cSrcweir my $destinationfile = $destination . $installer::globals::separator . $packagename; 1007cdf0e10cSrcweir if ( $installer::globals::issolarisbuild ) { $destinationfile = $destinationfile . ".tar"; } 1008cdf0e10cSrcweir if ( -f $sourcefile ) { installer::systemactions::copy_one_file($sourcefile, $destinationfile); } 1009cdf0e10cSrcweir # Unpacking for Solaris 1010cdf0e10cSrcweir if ( $installer::globals::issolarisbuild ) 1011cdf0e10cSrcweir { 1012cdf0e10cSrcweir my $tarfilename = $packagename . ".tar"; 1013cdf0e10cSrcweir installer::worker::untar_package($destination, $tarfilename, $installer::globals::getuidpath); 1014cdf0e10cSrcweir unlink $destinationfile; 1015cdf0e10cSrcweir $destinationfile =~ s/.tar\s*$//; 1016cdf0e10cSrcweir } 1017cdf0e10cSrcweir 1018cdf0e10cSrcweir # Keeping the content of @installer::globals::installsetcontent up to date (with full pathes): 1019cdf0e10cSrcweir push(@installer::globals::installsetcontent, $destinationfile); 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir return $destinationfile; 1022cdf0e10cSrcweir} 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir################################################################### 1025cdf0e10cSrcweir# Counting keys in hash 1026cdf0e10cSrcweir################################################################### 1027cdf0e10cSrcweir 1028cdf0e10cSrcweirsub get_count 1029cdf0e10cSrcweir{ 1030cdf0e10cSrcweir my ( $hashref ) = @_; 1031cdf0e10cSrcweir 1032cdf0e10cSrcweir my $counter = 0; 1033cdf0e10cSrcweir foreach my $onekey ( keys %{$hashref} ) { $counter++; } 1034cdf0e10cSrcweir return $counter; 1035cdf0e10cSrcweir} 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir################################################################### 1038cdf0e10cSrcweir# Logging some pool information 1039cdf0e10cSrcweir################################################################### 1040cdf0e10cSrcweir 1041cdf0e10cSrcweirsub log_pool_statistics 1042cdf0e10cSrcweir{ 1043cdf0e10cSrcweir my $infoline = ""; 1044cdf0e10cSrcweir 1045cdf0e10cSrcweir installer::logger::include_header_into_logfile("Pool statistics:"); 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir # Info collected in global hashes 1048cdf0e10cSrcweir # %installer::globals::createpackages 1049cdf0e10cSrcweir # %installer::globals::poolpackages 1050cdf0e10cSrcweir 1051cdf0e10cSrcweir my $pool_packages = get_count(\%installer::globals::poolpackages); 1052cdf0e10cSrcweir my $created_packages = get_count(\%installer::globals::createpackages); 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir $infoline = "Number of packages from pool: $pool_packages\n"; 1055b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir foreach my $packagename ( sort keys(%installer::globals::poolpackages) ) 1058cdf0e10cSrcweir { 1059cdf0e10cSrcweir $infoline = "\t$packagename\n"; 1060b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 1061cdf0e10cSrcweir } 1062cdf0e10cSrcweir 1063b274bc22SAndre Fischer $installer::logger::Lang->print("\n"); 1064b274bc22SAndre Fischer $installer::logger::Lang->print("Number of packages that were created: %s\n", $created_packages); 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir foreach my $packagename ( sort keys(%installer::globals::createpackages) ) 1067cdf0e10cSrcweir { 1068cdf0e10cSrcweir $infoline = "\t$packagename\n"; 1069b274bc22SAndre Fischer $installer::logger::Lang->print($infoline); 1070cdf0e10cSrcweir my $reason = $installer::globals::createpackages{$packagename}; 1071cdf0e10cSrcweir 1072b274bc22SAndre Fischer foreach my $line (@reason) 1073cdf0e10cSrcweir { 1074b274bc22SAndre Fischer $installer::logger::Lang->print($line); 1075cdf0e10cSrcweir } 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir} 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir1; 1080