1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: systemactions.pm,v $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer
::systemactions
;
36 use installer
::converter
;
37 use installer
::exiter
;
38 use installer
::globals
;
39 use installer
::pathanalyzer
;
40 use installer
::remover
;
42 ######################################################
43 # Creating a new direcotory
44 ######################################################
55 $returnvalue = mkdir($directory, 0775);
59 $infoline = "\nCreated directory: $directory\n";
60 push(@installer::globals
::logfileinfo
, $infoline);
62 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
66 # New solution in parallel packing: It is possible, that the directory now exists, although it
67 # was not created in this process. There is only an important error, if the directory does not
70 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n";
71 push(@installer::globals
::logfileinfo
, $infoline);
75 # Problem with parallel packaging? -> Try a little harder, before exiting.
76 # Did someone else remove the parent directory in the meantime?
77 my $parentdir = $directory;
78 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$parentdir);
81 $returnvalue = mkdir($parentdir, 0775);
85 $infoline = "\nAttention: Successfully created parent directory (should already be created before): $parentdir\n";
86 push(@installer::globals
::logfileinfo
, $infoline);
88 my $localcall = "chmod 775 $parentdir \>\/dev\/null 2\>\&1";
93 $infoline = "\Error: \"$directory\" could not be created. Even the parent directory \"$parentdir\" does not exist and could not be created.\n";
94 push(@installer::globals
::logfileinfo
, $infoline);
97 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n";
98 push(@installer::globals
::logfileinfo
, $infoline);
102 # Now it is time to exit, even the parent could not be created.
103 installer
::exiter
::exit_program
("ERROR: Could not create parent directory \"$parentdir\"", "create_directory");
108 # At this point we have to assume, that the parent directory exist.
109 # Trying once more to create the desired directory
111 $returnvalue = mkdir($directory, 0775);
115 $infoline = "\nAttention: Created directory \"$directory\" in the second try.\n";
116 push(@installer::globals
::logfileinfo
, $infoline);
118 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
125 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n";
126 push(@installer::globals
::logfileinfo
, $infoline);
130 # It is time to exit, even the second try failed.
131 installer
::exiter
::exit_program
("ERROR: Failed to create the directory: $directory", "create_directory");
137 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
138 push(@installer::globals
::logfileinfo
, $infoline);
144 $infoline = "\nAlready existing directory, did not create: $directory\n";
145 push(@installer::globals
::logfileinfo
, $infoline);
149 ######################################################
150 # Creating a new direcotory with defined privileges
151 ######################################################
153 sub create_directory_with_privileges
155 my ($directory, $privileges) = @_;
160 if (!(-d
$directory))
162 my $localprivileges = oct("0".$privileges); # changes "777" to 0777
163 $returnvalue = mkdir($directory, $localprivileges);
167 $infoline = "\nCreated directory: $directory\n";
168 push(@installer::globals
::logfileinfo
, $infoline);
170 my $localcall = "chmod $privileges $directory \>\/dev\/null 2\>\&1";
175 # New solution in parallel packing: It is possible, that the directory now exists, although it
176 # was not created in this process. There is only an important error, if the directory does not
179 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n";
180 push(@installer::globals
::logfileinfo
, $infoline);
182 if (!(-d
$directory))
184 # Problem with parallel packaging? -> Try a little harder, before exiting.
185 # Did someone else remove the parent directory in the meantime?
186 my $parentdir = $directory;
187 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$parentdir);
188 if (!(-d
$parentdir))
190 $returnvalue = mkdir($directory, $localprivileges);
194 $infoline = "\nAttention: Successfully created parent directory (should already be created before): $parentdir\n";
195 push(@installer::globals
::logfileinfo
, $infoline);
197 my $localcall = "chmod $privileges $parentdir \>\/dev\/null 2\>\&1";
202 $infoline = "\Error: \"$directory\" could not be created. Even the parent directory \"$parentdir\" does not exist and could not be created.\n";
203 push(@installer::globals
::logfileinfo
, $infoline);
206 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n";
207 push(@installer::globals
::logfileinfo
, $infoline);
211 # Now it is time to exit, even the parent could not be created.
212 installer
::exiter
::exit_program
("ERROR: Could not create parent directory \"$parentdir\"", "create_directory_with_privileges");
217 # At this point we have to assume, that the parent directory exist.
218 # Trying once more to create the desired directory
220 $returnvalue = mkdir($directory, $localprivileges);
224 $infoline = "\nAttention: Created directory \"$directory\" in the second try.\n";
225 push(@installer::globals
::logfileinfo
, $infoline);
227 my $localcall = "chmod $privileges $directory \>\/dev\/null 2\>\&1";
234 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n";
235 push(@installer::globals
::logfileinfo
, $infoline);
239 # It is time to exit, even the second try failed.
240 installer
::exiter
::exit_program
("ERROR: Failed to create the directory: $directory", "create_directory_with_privileges");
246 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
247 push(@installer::globals
::logfileinfo
, $infoline);
253 $infoline = "\nAlready existing directory, did not create: $directory\n";
254 push(@installer::globals
::logfileinfo
, $infoline);
256 my $localcall = "chmod $privileges $directory \>\/dev\/null 2\>\&1";
261 ######################################################
262 # Removing a new direcotory
263 ######################################################
265 sub remove_empty_directory
267 my ($directory) = @_;
273 my $systemcall = "rmdir $directory";
275 $returnvalue = system($systemcall);
277 my $infoline = "Systemcall: $systemcall\n";
278 push( @installer::globals
::logfileinfo
, $infoline);
282 $infoline = "ERROR: Could not remove \"$directory\"!\n";
283 push( @installer::globals
::logfileinfo
, $infoline);
287 $infoline = "Success: Removed \"$directory\"!\n";
288 push( @installer::globals
::logfileinfo
, $infoline);
293 #######################################################################
294 # Creating the directories, in which files are generated or unzipped
295 #######################################################################
297 sub create_directories
299 my ($newdirectory, $languagesref) =@_;
301 $installer::globals
::unpackpath
=~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
305 if (( $newdirectory eq "uno" ) || ( $newdirectory eq "zip" ) || ( $newdirectory eq "cab" ) || ( $newdirectory =~ /rdb\s*$/i )) # special handling for zip files, cab files and services file because of performance reasons
307 if ( $installer::globals
::temppathdefined
) { $path = $installer::globals
::temppath
; }
308 else { $path = $installer::globals
::unpackpath
; }
309 $path =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
310 $path = $path . $installer::globals
::separator
;
312 elsif ( ( $newdirectory eq "jds" ) )
314 if ( $installer::globals
::jdstemppathdefined
) { $path = $installer::globals
::jdstemppath
; }
315 else { $path = $installer::globals
::unpackpath
; }
316 $path =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
317 $path = $path . $installer::globals
::separator
;
318 installer
::systemactions
::create_directory
($path);
322 $path = $installer::globals
::unpackpath
. $installer::globals
::separator
;
325 $infoline = "create_directories: Using $path for $newdirectory !\n";
326 push( @installer::globals
::logfileinfo
, $infoline);
328 if ($newdirectory eq "unzip" ) # special handling for common directory
330 $path = $path . ".." . $installer::globals
::separator
. "common" . $installer::globals
::productextension
. $installer::globals
::separator
;
331 create_directory
($path);
333 $path = $path . $newdirectory . $installer::globals
::separator
;
334 create_directory
($path);
338 my $localproductname = $installer::globals
::product
;
339 my $localproductsubdir = "";
341 if ( $installer::globals
::product
=~ /^\s*(.+?)\_\_(.+?)\s*$/ )
343 $localproductname = $1;
344 $localproductsubdir = $2;
347 if ( $installer::globals
::languagepack
) { $path = $path . $localproductname . "_languagepack" . $installer::globals
::separator
; }
348 elsif ( $installer::globals
::patch
) { $path = $path . $localproductname . "_patch" . $installer::globals
::separator
; }
349 else { $path = $path . $localproductname . $installer::globals
::separator
; }
351 create_directory
($path);
353 if ( $localproductsubdir )
355 $path = $path . $localproductsubdir . $installer::globals
::separator
;
356 create_directory
($path);
359 $path = $path . $installer::globals
::installertypedir
. $installer::globals
::separator
;
360 create_directory
($path);
362 $path = $path . $newdirectory . $installer::globals
::separator
;
363 create_directory
($path);
365 my $locallanguagesref = "";
367 if ( $$languagesref ) { $locallanguagesref = $$languagesref; }
369 if (!($locallanguagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
371 my $languagestring = $$languagesref;
373 if (length($languagestring) > $installer::globals
::max_lang_length
)
375 chomp(my $shorter = `echo $languagestring | md5sum | sed -e "s/ .*//g"`);
376 $languagestring = $shorter;
379 $path = $path . $languagestring . $installer::globals
::separator
;
380 create_directory
($path);
384 installer
::remover
::remove_ending_pathseparator
(\
$path);
386 $path = installer
::converter
::make_path_conform
($path);
391 ########################
393 ########################
397 my ($source, $dest) = @_;
399 my ($returnvalue, $infoline);
401 my $copyreturn = copy
($source, $dest);
405 $infoline = "Copy: $source to $dest\n";
410 $infoline = "ERROR: Could not copy $source to $dest\n";
414 push(@installer::globals
::logfileinfo
, $infoline);
416 if ( !$returnvalue ) {
420 # taking care of file attributes
421 if ($installer::globals
::iswin
&& -f
$dest) {
422 my $mode = -x
$source ?
0775 : 0664;
423 my $mode_str = sprintf("%o", $mode);
424 my $chmodreturn = chmod($mode, $dest);
427 $infoline = "chmod $mode_str, $dest\n";
432 $infoline = "WARNING: Could not chmod $dest: $!\n";
436 push(@installer::globals
::logfileinfo
, $infoline);
442 ##########################
443 # Hard linking one file
444 ##########################
446 sub hardlink_one_file
448 my ($source, $dest) = @_;
450 my ($returnvalue, $infoline);
452 my $copyreturn = link($source, $dest);
456 $infoline = "Link: $source to $dest\n";
461 $infoline = "ERROR: Could not link $source to $dest\n";
465 push(@installer::globals
::logfileinfo
, $infoline);
470 ##########################
471 # Soft linking one file
472 ##########################
474 sub softlink_one_file
476 my ($source, $dest) = @_;
478 my ($returnvalue, $infoline);
480 my $linkreturn = symlink($source, $dest);
484 $infoline = "Symlink: $source to $dest\n";
489 $infoline = "ERROR: Could not symlink $source to $dest\n";
493 push(@installer::globals
::logfileinfo
, $infoline);
498 ########################
500 ########################
504 my ($source, $dest) = @_;
506 my ($returnvalue, $infoline);
508 my $renamereturn = rename($source, $dest);
512 $infoline = "Rename: $source to $dest\n";
517 $infoline = "ERROR: Could not rename $source to $dest\n";
521 push(@installer::globals
::logfileinfo
, $infoline);
526 ##########################################
527 # Copying all files from one directory
528 # to another directory
529 ##########################################
533 my ($sourcedir, $destdir) = @_;
535 my @sourcefiles = ();
537 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
538 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
541 push(@installer::globals
::logfileinfo
, $infoline);
542 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
543 push(@installer::globals
::logfileinfo
, $infoline);
545 opendir(DIR
, $sourcedir);
546 @sourcefiles = readdir(DIR
);
551 foreach $onefile (@sourcefiles)
553 if ((!($onefile eq ".")) && (!($onefile eq "..")))
555 my $sourcefile = $sourcedir . $installer::globals
::separator
. $onefile;
556 my $destfile = $destdir . $installer::globals
::separator
. $onefile;
557 if ( -f
$sourcefile ) # only files, no directories
559 copy_one_file
($sourcefile, $destfile);
565 ##########################################
566 # Copying all files from one directory
567 # to another directory
568 ##########################################
574 my $directory_is_empty = 1;
575 my @sourcefiles = ();
578 @sourcefiles = readdir(DIR
);
582 my @realcontent = ();
584 foreach $onefile (@sourcefiles)
586 if ((!($onefile eq ".")) && (!($onefile eq "..")))
588 push(@realcontent, $onefile);
592 if ( $#realcontent > -1 ) { $directory_is_empty = 0; }
594 return $directory_is_empty;
597 #####################################################################
598 # Creating hard links to a complete directory with sub directories.
599 #####################################################################
601 sub hardlink_complete_directory
603 my ($sourcedir, $destdir) = @_;
605 my @sourcefiles = ();
607 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
608 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
610 if ( ! -d
$destdir ) { create_directory
($destdir); }
613 push(@installer::globals
::logfileinfo
, $infoline);
614 $infoline = "Creating hard links for all files from directory $sourcedir to directory $destdir\n";
615 push(@installer::globals
::logfileinfo
, $infoline);
617 opendir(DIR
, $sourcedir);
618 @sourcefiles = readdir(DIR
);
623 foreach $onefile (@sourcefiles)
625 if ((!($onefile eq ".")) && (!($onefile eq "..")))
627 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
628 my $dest = $destdir . $installer::globals
::separator
. $onefile;
629 if ( -f
$source ) # only files, no directories
631 hardlink_one_file
($source, $dest);
633 if ( -d
$source ) # recursive
635 hardlink_complete_directory
($source, $dest);
641 #####################################################################
642 # Creating hard links to a complete directory with sub directories.
643 #####################################################################
645 sub softlink_complete_directory
647 my ($sourcedir, $destdir, $depth) = @_;
649 my @sourcefiles = ();
651 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
652 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
654 if ( ! -d
$destdir ) { create_directory
($destdir); }
657 push(@installer::globals
::logfileinfo
, $infoline);
658 $infoline = "Creating soft links for all files from directory $sourcedir to directory $destdir\n";
659 push(@installer::globals
::logfileinfo
, $infoline);
661 opendir(DIR
, $sourcedir);
662 @sourcefiles = readdir(DIR
);
667 foreach $onefile (@sourcefiles)
669 if ((!($onefile eq ".")) && (!($onefile eq "..")))
671 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
672 my $dest = $destdir . $installer::globals
::separator
. $onefile;
673 if ( -f
$source ) # only files, no directories
675 my $localsource = $source;
676 if ( $depth > 0 ) { for ( my $i = 1; $i <= $depth; $i++ ) { $localsource = "../" . $localsource; } }
677 softlink_one_file
($localsource, $dest);
679 if ( -d
$source ) # recursive
681 my $newdepth = $depth + 1;
682 softlink_complete_directory
($source, $dest, $newdepth);
688 #####################################################
689 # Copying a complete directory with sub directories.
690 #####################################################
692 sub copy_complete_directory
694 my ($sourcedir, $destdir) = @_;
696 my @sourcefiles = ();
698 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
699 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
701 if ( ! -d
$destdir ) { create_directory
($destdir); }
704 push(@installer::globals
::logfileinfo
, $infoline);
705 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
706 push(@installer::globals
::logfileinfo
, $infoline);
708 opendir(DIR
, $sourcedir);
709 @sourcefiles = readdir(DIR
);
714 foreach $onefile (@sourcefiles)
716 if ((!($onefile eq ".")) && (!($onefile eq "..")))
718 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
719 my $dest = $destdir . $installer::globals
::separator
. $onefile;
720 if ( -f
$source ) # only files, no directories
722 copy_one_file
($source, $dest);
724 if ( -d
$source ) # recursive
726 if ((!( $source =~ /packages\/SUNW
/ )) && (!( $source =~ /packages\
/OOO/ ))) # do not copy complete Solaris packages!
728 copy_complete_directory
($source, $dest);
735 #####################################################################################
736 # Copying a complete directory with sub directories, but not the CVS directories.
737 #####################################################################################
739 sub copy_complete_directory_without_cvs
741 my ($sourcedir, $destdir) = @_;
743 my @sourcefiles = ();
745 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
746 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
748 if ( ! -d
$destdir ) { create_directory
($destdir); }
751 push(@installer::globals
::logfileinfo
, $infoline);
752 $infoline = "Copying files from directory $sourcedir to directory $destdir (without CVS)\n";
753 push(@installer::globals
::logfileinfo
, $infoline);
755 opendir(DIR
, $sourcedir);
756 @sourcefiles = readdir(DIR
);
761 foreach $onefile (@sourcefiles)
763 if ((!($onefile eq ".")) && (!($onefile eq "..")) && (!($onefile eq "CVS")))
765 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
766 my $dest = $destdir . $installer::globals
::separator
. $onefile;
767 if ( -f
$source ) # only files, no directories
769 copy_one_file
($source, $dest);
771 if ( -d
$source ) # recursive
773 copy_complete_directory_without_cvs
($source, $dest);
779 #####################################################
780 # Copying all files with a specified file extension
781 # from one directory to another directory.
782 #####################################################
784 sub copy_directory_with_fileextension
786 my ($sourcedir, $destdir, $extension) = @_;
788 my @sourcefiles = ();
790 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
791 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
794 push(@installer::globals
::logfileinfo
, $infoline);
795 $infoline = "Copying files with extension $extension from directory $sourcedir to directory $destdir\n";
796 push(@installer::globals
::logfileinfo
, $infoline);
798 opendir(DIR
, $sourcedir);
799 @sourcefiles = readdir(DIR
);
804 foreach $onefile (@sourcefiles)
806 if ((!($onefile eq ".")) && (!($onefile eq "..")))
808 if ( $onefile =~ /\.$extension\s*$/ ) # only copying specified files
810 my $sourcefile = $sourcedir . $installer::globals
::separator
. $onefile;
811 my $destfile = $destdir . $installer::globals
::separator
. $onefile;
812 if ( -f
$sourcefile ) # only files, no directories
814 copy_one_file
($sourcefile, $destfile);
821 #########################################################
822 # Copying all files without a specified file extension
823 # from one directory to another directory.
824 #########################################################
826 sub copy_directory_except_fileextension
828 my ($sourcedir, $destdir, $extension) = @_;
830 my @sourcefiles = ();
832 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
833 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
836 push(@installer::globals
::logfileinfo
, $infoline);
837 $infoline = "Copying files without extension $extension from directory $sourcedir to directory $destdir\n";
838 push(@installer::globals
::logfileinfo
, $infoline);
840 opendir(DIR
, $sourcedir);
841 @sourcefiles = readdir(DIR
);
846 foreach $onefile (@sourcefiles)
848 if ((!($onefile eq ".")) && (!($onefile eq "..")))
850 if ( ! ( $onefile =~ /\.$extension\s*$/ )) # only copying not having the specified extension
852 my $sourcefile = $sourcedir . $installer::globals
::separator
. $onefile;
853 my $destfile = $destdir . $installer::globals
::separator
. $onefile;
854 if ( -f
$sourcefile ) # only files, no directories
856 copy_one_file
($sourcefile, $destfile);
863 ########################################################
864 # Renaming all files with a specified file extension
865 # in a specified directory.
866 # Example: "Feature.idt.01" -> "Feature.idt"
867 ########################################################
869 sub rename_files_with_fileextension
871 my ($dir, $extension) = @_;
873 my @sourcefiles = ();
875 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
878 push(@installer::globals
::logfileinfo
, $infoline);
879 $infoline = "Renaming files with extension \"$extension\" in the directory $dir\n";
880 push(@installer::globals
::logfileinfo
, $infoline);
883 @sourcefiles = readdir(DIR
);
888 foreach $onefile (@sourcefiles)
890 if ((!($onefile eq ".")) && (!($onefile eq "..")))
892 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ ) # only renaming specified files
895 my $sourcefile = $dir . $installer::globals
::separator
. $onefile;
896 $destfile = $dir . $installer::globals
::separator
. $destfile;
897 if ( -f
$sourcefile ) # only files, no directories
899 rename_one_file
($sourcefile, $destfile);
906 ########################################################
907 # Finding all files with a specified file extension
908 # in a specified directory.
909 ########################################################
911 sub find_file_with_file_extension
913 my ($extension, $dir) = @_;
917 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
920 push(@installer::globals
::logfileinfo
, $infoline);
921 $infoline = "Searching files with extension \"$extension\" in the directory $dir\n";
922 push(@installer::globals
::logfileinfo
, $infoline);
925 @sourcefiles = readdir(DIR
);
930 foreach $onefile (@sourcefiles)
932 if ((!($onefile eq ".")) && (!($onefile eq "..")))
934 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ )
936 push(@allfiles, $onefile)
944 ##############################################################
945 # Creating a unique directory, for example "01_inprogress_7"
946 # in the install directory.
947 ##############################################################
949 sub make_numbered_dir
951 my ($newstring, $olddir) = @_;
953 my $basedir = $olddir;
954 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$basedir);
956 my $alldirs = get_all_directories
($basedir);
958 # searching for the highest number extension
962 for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
964 if ( ${$alldirs}[$i] =~ /\_(\d+)\s*$/ )
967 if ( $number > $maxnumber ) { $maxnumber = $number; }
971 my $newnumber = $maxnumber + 1;
973 my $newdir = $olddir . "_" . $newstring . "_" . $newnumber;
977 if ( move
($olddir, $newdir) )
979 $infoline = "\nMoved directory from $olddir to $newdir\n";
980 push(@installer::globals
::logfileinfo
, $infoline);
981 $returndir = $newdir;
985 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"make_numbered_dir\"\n";
986 push(@installer::globals
::logfileinfo
, $infoline);
987 $returndir = $olddir;
993 ##############################################################
994 # Determining the highest number in the install directory.
995 ##############################################################
997 sub determine_maximum_number
999 my ($dir, $languagestringref) = @_;
1002 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$basedir);
1004 my $alldirs = get_all_directories
($basedir);
1008 # In control.pm the installation directory is determined as:
1009 # $installer::globals::build . "_" . $installer::globals::lastminor . "_" .
1010 # "native_inprogress-number_" . $$languagesref . "\." . $installer::globals::buildid;
1012 # searching for the highest number extension after the first "-", which belongs to
1013 # $installer::globals::build, $installer::globals::lastminor and $installer::globals::buildid
1014 # In this step not looking for the language!
1016 my @correctbuildiddirs = ();
1018 for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
1020 my $onedir = ${$alldirs}[$i];
1021 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$onedir);
1023 if ( $onedir =~ /^\s*\Q$installer::globals::build\E\_\Q$installer::globals::lastminor\E\_(.*?)\-(\d+)\_(.*?)\.\Q$installer::globals::buildid\E\s*$/ )
1026 if ( $number > $maxnumber ) { $maxnumber = $number; }
1027 push(@correctbuildiddirs, $onedir);
1031 # From all directories with correct $installer::globals::build, $installer::globals::lastminor
1032 # and $installer::globals::buildid, those directories, which already have the maximum number
1033 # have to be selected
1035 my @maximumnumberdirs = ();
1037 for ( my $i = 0; $i <= $#correctbuildiddirs; $i++ )
1039 my $onedir = $correctbuildiddirs[$i];
1041 if ( $onedir =~ /^\s*(.*?)\-(\d+)\_(.*?)\.(.*?)\s*$/ )
1045 if ( $number == $maxnumber )
1047 push(@maximumnumberdirs, $onedir);
1052 # @maximumnumberdirs contains only those directories with correct $installer::globals::build,
1053 # $installer::globals::lastminor and $installer::globals::buildid, which already have the maximum number.
1054 # If the current language is part of this directory, the number has to be increased.
1056 my $increase_counter = 0;
1058 for ( my $i = 0; $i <= $#maximumnumberdirs; $i++ )
1060 my $onedir = $maximumnumberdirs[$i];
1062 if ( $onedir =~ /^\s*(.*?)\-(\d+)\_(.*?)\.(.*?)\s*$/ )
1065 my $languagestring = $3;
1067 if ( $languagestring eq $$languagestringref )
1069 $increase_counter = 1;
1074 if ( $increase_counter )
1076 $maxnumber = $maxnumber + 1;
1082 #####################################################################################
1083 # Renaming a directory by exchanging a string, for example from "01_inprogress_7"
1084 # to "01_witherror_7".
1085 #####################################################################################
1087 sub rename_string_in_directory
1089 my ($olddir, $oldstring, $newstring) = @_;
1091 my $newdir = $olddir;
1094 $newdir =~ s/$oldstring/$newstring/g;
1096 if (( -d
$newdir ) && ( $olddir ne $newdir )) { remove_complete_directory
($newdir, 1); }
1098 if ( move
($olddir, $newdir) )
1100 $infoline = "\nMoved directory from $olddir to $newdir\n";
1101 push(@installer::globals
::logfileinfo
, $infoline);
1105 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_string_in_directory\"\n";
1106 push(@installer::globals
::logfileinfo
, $infoline);
1112 ######################################################
1113 # Returning the complete directory name,
1114 # input is the first part of the directory name.
1115 ######################################################
1117 sub get_directoryname
1119 my ($searchdir, $startstring) = @_;
1125 opendir(DIR
, $searchdir);
1127 foreach $direntry (readdir (DIR
))
1129 next if $direntry eq ".";
1130 next if $direntry eq "..";
1132 if (( -d
$direntry ) && ( $direntry =~ /^\s*\Q$startstring\E/ ))
1134 $dirname = $direntry;
1142 if ( ! $founddir ) { installer
::exiter
::exit_program
("ERROR: Did not find directory beginning with $startstring in directory $searchdir", "get_directoryname"); }
1148 ###################################
1149 # Renaming a directory
1150 ###################################
1152 sub rename_directory
1154 my ($olddir, $newdir) = @_;
1158 if ( move
($olddir, $newdir) )
1160 $infoline = "\nMoved directory from $olddir to $newdir\n";
1161 push(@installer::globals
::logfileinfo
, $infoline);
1165 installer
::exiter
::exit_program
("ERROR: Could not move directory from $olddir to $newdir", "rename_directory");
1166 # $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_directory\"\n";
1167 # push(@installer::globals::logfileinfo, $infoline);
1173 ##############################################################
1174 # Creating a directory next to an existing directory
1175 ##############################################################
1177 sub create_directory_next_to_directory
1179 my ($topdir, $dirname) = @_;
1181 my $basedir = $topdir;
1182 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$basedir);
1184 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1186 my $newdir = $basedir . $installer::globals
::separator
. $dirname;
1188 create_directory
($newdir);
1193 ##############################################################
1194 # Collecting all directories inside a directory
1195 ##############################################################
1197 sub get_all_directories
1204 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1206 opendir(DIR
, $basedir);
1208 foreach $direntry (readdir (DIR
))
1210 next if $direntry eq ".";
1211 next if $direntry eq "..";
1213 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1215 if ( -d
$completeentry ) { push(@alldirs, $completeentry); }
1223 ##############################################################
1224 # Collecting all directories inside a directory
1225 # Returning without path
1226 ##############################################################
1228 sub get_all_directories_without_path
1235 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1237 opendir(DIR
, $basedir);
1239 foreach $direntry (readdir (DIR
))
1241 next if $direntry eq ".";
1242 next if $direntry eq "..";
1244 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1246 if ( -d
$completeentry ) { push(@alldirs, $direntry); }
1254 ##############################################################
1255 # Collecting all files inside one directory
1256 ##############################################################
1258 sub get_all_files_from_one_directory
1265 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1267 opendir(DIR
, $basedir);
1269 foreach $direntry (readdir (DIR
))
1271 next if $direntry eq ".";
1272 next if $direntry eq "..";
1274 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1276 if ( -f
$completeentry ) { push(@allfiles, $completeentry); }
1284 ##############################################################
1285 # Collecting all files inside one directory
1286 ##############################################################
1288 sub get_all_files_from_one_directory_without_path
1295 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1297 opendir(DIR
, $basedir);
1299 foreach $direntry (readdir (DIR
))
1301 next if $direntry eq ".";
1302 next if $direntry eq "..";
1304 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1306 if ( -f
$completeentry ) { push(@allfiles, $direntry); }
1314 ##############################################################
1315 # Collecting all files and directories inside one directory
1316 ##############################################################
1322 my @allcontent = ();
1325 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1327 opendir(DIR
, $basedir);
1329 foreach $direntry (readdir (DIR
))
1331 next if $direntry eq ".";
1332 next if $direntry eq "..";
1334 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1336 if (( -f
$completeentry ) || ( -d
$completeentry )) { push(@allcontent, $completeentry); }
1341 return \
@allcontent;
1344 ##############################################################
1345 # Finding the new content in a directory
1346 ##############################################################
1348 sub find_new_content_in_directory
1350 my ( $basedir, $oldcontent ) = @_;
1352 my @newcontent = ();
1353 my @allcontent = ();
1357 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1359 opendir(DIR
, $basedir);
1361 foreach $direntry (readdir (DIR
))
1363 next if $direntry eq ".";
1364 next if $direntry eq "..";
1366 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1368 if (( -f
$completeentry ) || ( -d
$completeentry ))
1370 push(@allcontent, $completeentry);
1371 if (! installer
::existence
::exists_in_array
($completeentry, $oldcontent))
1373 push(@newcontent, $completeentry);
1380 return (\
@newcontent, \
@allcontent);
1383 ##############################################################
1384 # Trying to create a directory, no error if this fails
1385 ##############################################################
1387 sub try_to_create_directory
1389 my ($directory) = @_;
1391 my $returnvalue = 1;
1392 my $created_directory = 0;
1394 if (!(-d
$directory))
1396 $returnvalue = mkdir($directory, 0775);
1400 $created_directory = 1;
1401 $infoline = "\nCreated directory: $directory\n";
1402 push(@installer::globals
::logfileinfo
, $infoline);
1404 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
1409 $created_directory = 0;
1414 $created_directory = 1;
1417 return $created_directory;
1420 ##############################################################
1421 # Creating a complete directory structure
1422 ##############################################################
1424 sub create_directory_structure
1426 my ($directory) = @_;
1428 if ( ! try_to_create_directory
($directory) )
1430 my $parentdir = $directory;
1431 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$parentdir);
1433 my $infoline = "INFO: Did not create directory $directory\n";
1434 push(@installer::globals
::logfileinfo
, $infoline);
1435 $infoline = "Now trying to create parent directory $parentdir\n";
1436 push(@installer::globals
::logfileinfo
, $infoline);
1438 create_directory_structure
($parentdir); # recursive
1441 create_directory
($directory); # now it has to succeed
1444 ######################################################
1445 # Removing a complete directory with subdirectories
1446 ######################################################
1448 sub remove_complete_directory
1450 my ($directory, $start) = @_;
1455 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1457 if ( -d
$directory )
1462 push(@installer::globals
::logfileinfo
, $infoline);
1463 $infoline = "Removing directory $directory\n";
1464 push(@installer::globals
::logfileinfo
, $infoline);
1467 opendir(DIR
, $directory);
1468 @content = readdir(DIR
);
1473 foreach $oneitem (@content)
1475 if ((!($oneitem eq ".")) && (!($oneitem eq "..")))
1477 my $item = $directory . $installer::globals
::separator
. $oneitem;
1479 if ( -f
$item || -l
$item ) # deleting files or links
1484 if ( -d
$item ) # recursive
1486 remove_complete_directory
($item, 0);
1491 # try to remove empty directory
1493 my $returnvalue = rmdir $directory;
1495 if ( ! $returnvalue )
1497 $infoline = "Warning: Problem with removing empty dir $directory\n";
1498 push(@installer::globals
::logfileinfo
, $infoline);
1501 # try a little bit harder (sometimes there is a performance problem)
1502 if ( -d
$directory )
1504 for ( my $j = 1; $j <= 3; $j++ )
1506 if ( -d
$directory )
1509 push(@installer::globals
::logfileinfo
, $infoline);
1510 $infoline = "Warning (Try $j): Problems with removing directory $directory\n";
1511 push(@installer::globals
::logfileinfo
, $infoline);
1513 $returnvalue = rmdir $directory;
1517 $infoline = "Successfully removed empty dir $directory\n";
1518 push(@installer::globals
::logfileinfo
, $infoline);
1520 $infoline = "Warning: rmdir $directory failed.\n";
1521 push(@installer::globals
::logfileinfo
, $infoline);
1529 ######################################################
1530 # Creating a unique directory with number extension
1531 ######################################################
1533 sub create_unique_directory
1535 my ($directory) = @_;
1537 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1538 $directory = $directory . "_INCREASINGNUMBER";
1542 my $localdirectory = "";
1546 $localdirectory = $directory;
1547 $localdirectory =~ s/INCREASINGNUMBER/$counter/;
1550 if ( ! -d
$localdirectory )
1552 create_directory
($localdirectory);
1556 while ( ! $created );
1558 return $localdirectory;
1561 ######################################################
1562 # Creating a unique directory with pid extension
1563 ######################################################
1565 sub create_pid_directory
1567 my ($directory) = @_;
1569 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1570 my $pid = $$; # process id
1571 my $time = time(); # time
1573 $directory = $directory . "_" . $pid . $time;
1575 if ( ! -d
$directory ) { create_directory
($directory); }
1576 else { installer
::exiter
::exit_program
("ERROR: Directory $directory already exists!", "create_pid_directory"); }
1581 ##############################################################
1582 # Reading all files from a directory and its subdirectories
1583 ##############################################################
1585 sub read_complete_directory
1587 my ($directory, $pathstring, $filecollector) = @_;
1590 opendir(DIR
, $directory);
1591 @content = readdir(DIR
);
1596 foreach $onefile (@content)
1598 if ((!($onefile eq ".")) && (!($onefile eq "..")))
1600 my $completefilename = $directory . $installer::globals
::separator
. $onefile;
1602 if ( $pathstring ne "" ) { $sep = $installer::globals
::separator
; }
1604 if ( ! -d
$completefilename ) # only files, no directories
1606 my $content = $pathstring . $sep . $onefile;
1607 push(@
{$filecollector}, $content);
1609 else # recursive for directories
1611 my $newpathstring = $pathstring . $sep . $onefile;
1612 read_complete_directory
($completefilename, $newpathstring, $filecollector);
1618 ##############################################################
1619 # Reading all files from a directory and its subdirectories
1621 ##############################################################
1623 sub read_full_directory
{
1624 my ( $currentdir, $pathstring, $collector ) = @_;
1629 unless (opendir(DH
, $currentdir))
1633 while (defined ($item = readdir(DH
)))
1635 next if($item eq "." or $item eq "..");
1636 $fullname = $currentdir . $installer::globals
::separator
. $item;
1638 if ( $pathstring ne "" ) { $sep = $installer::globals
::separator
; }
1642 my $newpathstring = $pathstring . $sep . $item;
1643 read_full_directory
($fullname, $newpathstring, $collector) if(-d
$fullname);
1647 my $content = $pathstring . $sep . $item;
1648 push(@
{$collector}, $content);