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
::systemactions
;
23 use installer
::converter
;
24 use installer
::exiter
;
25 use installer
::globals
;
26 use installer
::pathanalyzer
;
27 use installer
::remover
;
29 ######################################################
30 # Creating a new direcotory
31 ######################################################
37 create_directory_with_privileges
( $directory, "755" );
40 ######################################################
41 # Creating a new direcotory with defined privileges
42 ######################################################
44 sub create_directory_with_privileges
46 my ($directory, $privileges) = @_;
50 my $localprivileges = oct("0".$privileges); # changes "777" to 0777
54 $returnvalue = mkdir($directory, $localprivileges);
58 $infoline = "\nCreated directory: $directory\n";
59 push(@installer::globals
::logfileinfo
, $infoline);
61 chmod $localprivileges, $directory;
65 # New solution in parallel packing: It is possible, that the directory now exists, although it
66 # was not created in this process. There is only an important error, if the directory does not
69 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n";
70 push(@installer::globals
::logfileinfo
, $infoline);
74 # Problem with parallel packaging? -> Try a little harder, before exiting.
75 # Did someone else remove the parent directory in the meantime?
76 my $parentdir = $directory;
77 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$parentdir);
80 $returnvalue = mkdir($directory, $localprivileges);
84 $infoline = "\nAttention: Successfully created parent directory (should already be created before): $parentdir\n";
85 push(@installer::globals
::logfileinfo
, $infoline);
87 chmod $localprivileges, $parentdir;
91 $infoline = "\nError: \"$directory\" could not be created. Even the parent directory \"$parentdir\" does not exist and could not be created.\n";
92 push(@installer::globals
::logfileinfo
, $infoline);
95 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n";
96 push(@installer::globals
::logfileinfo
, $infoline);
100 # Now it is time to exit, even the parent could not be created.
101 installer
::exiter
::exit_program
("ERROR: Could not create parent directory \"$parentdir\"", "create_directory_with_privileges");
106 # At this point we have to assume, that the parent directory exist.
107 # Trying once more to create the desired directory
109 $returnvalue = mkdir($directory, $localprivileges);
113 $infoline = "\nAttention: Created directory \"$directory\" in the second try.\n";
114 push(@installer::globals
::logfileinfo
, $infoline);
116 chmod $localprivileges, $directory;
122 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n";
123 push(@installer::globals
::logfileinfo
, $infoline);
127 # It is time to exit, even the second try failed.
128 installer
::exiter
::exit_program
("ERROR: Failed to create the directory: $directory", "create_directory_with_privileges");
134 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
135 push(@installer::globals
::logfileinfo
, $infoline);
141 $infoline = "\nAlready existing directory, did not create: $directory\n";
142 push(@installer::globals
::logfileinfo
, $infoline);
144 chmod $localprivileges, $directory;
148 #######################################################################
149 # Calculating the number of languages in the string
150 #######################################################################
152 sub get_number_of_langs
154 my ($languagestring) = @_;
158 my $workstring = $languagestring;
160 while ( $workstring =~ /^\s*(.*)_(.*?)\s*$/ )
169 #######################################################################
170 # Creating the directories, in which files are generated or unzipped
171 #######################################################################
173 sub create_directories
175 my ($newdirectory, $languagesref) =@_;
177 $installer::globals
::unpackpath
=~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
181 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
183 if ( $installer::globals
::temppathdefined
) { $path = $installer::globals
::temppath
; }
184 else { $path = $installer::globals
::unpackpath
; }
185 $path =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
186 $path = $path . $installer::globals
::separator
;
190 $path = $installer::globals
::unpackpath
. $installer::globals
::separator
;
192 # special handling, if LOCALINSTALLDIR is set
193 if (( $installer::globals
::localinstalldirset
) && ( $newdirectory eq "install" ))
195 $installer::globals
::localinstalldir
=~ s/\Q$installer::globals::separator\E\s*$//;
196 $path = $installer::globals
::localinstalldir
. $installer::globals
::separator
;
200 $infoline = "create_directories: Using $path for $newdirectory !\n";
201 push( @installer::globals
::logfileinfo
, $infoline);
203 if ($newdirectory eq "unzip" ) # special handling for common directory
208 my $localproductname = $installer::globals
::product
;
209 my $localproductsubdir = "";
211 if ( $installer::globals
::product
=~ /^\s*(.+?)\_\_(.+?)\s*$/ )
213 $localproductname = $1;
214 $localproductsubdir = $2;
217 if ( $installer::globals
::languagepack
) { $path = $path . $localproductname . "_languagepack" . $installer::globals
::separator
; }
218 elsif ( $installer::globals
::helppack
) { $path = $path . $localproductname . "_helppack" . $installer::globals
::separator
; }
219 else { $path = $path . $localproductname . $installer::globals
::separator
; }
221 create_directory
($path);
223 if ( $localproductsubdir )
225 $path = $path . $localproductsubdir . $installer::globals
::separator
;
226 create_directory
($path);
229 $path = $path . $installer::globals
::installertypedir
. $installer::globals
::separator
;
230 create_directory
($path);
232 $path = $path . $newdirectory . $installer::globals
::separator
;
233 create_directory
($path);
235 my $locallanguagesref = "";
237 if ( $$languagesref ) { $locallanguagesref = $$languagesref; }
239 if ($newdirectory eq "install" && $installer::globals
::ooodownloadfilename
ne "" )
241 # put packages into versioned path; needed only on linux (fdo#30837)
242 $path = $path . "$installer::globals::ooodownloadfilename" . $installer::globals
::separator
;
243 create_directory
($path);
247 if ($locallanguagesref ne "") # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
250 my $languagestring = $$languagesref;
252 if (length($languagestring) > $installer::globals
::max_lang_length
)
254 my $number_of_languages = get_number_of_langs
($languagestring);
255 chomp(my $shorter = `echo $languagestring | $ENV{'MD5SUM'} | sed -e "s/ .*//g"`);
256 my $id = substr($shorter, 0, 8); # taking only the first 8 digits
257 $languagestring = "lang_" . $number_of_languages . "_id_" . $id;
260 $path = $path . $languagestring . $installer::globals
::separator
;
261 create_directory
($path);
266 installer
::remover
::remove_ending_pathseparator
(\
$path);
268 $path = installer
::converter
::make_path_conform
($path);
273 ########################
275 ########################
279 my ($source, $dest) = @_;
281 my ($returnvalue, $infoline, $copyreturn);
284 $copyreturn = symlink(readlink("$source"), "$dest");
287 $copyreturn = copy
($source, $dest);
292 $infoline = "Copy: $source to $dest\n";
297 $infoline = "ERROR: Could not copy $source to $dest $!\n";
301 push(@installer::globals
::logfileinfo
, $infoline);
303 if ( !$returnvalue ) {
307 # taking care of file attributes
308 if ($installer::globals
::iswin
&& -f
$dest) {
309 my $mode = -x
$source ?
0775 : 0664;
310 my $mode_str = sprintf("%o", $mode);
311 my $chmodreturn = chmod($mode, $dest);
314 $infoline = "chmod $mode_str, $dest\n";
319 $infoline = "WARNING: Could not chmod $dest: $!\n";
323 push(@installer::globals
::logfileinfo
, $infoline);
329 ##########################
330 # Hard linking one file
331 ##########################
333 sub hardlink_one_file
335 my ($source, $dest) = @_;
337 my ($returnvalue, $infoline);
339 my $copyreturn = link($source, $dest);
343 $infoline = "Link: $source to $dest\n";
348 $infoline = "ERROR: Could not link $source to $dest\n";
352 push(@installer::globals
::logfileinfo
, $infoline);
357 ##########################
358 # Soft linking one file
359 ##########################
361 sub softlink_one_file
363 my ($source, $dest) = @_;
365 my ($returnvalue, $infoline);
367 my $linkreturn = symlink($source, $dest);
371 $infoline = "Symlink: $source to $dest\n";
376 $infoline = "ERROR: Could not symlink $source to $dest\n";
380 push(@installer::globals
::logfileinfo
, $infoline);
385 ########################
387 ########################
391 my ($source, $dest) = @_;
393 my ($returnvalue, $infoline);
395 my $renamereturn = rename($source, $dest);
399 $infoline = "Rename: $source to $dest\n";
404 $infoline = "ERROR: Could not rename $source to $dest\n";
408 push(@installer::globals
::logfileinfo
, $infoline);
413 ##########################################
414 # Copying all files from one directory
415 # to another directory
416 ##########################################
420 my ($sourcedir, $destdir) = @_;
422 my @sourcefiles = ();
424 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
425 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
428 push(@installer::globals
::logfileinfo
, $infoline);
429 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
430 push(@installer::globals
::logfileinfo
, $infoline);
432 opendir(DIR
, $sourcedir);
433 @sourcefiles = readdir(DIR
);
438 foreach $onefile (@sourcefiles)
440 if ((!($onefile eq ".")) && (!($onefile eq "..")))
442 my $sourcefile = $sourcedir . $installer::globals
::separator
. $onefile;
443 my $destfile = $destdir . $installer::globals
::separator
. $onefile;
444 if ( -f
$sourcefile ) # only files, no directories
446 copy_one_file
($sourcefile, $destfile);
452 ##########################################
453 # Copying all files from one directory
454 # to another directory
455 ##########################################
461 my $directory_is_empty = 1;
462 my @sourcefiles = ();
465 @sourcefiles = readdir(DIR
);
469 my @realcontent = ();
471 foreach $onefile (@sourcefiles)
473 if ((!($onefile eq ".")) && (!($onefile eq "..")))
475 push(@realcontent, $onefile);
479 if ( $#realcontent > -1 ) { $directory_is_empty = 0; }
481 return $directory_is_empty;
484 #####################################################################
485 # Creating hard links to a complete directory with sub directories.
486 #####################################################################
488 sub hardlink_complete_directory
490 my ($sourcedir, $destdir) = @_;
492 my @sourcefiles = ();
494 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
495 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
497 if ( ! -d
$destdir ) { create_directory
($destdir); }
500 push(@installer::globals
::logfileinfo
, $infoline);
501 $infoline = "Creating hard links for all files from directory $sourcedir to directory $destdir\n";
502 push(@installer::globals
::logfileinfo
, $infoline);
504 opendir(DIR
, $sourcedir);
505 @sourcefiles = readdir(DIR
);
510 foreach $onefile (@sourcefiles)
512 if ((!($onefile eq ".")) && (!($onefile eq "..")))
514 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
515 my $dest = $destdir . $installer::globals
::separator
. $onefile;
516 if ( -f
$source ) # only files, no directories
518 hardlink_one_file
($source, $dest);
520 if ( -d
$source ) # recursive
522 hardlink_complete_directory
($source, $dest);
528 #####################################################################
529 # Creating hard links to a complete directory with sub directories.
530 #####################################################################
532 sub softlink_complete_directory
534 my ($sourcedir, $destdir, $depth) = @_;
536 my @sourcefiles = ();
538 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
539 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
541 if ( ! -d
$destdir ) { create_directory
($destdir); }
544 push(@installer::globals
::logfileinfo
, $infoline);
545 $infoline = "Creating soft links for all files from directory $sourcedir to directory $destdir\n";
546 push(@installer::globals
::logfileinfo
, $infoline);
548 opendir(DIR
, $sourcedir);
549 @sourcefiles = readdir(DIR
);
554 foreach $onefile (@sourcefiles)
556 if ((!($onefile eq ".")) && (!($onefile eq "..")))
558 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
559 my $dest = $destdir . $installer::globals
::separator
. $onefile;
560 if ( -f
$source ) # only files, no directories
562 my $localsource = $source;
563 if ( $depth > 0 ) { for ( my $i = 1; $i <= $depth; $i++ ) { $localsource = "../" . $localsource; } }
564 softlink_one_file
($localsource, $dest);
566 if ( -d
$source ) # recursive
568 my $newdepth = $depth + 1;
569 softlink_complete_directory
($source, $dest, $newdepth);
575 #####################################################
576 # Copying a complete directory with sub directories.
577 #####################################################
579 sub copy_complete_directory
581 my ($sourcedir, $destdir) = @_;
583 my @sourcefiles = ();
585 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
586 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
588 if ( ! -d
$destdir ) { create_directory
($destdir); }
591 push(@installer::globals
::logfileinfo
, $infoline);
592 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
593 push(@installer::globals
::logfileinfo
, $infoline);
595 opendir(DIR
, $sourcedir);
596 @sourcefiles = readdir(DIR
);
601 foreach $onefile (@sourcefiles)
603 if ((!($onefile eq ".")) && (!($onefile eq "..")))
605 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
606 my $dest = $destdir . $installer::globals
::separator
. $onefile;
607 if ( -f
$source ) # only files, no directories
609 copy_one_file
($source, $dest);
611 if ( -d
$source ) # recursive
613 if ((!( $source =~ /packages\/SUNW
/ )) && (!( $source =~ /packages\
/OOO/ ))) # do not copy complete Solaris packages!
615 copy_complete_directory
($source, $dest);
622 #####################################################
623 # Copying all files with a specified file extension
624 # from one directory to another directory.
625 #####################################################
627 sub copy_directory_with_fileextension
629 my ($sourcedir, $destdir, $extension) = @_;
631 my @sourcefiles = ();
633 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
634 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
637 push(@installer::globals
::logfileinfo
, $infoline);
638 $infoline = "Copying files with extension $extension from directory $sourcedir to directory $destdir\n";
639 push(@installer::globals
::logfileinfo
, $infoline);
641 opendir(DIR
, $sourcedir);
642 @sourcefiles = readdir(DIR
);
647 foreach $onefile (@sourcefiles)
649 if ((!($onefile eq ".")) && (!($onefile eq "..")))
651 if ( $onefile =~ /\.$extension\s*$/ ) # only copying specified files
653 my $sourcefile = $sourcedir . $installer::globals
::separator
. $onefile;
654 my $destfile = $destdir . $installer::globals
::separator
. $onefile;
655 if ( -f
$sourcefile ) # only files, no directories
657 copy_one_file
($sourcefile, $destfile);
664 ########################################################
665 # Renaming all files with a specified file extension
666 # in a specified directory.
667 # Example: "Feature.idt.01" -> "Feature.idt"
668 ########################################################
670 sub rename_files_with_fileextension
672 my ($dir, $extension) = @_;
674 my @sourcefiles = ();
676 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
679 push(@installer::globals
::logfileinfo
, $infoline);
680 $infoline = "Renaming files with extension \"$extension\" in the directory $dir\n";
681 push(@installer::globals
::logfileinfo
, $infoline);
684 @sourcefiles = readdir(DIR
);
689 foreach $onefile (@sourcefiles)
691 if ((!($onefile eq ".")) && (!($onefile eq "..")))
693 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ ) # only renaming specified files
696 my $sourcefile = $dir . $installer::globals
::separator
. $onefile;
697 $destfile = $dir . $installer::globals
::separator
. $destfile;
698 if ( -f
$sourcefile ) # only files, no directories
700 rename_one_file
($sourcefile, $destfile);
707 ########################################################
708 # Finding all files with a specified file extension
709 # in a specified directory.
710 ########################################################
712 sub find_file_with_file_extension
714 my ($extension, $dir) = @_;
718 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
721 push(@installer::globals
::logfileinfo
, $infoline);
722 $infoline = "Searching files with extension \"$extension\" in the directory $dir\n";
723 push(@installer::globals
::logfileinfo
, $infoline);
726 @sourcefiles = sort readdir(DIR
);
731 foreach $onefile (@sourcefiles)
733 if ((!($onefile eq ".")) && (!($onefile eq "..")))
735 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ )
737 push(@allfiles, $onefile)
745 ##############################################################
746 # Creating a unique directory, for example "01_inprogress_7"
747 # in the install directory.
748 ##############################################################
750 sub make_numbered_dir
752 my ($newstring, $olddir) = @_;
754 my $basedir = $olddir;
755 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$basedir);
757 my $alldirs = get_all_directories
($basedir);
759 # searching for the highest number extension
763 for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
765 if ( ${$alldirs}[$i] =~ /\_(\d+)\s*$/ )
768 if ( $number > $maxnumber ) { $maxnumber = $number; }
772 my $newnumber = $maxnumber + 1;
774 my $newdir = $olddir . "_" . $newstring . "_" . $newnumber;
778 if ( move
($olddir, $newdir) )
780 $infoline = "\nMoved directory from $olddir to $newdir\n";
781 push(@installer::globals
::logfileinfo
, $infoline);
782 $returndir = $newdir;
786 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"make_numbered_dir\"\n";
787 push(@installer::globals
::logfileinfo
, $infoline);
788 $returndir = $olddir;
794 #####################################################################################
795 # Renaming a directory by exchanging a string, for example from "01_inprogress_7"
796 # to "01_witherror_7".
797 #####################################################################################
799 sub rename_string_in_directory
801 my ($olddir, $oldstring, $newstring) = @_;
803 my $newdir = $olddir;
806 $newdir =~ s/$oldstring/$newstring/g;
808 if (( -d
$newdir ) && ( $olddir ne $newdir )) { remove_complete_directory
($newdir, 1); }
810 if ( move
($olddir, $newdir) )
812 $infoline = "\nMoved directory from $olddir to $newdir\n";
813 push(@installer::globals
::logfileinfo
, $infoline);
817 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_string_in_directory\"\n";
818 push(@installer::globals
::logfileinfo
, $infoline);
824 ######################################################
825 # Returning the complete directory name,
826 # input is the first part of the directory name.
827 ######################################################
829 sub get_directoryname
831 my ($searchdir, $startstring) = @_;
837 opendir(DIR
, $searchdir);
839 foreach $direntry (readdir (DIR
))
841 next if $direntry eq ".";
842 next if $direntry eq "..";
844 if (( -d
$direntry ) && ( $direntry =~ /^\s*\Q$startstring\E/ ))
846 $dirname = $direntry;
854 if ( ! $founddir ) { installer
::exiter
::exit_program
("ERROR: Did not find directory beginning with $startstring in directory $searchdir", "get_directoryname"); }
860 ###################################
861 # Renaming a directory
862 ###################################
866 my ($olddir, $newdir) = @_;
870 if ( move
($olddir, $newdir) )
872 $infoline = "\nMoved directory from $olddir to $newdir\n";
873 push(@installer::globals
::logfileinfo
, $infoline);
877 installer
::exiter
::exit_program
("ERROR: Could not move directory from $olddir to $newdir $!", "rename_directory");
883 ##############################################################
884 # Creating a directory next to an existing directory
885 ##############################################################
887 sub create_directory_next_to_directory
889 my ($topdir, $dirname) = @_;
891 my $basedir = $topdir;
892 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$basedir);
894 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
896 my $newdir = $basedir . $installer::globals
::separator
. $dirname;
898 create_directory
($newdir);
903 ##############################################################
904 # Collecting all directories inside a directory
905 ##############################################################
907 sub get_all_directories
914 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
916 opendir(DIR
, $basedir);
918 foreach $direntry (readdir (DIR
))
920 next if $direntry eq ".";
921 next if $direntry eq "..";
923 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
925 if ( -d
$completeentry ) { push(@alldirs, $completeentry); }
933 ##############################################################
934 # Collecting all directories inside a directory
935 # Returning without path
936 ##############################################################
938 sub get_all_directories_without_path
945 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
947 opendir(DIR
, $basedir);
949 foreach $direntry (readdir (DIR
))
951 next if $direntry eq ".";
952 next if $direntry eq "..";
954 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
956 if ( -d
$completeentry ) { push(@alldirs, $direntry); }
964 ##############################################################
965 # Collecting all files and directories inside one directory
966 ##############################################################
975 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
977 opendir(DIR
, $basedir);
979 foreach $direntry (readdir (DIR
))
981 next if $direntry eq ".";
982 next if $direntry eq "..";
984 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
986 if (( -f
$completeentry ) || ( -d
$completeentry )) { push(@allcontent, $completeentry); }
994 ##############################################################
995 # Finding the new content in a directory
996 ##############################################################
998 sub find_new_content_in_directory
1000 my ( $basedir, $oldcontent ) = @_;
1002 my @newcontent = ();
1003 my @allcontent = ();
1007 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1009 opendir(DIR
, $basedir);
1011 foreach $direntry (readdir (DIR
))
1013 next if $direntry eq ".";
1014 next if $direntry eq "..";
1016 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1018 if (( -f
$completeentry ) || ( -d
$completeentry ))
1020 push(@allcontent, $completeentry);
1021 if (! grep {$_ eq $completeentry} @
{$oldcontent})
1023 push(@newcontent, $completeentry);
1030 return (\
@newcontent, \
@allcontent);
1033 ##############################################################
1034 # Trying to create a directory, no error if this fails
1035 ##############################################################
1037 sub try_to_create_directory
1039 my ($directory) = @_;
1041 my $returnvalue = 1;
1042 my $created_directory = 0;
1044 if (!(-d
$directory))
1046 $returnvalue = mkdir($directory, 0775);
1050 $created_directory = 1;
1051 $infoline = "\nCreated directory: $directory\n";
1052 push(@installer::globals
::logfileinfo
, $infoline);
1054 chmod 0775, $directory;
1058 $created_directory = 0;
1063 $created_directory = 1;
1066 return $created_directory;
1069 ##############################################################
1070 # Creating a complete directory structure
1071 ##############################################################
1073 sub create_directory_structure
1075 my ($directory) = @_;
1077 if ( ! try_to_create_directory
($directory) )
1079 my $parentdir = $directory;
1080 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$parentdir);
1082 my $infoline = "INFO: Did not create directory $directory\n";
1083 push(@installer::globals
::logfileinfo
, $infoline);
1084 $infoline = "Now trying to create parent directory $parentdir\n";
1085 push(@installer::globals
::logfileinfo
, $infoline);
1087 create_directory_structure
($parentdir); # recursive
1090 create_directory
($directory); # now it has to succeed
1093 ######################################################
1094 # Removing a complete directory with subdirectories
1095 ######################################################
1097 sub remove_complete_directory
1099 my ($directory, $start) = @_;
1104 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1106 if ( -d
$directory )
1111 push(@installer::globals
::logfileinfo
, $infoline);
1112 $infoline = "Removing directory $directory\n";
1113 push(@installer::globals
::logfileinfo
, $infoline);
1116 opendir(DIR
, $directory);
1117 @content = readdir(DIR
);
1122 foreach $oneitem (@content)
1124 if ((!($oneitem eq ".")) && (!($oneitem eq "..")))
1126 my $item = $directory . $installer::globals
::separator
. $oneitem;
1128 if ( -f
$item || -l
$item ) # deleting files or links
1133 if ( -d
$item ) # recursive
1135 remove_complete_directory
($item, 0);
1140 # try to remove empty directory
1142 my $returnvalue = rmdir $directory;
1144 if ( ! $returnvalue )
1146 $infoline = "Warning: Problem with removing empty dir $directory\n";
1147 push(@installer::globals
::logfileinfo
, $infoline);
1150 # try a little bit harder (sometimes there is a performance problem)
1151 if ( -d
$directory )
1153 for ( my $j = 1; $j <= 3; $j++ )
1155 if ( -d
$directory )
1158 push(@installer::globals
::logfileinfo
, $infoline);
1159 $infoline = "Warning (Try $j): Problems with removing directory $directory\n";
1160 push(@installer::globals
::logfileinfo
, $infoline);
1162 $returnvalue = rmdir $directory;
1166 $infoline = "Successfully removed empty dir $directory\n";
1167 push(@installer::globals
::logfileinfo
, $infoline);
1169 $infoline = "Warning: rmdir $directory failed.\n";
1170 push(@installer::globals
::logfileinfo
, $infoline);
1178 ######################################################
1179 # Creating a unique directory with pid extension
1180 ######################################################
1182 sub create_pid_directory
1184 my ($directory) = @_;
1186 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1187 my $pid = $$; # process id
1188 my $time = time(); # time
1190 $directory = $directory . "_" . $pid . $time;
1192 if ( ! -d
$directory ) { create_directory
($directory); }
1193 else { installer
::exiter
::exit_program
("ERROR: Directory $directory already exists!", "create_pid_directory"); }
1198 ##############################################################
1199 # Reading all files from a directory and its subdirectories
1200 ##############################################################
1202 sub read_complete_directory
1204 my ($directory, $pathstring, $filecollector) = @_;
1207 opendir(DIR
, $directory);
1208 @content = readdir(DIR
);
1213 foreach $onefile (@content)
1215 if ((!($onefile eq ".")) && (!($onefile eq "..")))
1217 my $completefilename = $directory . $installer::globals
::separator
. $onefile;
1219 if ( $pathstring ne "" ) { $sep = $installer::globals
::separator
; }
1221 if ( ! -d
$completefilename ) # only files, no directories
1223 my $content = $pathstring . $sep . $onefile;
1224 push(@
{$filecollector}, $content);
1226 else # recursive for directories
1228 my $newpathstring = $pathstring . $sep . $onefile;
1229 read_complete_directory
($completefilename, $newpathstring, $filecollector);
1235 ##############################################################
1236 # Reading all files from a directory and its subdirectories
1238 ##############################################################
1240 sub read_full_directory
{
1241 my ( $currentdir, $pathstring, $collector ) = @_;
1246 unless (opendir(DH
, $currentdir))
1250 while (defined ($item = readdir(DH
)))
1252 next if($item eq "." or $item eq "..");
1253 $fullname = $currentdir . $installer::globals
::separator
. $item;
1255 if ( $pathstring ne "" ) { $sep = $installer::globals
::separator
; }
1259 my $newpathstring = $pathstring . $sep . $item;
1260 read_full_directory
($fullname, $newpathstring, $collector) if(-d
$fullname);
1264 my $content = $pathstring . $sep . $item;
1265 push(@
{$collector}, $content);
1272 ##############################################################
1273 # Removing all empty directories below a specified directory
1274 ##############################################################
1276 sub remove_empty_dirs_in_folder
1283 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
1288 @content = readdir(DIR
);
1293 foreach $oneitem (@content)
1295 if ((!($oneitem eq ".")) && (!($oneitem eq "..")))
1297 my $item = $dir . $installer::globals
::separator
. $oneitem;
1299 if ( -d
$item ) # recursive
1301 remove_empty_dirs_in_folder
($item);
1306 # try to remove empty directory
1307 my $returnvalue = rmdir $dir;
1311 $infoline = "Successfully removed empty dir $dir\n";
1312 push(@installer::globals
::logfileinfo
, $infoline);
1319 ######################################################
1321 ######################################################
1325 my ($systemcall) = @_;
1327 my $returnvalue = system($systemcall);
1329 my $infoline = "Systemcall: $systemcall\n";
1330 push( @installer::globals
::logfileinfo
, $infoline);
1334 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
1335 push( @installer::globals
::logfileinfo
, $infoline);
1339 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
1340 push( @installer::globals
::logfileinfo
, $infoline);