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