2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer
::archivefiles
;
21 use Archive
::Zip
qw( :ERROR_CODES :CONSTANTS );
23 use installer
::globals
;
24 use installer
::logger
;
25 use installer
::pathanalyzer
;
26 use installer
::systemactions
;
29 #################################################################
30 # Changing the name for files with flag RENAME_TO_LANGUAGE
31 #################################################################
33 sub put_language_into_name
35 my ( $oldname, $onelanguage ) = @_;
42 if ( $oldname =~ /en-US/ ) # files, that contain the language in the file name
45 $newname =~ s/en-US/$onelanguage/;
47 else # files, that do not contain the language in the file name
49 if ( $oldname =~ /^\s*(.*)(\..*?)\s*$/ ) # files with extension
60 $newname = $1 . "_" . $onelanguage . $2;
66 #################################################################
67 # Converting patchfiles string into array
68 #################################################################
70 sub get_patch_file_list
72 my ( $patchfilestring ) = @_;
74 $patchfilestring =~ s/^\s*\(?//;
75 $patchfilestring =~ s/\)?\s*$//;
76 $patchfilestring =~ s/^\s*\///;
77 $patchfilestring =~ s/^\s*\\//;
79 my @patchfilesarray = split /,\s*/, $patchfilestring;
81 return \
@patchfilesarray;
84 #################################################################
85 # Reading all executables in the "manifest.xml"
86 #################################################################
88 sub get_all_executables_from_manifest
90 my ($unzipdir, $manifestfile, $executable_files_in_extensions) = @_;
92 my $is_executable = 0;
94 for ( my $i = 0; $i <= $#{$manifestfile}; $i++ )
96 my $line = ${$manifestfile}[$i];
98 if ( $line =~ /\"application\/vnd\
.sun\
.star\
.executable
\"/ ) { $is_executable = 1; }
100 if (( $line =~ /manifest\:full\-path=\"(.*?)\"/ ) && ( $is_executable ))
102 my $filename = $unzipdir . $installer::globals
::separator
. $1;
103 # making only slashes for comparison reasons
104 $filename =~ s/\\/\//g
;
105 $executable_files_in_extensions->{$filename} = 1;
108 if ( $line =~ /\/\
>/ ) { $is_executable = 0; }
112 #################################################################
113 # Reading the "manifest.xml" in extensions and determine, if
114 # there are executable files
115 #################################################################
117 sub collect_all_executable_files_in_extensions
119 my ($unzipdir, $executable_files_in_extensions) = @_;
121 $unzipdir =~ s/\Q$installer::globals::separator\E\s*$//;
123 my $manifestfilename = $unzipdir . $installer::globals
::separator
. "META-INF" . $installer::globals
::separator
. "manifest.xml";
125 if ( -f
$manifestfilename )
127 my $manifestfile = installer
::files
::read_file
($manifestfilename);
128 get_all_executables_from_manifest
($unzipdir, $manifestfile, $executable_files_in_extensions);
132 #################################################################
133 # Analyzing files with flag ARCHIVE
134 #################################################################
136 sub resolving_archive_flag
138 my ($filesarrayref, $additionalpathsref, $languagestringref, $loggingdir) = @_;
140 my @newallfilesarray = ();
142 my ($systemcall, $returnvalue, $infoline);
144 my $platformunzipdirbase = installer
::systemactions
::create_directories
("zip", $languagestringref);
145 push(@installer::globals
::removedirs
, $platformunzipdirbase);
147 installer
::logger
::include_header_into_logfile
("Files with flag ARCHIVE:");
149 my $repeat_unzip = 0;
152 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
154 if ( $repeat_unzip ) { $i--; } # decreasing the counter
156 my $onefile = ${$filesarrayref}[$i];
159 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
161 if ( $styles =~ /\bARCHIVE\b/ ) # copying, unzipping and changing the file list
163 my $sourcepath = $onefile->{'sourcepath'};
165 my $use_internal_rights = 0;
166 if ( $styles =~ /\bUSE_INTERNAL_RIGHTS\b/ ) { $use_internal_rights = 1; } # using the rights used inside the zip file
168 my $rename_to_language = 0;
169 if ( $styles =~ /\bRENAME_TO_LANGUAGE\b/ ) { $rename_to_language = 1; } # special handling for renamed files (scriptitems.pm)
171 my %executable_files_in_extensions = ();
172 my $set_executable_privileges = 0; # setting privileges for exectables is required for oxt files
173 if ( $onefile->{'Name'} =~ /\.oxt\s*$/ ) { $set_executable_privileges = 1; }
175 # mechanism to select files from an archive files
176 my $select_files = 0;
177 my $selectlistfiles = "";
179 if ( $onefile->{'Selectfiles'} )
182 $selectlistfiles = get_patch_file_list
( $onefile->{'Selectfiles'} );
183 $infoline = "Selected file list defined at file: $onefile->{'Name'} :\n";
184 push( @installer::globals
::logfileinfo
, $infoline);
185 for ( my $k = 0; $k <= $#{$selectlistfiles}; $k++ )
187 $infoline = "\"${$selectlistfiles}[$k]\"\n";
188 push( @installer::globals
::logfileinfo
, $infoline);
192 if ( $onefile->{'Selectfiles'} ) { $onefile->{'Selectfiles'} = ""; } # Selected files list no longer required
194 # creating directories
196 my $onelanguage = $onefile->{'specificlanguage'};
198 # files without language into directory "00"
200 if ($onelanguage eq "") { $onelanguage = "00"; }
204 $unzipdir = $platformunzipdirbase . $installer::globals
::separator
. $onelanguage . $installer::globals
::separator
;
206 installer
::systemactions
::create_directory
($unzipdir); # creating language specific subdirectories
208 my $onefilename = $onefile->{'Name'};
209 $onefilename =~ s/\./\_/g; # creating new directory name
210 $onefilename =~ s/\//\_
/g; # only because of /letter
/fontunxpsprint
.zip
, the only zip file with path
211 $unzipdir = $unzipdir . $onefilename . $installer::globals
::separator
;
213 if ( $installer::globals
::dounzip
) { installer
::systemactions
::create_directory
($unzipdir); } # creating subdirectories with the names of the zipfiles
215 my $zip = Archive
::Zip
->new();
216 if ( $zip->read($sourcepath) != AZ_OK
)
218 $infoline = "ERROR: Could not unzip $sourcepath\n";
219 push( @installer::globals
::logfileinfo
, $infoline);
223 my $contains_dll = 0;
226 foreach my $member ( $zip->memberNames() )
229 if ( $member =~ /.dll\s*$/i ) { $contains_dll = 1; push(@dllList, $member); }
230 if ( $member =~ m/\/$/ ) { push(@dirs, $member); }
233 if (! ( $counter > 0 )) # the zipfile is empty
235 $infoline = "ERROR: Could not unzip $sourcepath\n";
236 push( @installer::globals
::logfileinfo
, $infoline);
241 if ( $installer::globals
::dounzip
) # really unpacking the files
243 if ( $zip->extractTree("", $unzipdir) != AZ_OK
) { die "Could not unzip: $!"; }
245 if (( $^O
=~ /cygwin/i ) && ( $contains_dll ))
249 my $changed = chmod(0775, @dllList);
250 $infoline = "Changed mode of $changed files (of ".scalar(@dllList).")\n";
251 push( @installer::globals
::logfileinfo
, $infoline);
254 if ($changed != scalar(@dllList))
256 $infoline = "ERROR: Could not chmod all files!\n";
257 push( @installer::globals
::logfileinfo
, $infoline);
261 if ( ! $installer::globals
::iswindowsbuild
&& scalar(@dirs) > 0 )
265 # Setting unix rights to "775" for all created directories inside the package
266 my $changed = chmod(0775, @dirs);
267 $infoline = "Changed mode of : $changed; should be: ".scalar(@dirs)."\n";
270 push( @installer::globals
::logfileinfo
, $infoline);
272 if ($changed != scalar(@dirs))
274 $infoline = "ERROR: Could not chmod all files!\n";
275 push( @installer::globals
::logfileinfo
, $infoline);
279 # Selecting names of executable files in extensions
280 if ( $set_executable_privileges )
282 collect_all_executable_files_in_extensions
($unzipdir, \
%executable_files_in_extensions);
288 foreach my $zipname ( $zip->memberNames() )
290 # Format from Archive:::Zip :
292 # dir1/so7drawing.desktop
294 # some directories and files (from the help) start with "./simpress.idx"
296 $zipname =~ s/^\s*\.\///;
298 if ($installer::globals
::iswin
and $^O
=~ /MSWin/i) { $zipname =~ s/\//\\/g
; }
300 if ( $zipname =~ /\Q$installer::globals::separator\E\s*$/ ) # slash or backslash at the end characterizes a directory
302 $zipname = $zipname . "\n";
303 push(@
{$additionalpathsref}, $zipname);
311 # This is not needed, because the list of all directories for the
312 # epm list file is generated from the destination directories of the
313 # files included in the product!
318 %newfile = %{$onefile};
319 $newfile{'Name'} = $zipname;
320 my $destination = $onefile->{'destination'};
321 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$destination);
322 $newfile{'destination'} = $destination . $zipname;
323 $newfile{'sourcepath'} = $unzipdir . $zipname;
324 $newfile{'zipfilename'} = $onefile->{'Name'};
325 $newfile{'zipfilesource'} = $onefile->{'sourcepath'};
326 $newfile{'zipfiledestination'} = $onefile->{'destination'};
328 if (( $use_internal_rights ) && ( ! $installer::globals
::iswin
))
330 $newfile{'UnixRights'} = sprintf("%o", ($zip->memberNamed($zipname)->unixFileAttributes() & 07777));
331 $infoline = "Setting unix rights for \"$newfile{'sourcepath'}\" to \"$newfile{'UnixRights'}\"\n";
332 push( @installer::globals
::logfileinfo
, $infoline);
335 if ( $set_executable_privileges )
337 # All paths to executables are saved in the hash %executable_files_in_extensions
338 my $compare_path = $newfile{'sourcepath'};
339 $compare_path =~ s/\\/\//g
; # contains only slashes for comparison reasons
340 if ( exists($executable_files_in_extensions{$compare_path}) )
342 $newfile{'UnixRights'} = "775";
343 $infoline = "Executable in Extension: Setting unix rights for \"$newfile{'sourcepath'}\" to \"$newfile{'UnixRights'}\"\n";
344 push( @installer::globals
::logfileinfo
, $infoline);
350 if ( ! grep {$_ eq $zipname} @
{$selectlistfiles} )
352 $infoline = "Removing from ARCHIVE file $onefilename: $zipname\n";
353 push( @installer::globals
::logfileinfo
, $infoline);
354 next; # ignoring files, that are not included in $selectlistfiles
358 $infoline = "Keeping from ARCHIVE file $onefilename: $zipname\n";
359 push( @installer::globals
::logfileinfo
, $infoline);
360 push( @keptfiles, $zipname); # collecting all kept files
364 if ( $rename_to_language )
366 my $newzipname = put_language_into_name
($zipname, $onelanguage);
367 my $oldfilename = $unzipdir . $zipname;
368 my $newfilename = $unzipdir . $newzipname;
370 installer
::systemactions
::copy_one_file
($oldfilename, $newfilename);
372 $newfile{'Name'} = $newzipname;
373 $newfile{'destination'} = $destination . $newzipname;
374 $newfile{'sourcepath'} = $unzipdir . $newzipname;
376 $infoline = "RENAME_TO_LANGUAGE: Using $newzipname instead of $zipname!\n";
377 push( @installer::globals
::logfileinfo
, $infoline);
380 my $sourcefiletest = $unzipdir . $zipname;
381 if ( ! -f
$sourcefiletest )
383 $infoline = "ATTENTION: Unzip failed for $sourcefiletest!\n";
384 push( @installer::globals
::logfileinfo
, $infoline);
388 # only adding the new line into the files array, if not in repeat modus
390 if ( ! $repeat_unzip ) { push(@newallfilesarray, \
%newfile); }
394 # Comparing the content of @keptfiles and $selectlistfiles
395 # Do all files from the list of selected files are stored in @keptfiles ?
396 # @keptfiles contains only files included in $selectlistfiles. But are all
397 # files from $selectlistfiles included in @keptfiles?
401 my $number = $#{$selectlistfiles} + 1;
402 $infoline = "SELECTLIST: Number of files in file selection list: $number\n";
403 push( @installer::globals
::logfileinfo
, $infoline);
404 $number = $#keptfiles + 1;
405 $infoline = "SELECTLIST: Number of kept files: $number\n";
406 push( @installer::globals
::logfileinfo
, $infoline);
408 for ( my $k = 0; $k <= $#keptfiles; $k++ )
410 $infoline = "KEPT FILES: $keptfiles[$k]\n";
411 push( @installer::globals
::logfileinfo
, $infoline);
414 my @warningfiles = ();
416 for ( my $k = 0; $k <= $#{$selectlistfiles}; $k++ )
418 if ( ! grep {$_ eq ${$selectlistfiles}[$k]} @keptfiles )
420 push(@warningfiles, ${$selectlistfiles}[$k]);
424 for ( my $k = 0; $k <= $#warningfiles; $k++ )
426 $infoline = "WARNING: $warningfiles[$k] not included in install set (does not exist in zip file)!\n";
427 push( @installer::globals
::logfileinfo
, $infoline);
434 installer
::logger
::print_warning
( "Repeating to unpack $sourcepath! \n" );
435 $infoline = "ATTENTION: Repeating to unpack $sourcepath !\n";
436 push( @installer::globals
::logfileinfo
, $infoline);
440 if ( $maxcounter == 5 ) # exiting the program
442 die "Failed to unzip $sourcepath !";
447 $infoline = "Info: $sourcepath unpacked without problems !\n";
448 push( @installer::globals
::logfileinfo
, $infoline);
454 else # nothing to do here, no zipped file (no ARCHIVE flag)
456 push(@newallfilesarray, $onefile);
461 push( @installer::globals
::logfileinfo
, $infoline);
463 return \
@newallfilesarray;