merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / modules / installer / systemactions.pm
blob0f0bede6a25bd6c290b961bd54dc24c14e1bff93
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: systemactions.pm,v $
11 # $Revision: 1.38 $
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;
34 use Cwd;
35 use File::Copy;
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 ######################################################
46 sub create_directory
48 my ($directory) = @_;
50 my $returnvalue = 1;
51 my $infoline = "";
53 if (!(-d $directory))
55 $returnvalue = mkdir($directory, 0775);
57 if ($returnvalue)
59 $infoline = "\nCreated directory: $directory\n";
60 push(@installer::globals::logfileinfo, $infoline);
62 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
64 else
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
68 # exist now.
70 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n";
71 push(@installer::globals::logfileinfo, $infoline);
73 if (!(-d $directory))
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);
79 if (!(-d $parentdir))
81 $returnvalue = mkdir($parentdir, 0775);
83 if ($returnvalue)
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";
89 system($localcall);
91 else
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);
95 if ( -d $parentdir )
97 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n";
98 push(@installer::globals::logfileinfo, $infoline);
100 else
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);
113 if ($returnvalue)
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";
119 system($localcall);
121 else
123 if ( -d $directory )
125 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n";
126 push(@installer::globals::logfileinfo, $infoline);
128 else
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");
135 else
137 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
138 push(@installer::globals::logfileinfo, $infoline);
142 else
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) = @_;
157 my $returnvalue = 1;
158 my $infoline = "";
160 if (!(-d $directory))
162 my $localprivileges = oct("0".$privileges); # changes "777" to 0777
163 $returnvalue = mkdir($directory, $localprivileges);
165 if ($returnvalue)
167 $infoline = "\nCreated directory: $directory\n";
168 push(@installer::globals::logfileinfo, $infoline);
170 my $localcall = "chmod $privileges $directory \>\/dev\/null 2\>\&1";
171 system($localcall);
173 else
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
177 # exist now.
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);
192 if ($returnvalue)
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";
198 system($localcall);
200 else
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);
204 if ( -d $parentdir )
206 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n";
207 push(@installer::globals::logfileinfo, $infoline);
209 else
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);
222 if ($returnvalue)
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";
228 system($localcall);
230 else
232 if ( -d $directory )
234 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n";
235 push(@installer::globals::logfileinfo, $infoline);
237 else
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");
244 else
246 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
247 push(@installer::globals::logfileinfo, $infoline);
251 else
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";
257 system($localcall);
261 ######################################################
262 # Removing a new direcotory
263 ######################################################
265 sub remove_empty_directory
267 my ($directory) = @_;
269 my $returnvalue = 1;
271 if (-d $directory)
273 my $systemcall = "rmdir $directory";
275 $returnvalue = system($systemcall);
277 my $infoline = "Systemcall: $systemcall\n";
278 push( @installer::globals::logfileinfo, $infoline);
280 if ($returnvalue)
282 $infoline = "ERROR: Could not remove \"$directory\"!\n";
283 push( @installer::globals::logfileinfo, $infoline);
285 else
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
303 my $path = "";
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);
320 else
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);
336 else
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);
388 return $path;
391 ########################
392 # Copying one file
393 ########################
395 sub copy_one_file
397 my ($source, $dest) = @_;
399 my ($returnvalue, $infoline);
401 my $copyreturn = copy($source, $dest);
403 if ($copyreturn)
405 $infoline = "Copy: $source to $dest\n";
406 $returnvalue = 1;
408 else
410 $infoline = "ERROR: Could not copy $source to $dest\n";
411 $returnvalue = 0;
414 push(@installer::globals::logfileinfo, $infoline);
416 if ( !$returnvalue ) {
417 return $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);
425 if ($chmodreturn)
427 $infoline = "chmod $mode_str, $dest\n";
428 $returnvalue = 1;
430 else
432 $infoline = "WARNING: Could not chmod $dest: $!\n";
433 $returnvalue = 0;
436 push(@installer::globals::logfileinfo, $infoline);
439 return $returnvalue;
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);
454 if ($copyreturn)
456 $infoline = "Link: $source to $dest\n";
457 $returnvalue = 1;
459 else
461 $infoline = "ERROR: Could not link $source to $dest\n";
462 $returnvalue = 0;
465 push(@installer::globals::logfileinfo, $infoline);
467 return $returnvalue;
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);
482 if ($linkreturn)
484 $infoline = "Symlink: $source to $dest\n";
485 $returnvalue = 1;
487 else
489 $infoline = "ERROR: Could not symlink $source to $dest\n";
490 $returnvalue = 0;
493 push(@installer::globals::logfileinfo, $infoline);
495 return $returnvalue;
498 ########################
499 # Renaming one file
500 ########################
502 sub rename_one_file
504 my ($source, $dest) = @_;
506 my ($returnvalue, $infoline);
508 my $renamereturn = rename($source, $dest);
510 if ($renamereturn)
512 $infoline = "Rename: $source to $dest\n";
513 $returnvalue = 1;
515 else
517 $infoline = "ERROR: Could not rename $source to $dest\n";
518 $returnvalue = 0;
521 push(@installer::globals::logfileinfo, $infoline);
523 return $returnvalue;
526 ##########################################
527 # Copying all files from one directory
528 # to another directory
529 ##########################################
531 sub copy_directory
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*$//;
540 my $infoline = "\n";
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);
547 closedir(DIR);
549 my $onefile;
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 ##########################################
570 sub is_empty_dir
572 my ($dir) = @_;
574 my $directory_is_empty = 1;
575 my @sourcefiles = ();
577 opendir(DIR, $dir);
578 @sourcefiles = readdir(DIR);
579 closedir(DIR);
581 my $onefile;
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); }
612 my $infoline = "\n";
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);
619 closedir(DIR);
621 my $onefile;
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); }
656 my $infoline = "\n";
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);
663 closedir(DIR);
665 my $onefile;
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); }
703 my $infoline = "\n";
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);
710 closedir(DIR);
712 my $onefile;
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); }
750 my $infoline = "\n";
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);
757 closedir(DIR);
759 my $onefile;
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*$//;
793 $infoline = "\n";
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);
800 closedir(DIR);
802 my $onefile;
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*$//;
835 $infoline = "\n";
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);
842 closedir(DIR);
844 my $onefile;
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*$//;
877 my $infoline = "\n";
878 push(@installer::globals::logfileinfo, $infoline);
879 $infoline = "Renaming files with extension \"$extension\" in the directory $dir\n";
880 push(@installer::globals::logfileinfo, $infoline);
882 opendir(DIR, $dir);
883 @sourcefiles = readdir(DIR);
884 closedir(DIR);
886 my $onefile;
888 foreach $onefile (@sourcefiles)
890 if ((!($onefile eq ".")) && (!($onefile eq "..")))
892 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ ) # only renaming specified files
894 my $destfile = $1;
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) = @_;
915 my @allfiles = ();
917 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
919 my $infoline = "\n";
920 push(@installer::globals::logfileinfo, $infoline);
921 $infoline = "Searching files with extension \"$extension\" in the directory $dir\n";
922 push(@installer::globals::logfileinfo, $infoline);
924 opendir(DIR, $dir);
925 @sourcefiles = readdir(DIR);
926 closedir(DIR);
928 my $onefile;
930 foreach $onefile (@sourcefiles)
932 if ((!($onefile eq ".")) && (!($onefile eq "..")))
934 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ )
936 push(@allfiles, $onefile)
941 return \@allfiles;
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
960 my $maxnumber = 0;
962 for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
964 if ( ${$alldirs}[$i] =~ /\_(\d+)\s*$/ )
966 my $number = $1;
967 if ( $number > $maxnumber ) { $maxnumber = $number; }
971 my $newnumber = $maxnumber + 1;
973 my $newdir = $olddir . "_" . $newstring . "_" . $newnumber;
975 my $returndir = "";
977 if ( move($olddir, $newdir) )
979 $infoline = "\nMoved directory from $olddir to $newdir\n";
980 push(@installer::globals::logfileinfo, $infoline);
981 $returndir = $newdir;
983 else
985 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"make_numbered_dir\"\n";
986 push(@installer::globals::logfileinfo, $infoline);
987 $returndir = $olddir;
990 return $returndir;
993 ##############################################################
994 # Determining the highest number in the install directory.
995 ##############################################################
997 sub determine_maximum_number
999 my ($dir, $languagestringref) = @_;
1001 my $basedir = $dir;
1002 installer::pathanalyzer::get_path_from_fullqualifiedname(\$basedir);
1004 my $alldirs = get_all_directories($basedir);
1006 my $maxnumber = 1;
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*$/ )
1025 my $number = $2;
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*$/ )
1043 my $number = $2;
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*$/ )
1064 my $number = $2;
1065 my $languagestring = $3;
1067 if ( $languagestring eq $$languagestringref )
1069 $increase_counter = 1;
1074 if ( $increase_counter )
1076 $maxnumber = $maxnumber + 1;
1079 return $maxnumber;
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;
1092 my $infoline = "";
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);
1103 else
1105 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_string_in_directory\"\n";
1106 push(@installer::globals::logfileinfo, $infoline);
1109 return $newdir;
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) = @_;
1121 my $dirname = "";
1122 my $founddir = 0;
1123 my $direntry;
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;
1135 $founddir = 1;
1136 last;
1140 closedir(DIR);
1142 if ( ! $founddir ) { installer::exiter::exit_program("ERROR: Did not find directory beginning with $startstring in directory $searchdir", "get_directoryname"); }
1144 return $dirname;
1148 ###################################
1149 # Renaming a directory
1150 ###################################
1152 sub rename_directory
1154 my ($olddir, $newdir) = @_;
1156 my $infoline = "";
1158 if ( move($olddir, $newdir) )
1160 $infoline = "\nMoved directory from $olddir to $newdir\n";
1161 push(@installer::globals::logfileinfo, $infoline);
1163 else
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);
1170 return $newdir;
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);
1190 return $newdir;
1193 ##############################################################
1194 # Collecting all directories inside a directory
1195 ##############################################################
1197 sub get_all_directories
1199 my ($basedir) = @_;
1201 my @alldirs = ();
1202 my $direntry;
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); }
1218 closedir(DIR);
1220 return \@alldirs;
1223 ##############################################################
1224 # Collecting all directories inside a directory
1225 # Returning without path
1226 ##############################################################
1228 sub get_all_directories_without_path
1230 my ($basedir) = @_;
1232 my @alldirs = ();
1233 my $direntry;
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); }
1249 closedir(DIR);
1251 return \@alldirs;
1254 ##############################################################
1255 # Collecting all files inside one directory
1256 ##############################################################
1258 sub get_all_files_from_one_directory
1260 my ($basedir) = @_;
1262 my @allfiles = ();
1263 my $direntry;
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); }
1279 closedir(DIR);
1281 return \@allfiles;
1284 ##############################################################
1285 # Collecting all files inside one directory
1286 ##############################################################
1288 sub get_all_files_from_one_directory_without_path
1290 my ($basedir) = @_;
1292 my @allfiles = ();
1293 my $direntry;
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); }
1309 closedir(DIR);
1311 return \@allfiles;
1314 ##############################################################
1315 # Collecting all files and directories inside one directory
1316 ##############################################################
1318 sub read_directory
1320 my ($basedir) = @_;
1322 my @allcontent = ();
1323 my $direntry;
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); }
1339 closedir(DIR);
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 = ();
1355 my $direntry;
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);
1378 closedir(DIR);
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);
1398 if ($returnvalue)
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";
1405 system($localcall);
1407 else
1409 $created_directory = 0;
1412 else
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) = @_;
1452 my @content = ();
1453 my $infoline = "";
1455 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1457 if ( -d $directory )
1459 if ( $start )
1461 $infoline = "\n";
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);
1469 closedir(DIR);
1471 my $oneitem;
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
1481 unlink($item);
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 )
1508 $infoline = "\n";
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;
1515 if ( $returnvalue )
1517 $infoline = "Successfully removed empty dir $directory\n";
1518 push(@installer::globals::logfileinfo, $infoline);
1519 } else {
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";
1540 my $counter = 1;
1541 my $created = 0;
1542 my $localdirectory = "";
1546 $localdirectory = $directory;
1547 $localdirectory =~ s/INCREASINGNUMBER/$counter/;
1548 $counter++;
1550 if ( ! -d $localdirectory )
1552 create_directory($localdirectory);
1553 $created = 1;
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"); }
1578 return $directory;
1581 ##############################################################
1582 # Reading all files from a directory and its subdirectories
1583 ##############################################################
1585 sub read_complete_directory
1587 my ($directory, $pathstring, $filecollector) = @_;
1589 my @content = ();
1590 opendir(DIR, $directory);
1591 @content = readdir(DIR);
1592 closedir(DIR);
1594 my $onefile;
1596 foreach $onefile (@content)
1598 if ((!($onefile eq ".")) && (!($onefile eq "..")))
1600 my $completefilename = $directory . $installer::globals::separator . $onefile;
1601 my $sep = "";
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
1620 # Version 2
1621 ##############################################################
1623 sub read_full_directory {
1624 my ( $currentdir, $pathstring, $collector ) = @_;
1625 my $item;
1626 my $fullname;
1627 local *DH;
1629 unless (opendir(DH, $currentdir))
1631 return;
1633 while (defined ($item = readdir(DH)))
1635 next if($item eq "." or $item eq "..");
1636 $fullname = $currentdir . $installer::globals::separator . $item;
1637 my $sep = "";
1638 if ( $pathstring ne "" ) { $sep = $installer::globals::separator; }
1640 if( -d $fullname)
1642 my $newpathstring = $pathstring . $sep . $item;
1643 read_full_directory($fullname, $newpathstring, $collector) if(-d $fullname);
1645 else
1647 my $content = $pathstring . $sep . $item;
1648 push(@{$collector}, $content);
1651 closedir(DH);
1652 return