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
;
26 use installer
::converter
;
27 use installer
::exiter
;
28 use installer
::globals
;
29 use installer
::pathanalyzer
;
30 use installer
::remover
;
31 use installer
::windows
::msiglobal
;
33 ######################################################
34 # Creating a new directory
35 ######################################################
41 create_directory_with_privileges
( $directory, "755" );
44 ######################################################
45 # Creating a new directory with defined privileges
46 ######################################################
48 sub create_directory_with_privileges
50 my ($directory, $privileges) = @_;
54 my $localprivileges = oct("0".$privileges); # changes "777" to 0777
58 $returnvalue = mkdir($directory, $localprivileges);
62 $infoline = "\nCreated directory: $directory\n";
63 push(@installer::globals
::logfileinfo
, $infoline);
65 chmod $localprivileges, $directory;
69 # New solution in parallel packing: It is possible, that the directory now exists, although it
70 # was not created in this process. There is only an important error, if the directory does not
73 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n";
74 push(@installer::globals
::logfileinfo
, $infoline);
78 # Problem with parallel packaging? -> Try a little harder, before exiting.
79 # Did someone else remove the parent directory in the meantime?
80 my $parentdir = $directory;
81 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$parentdir);
84 $returnvalue = mkdir($directory, $localprivileges);
88 $infoline = "\nAttention: Successfully created parent directory (should already be created before): $parentdir\n";
89 push(@installer::globals
::logfileinfo
, $infoline);
91 chmod $localprivileges, $parentdir;
95 $infoline = "\nError: \"$directory\" could not be created. Even the parent directory \"$parentdir\" does not exist and could not be created.\n";
96 push(@installer::globals
::logfileinfo
, $infoline);
99 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n";
100 push(@installer::globals
::logfileinfo
, $infoline);
104 # Now it is time to exit, even the parent could not be created.
105 installer
::exiter
::exit_program
("ERROR: Could not create parent directory \"$parentdir\"", "create_directory_with_privileges");
110 # At this point we have to assume, that the parent directory exist.
111 # Trying once more to create the desired directory
113 $returnvalue = mkdir($directory, $localprivileges);
117 $infoline = "\nAttention: Created directory \"$directory\" in the second try.\n";
118 push(@installer::globals
::logfileinfo
, $infoline);
120 chmod $localprivileges, $directory;
126 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n";
127 push(@installer::globals
::logfileinfo
, $infoline);
131 # It is time to exit, even the second try failed.
132 installer
::exiter
::exit_program
("ERROR: Failed to create the directory: $directory", "create_directory_with_privileges");
138 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
139 push(@installer::globals
::logfileinfo
, $infoline);
145 $infoline = "\nAlready existing directory, did not create: $directory\n";
146 push(@installer::globals
::logfileinfo
, $infoline);
148 chmod $localprivileges, $directory;
152 #######################################################################
153 # Calculating the number of languages in the string
154 #######################################################################
156 sub get_number_of_langs
158 my ($languagestring) = @_;
162 my $workstring = $languagestring;
164 while ( $workstring =~ /^\s*(.*)_(.*?)\s*$/ )
173 #######################################################################
174 # Creating the directories, in which files are generated or unzipped
175 #######################################################################
177 sub create_directories
179 my ($newdirectory, $languagesref) =@_;
181 $installer::globals
::unpackpath
=~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
185 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
187 if ( $installer::globals
::temppathdefined
) { $path = $installer::globals
::temppath
; }
188 else { $path = $installer::globals
::unpackpath
; }
189 $path =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
190 $path = $path . $installer::globals
::separator
;
194 $path = $installer::globals
::unpackpath
. $installer::globals
::separator
;
196 # special handling, if LOCALINSTALLDIR is set
197 if (( $installer::globals
::localinstalldirset
) && ( $newdirectory eq "install" ))
199 $installer::globals
::localinstalldir
=~ s/\Q$installer::globals::separator\E\s*$//;
200 $path = $installer::globals
::localinstalldir
. $installer::globals
::separator
;
204 my $infoline = "create_directories: Using $path for $newdirectory !\n";
205 push( @installer::globals
::logfileinfo
, $infoline);
207 if ($newdirectory eq "unzip" ) # special handling for common directory
212 my $localproductname = $installer::globals
::product
;
213 my $localproductsubdir = "";
215 if ( $installer::globals
::product
=~ /^\s*(.+?)\_\_(.+?)\s*$/ )
217 $localproductname = $1;
218 $localproductsubdir = $2;
221 if ( $installer::globals
::languagepack
) { $path = $path . $localproductname . "_languagepack" . $installer::globals
::separator
; }
222 elsif ( $installer::globals
::helppack
) { $path = $path . $localproductname . "_helppack" . $installer::globals
::separator
; }
223 else { $path = $path . $localproductname . $installer::globals
::separator
; }
225 create_directory
($path);
227 if ( $localproductsubdir )
229 $path = $path . $localproductsubdir . $installer::globals
::separator
;
230 create_directory
($path);
233 $path = $path . $installer::globals
::installertypedir
. $installer::globals
::separator
;
234 create_directory
($path);
236 $path = $path . $newdirectory . $installer::globals
::separator
;
237 create_directory
($path);
239 my $locallanguagesref = "";
241 if ( $$languagesref ) { $locallanguagesref = $$languagesref; }
243 if ($newdirectory eq "install" && $installer::globals
::ooodownloadfilename
ne "" )
245 # put packages into versioned path; needed only on linux (fdo#30837)
246 $path = $path . "$installer::globals::ooodownloadfilename" . $installer::globals
::separator
;
247 create_directory
($path);
251 if ($locallanguagesref ne "") # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
254 my $languagestring = $$languagesref;
256 if (length($languagestring) > $installer::globals
::max_lang_length
)
258 my $number_of_languages = get_number_of_langs
($languagestring);
259 #replace this in the same it was done in installer/windows/directory.pm
260 #chomp(my $shorter = `echo $languagestring | $ENV{'MD5SUM'} | sed -e "s/ .*//g"`);
261 #my $id = substr($shorter, 0, 8); # taking only the first 8 digits
262 my $id = installer
::windows
::msiglobal
::calculate_id
($languagestring, 8); # taking only the first 8 digits
263 $languagestring = "lang_" . $number_of_languages . "_id_" . $id;
266 $path = $path . $languagestring . $installer::globals
::separator
;
267 create_directory
($path);
272 installer
::remover
::remove_ending_pathseparator
(\
$path);
274 $path = installer
::converter
::make_path_conform
($path);
279 ########################
281 ########################
286 my ($handle, $count);
287 opendir($handle, $dir) or return 0;
288 $count = scalar(grep { $_ ne '.' && $_ ne '..' } readdir($handle));
295 my ($source, $dest) = @_;
297 my ($returnvalue, $infoline, $copyreturn);
300 $copyreturn = symlink(readlink("$source"), "$dest");
302 elsif (-d
$source && is_empty_dir
($source)) {
303 my $mode = (stat($source))[2] & 07777;
304 $copyreturn = mkdir($dest, $mode);
307 $copyreturn = copy
($source, $dest);
312 $infoline = "Copy: $source to $dest\n";
317 $infoline = "ERROR: Could not copy $source to $dest $!\n";
321 push(@installer::globals
::logfileinfo
, $infoline);
323 if ( !$returnvalue ) {
327 # taking care of file attributes
328 if ($installer::globals
::iswin
&& -f
$dest) {
329 my $mode = -x
$source ?
0775 : 0664;
330 my $mode_str = sprintf("%o", $mode);
331 my $chmodreturn = chmod($mode, $dest);
334 $infoline = "chmod $mode_str, $dest\n";
339 $infoline = "WARNING: Could not chmod $dest: $!\n";
343 push(@installer::globals
::logfileinfo
, $infoline);
349 ##########################
350 # Hard linking one file
351 ##########################
353 sub hardlink_one_file
355 my ($source, $dest) = @_;
357 my ($returnvalue, $infoline);
359 my $copyreturn = link($source, $dest);
363 $infoline = "Link: $source to $dest\n";
368 $infoline = "ERROR: Could not link $source to $dest\n";
372 push(@installer::globals
::logfileinfo
, $infoline);
377 ##########################
378 # Soft linking one file
379 ##########################
381 sub softlink_one_file
383 my ($source, $dest) = @_;
385 my ($returnvalue, $infoline);
387 my $linkreturn = symlink($source, $dest);
391 $infoline = "Symlink: $source to $dest\n";
396 $infoline = "ERROR: Could not symlink $source to $dest\n";
400 push(@installer::globals
::logfileinfo
, $infoline);
405 ########################
407 ########################
411 my ($source, $dest) = @_;
413 my ($returnvalue, $infoline);
415 my $renamereturn = rename($source, $dest);
419 $infoline = "Rename: $source to $dest\n";
424 $infoline = "ERROR: Could not rename $source to $dest\n";
428 push(@installer::globals
::logfileinfo
, $infoline);
433 ##########################################
434 # Copying all files from one directory
435 # to another directory
436 ##########################################
440 my ($sourcedir, $destdir) = @_;
442 my @sourcefiles = ();
444 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
445 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
448 push(@installer::globals
::logfileinfo
, $infoline);
449 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
450 push(@installer::globals
::logfileinfo
, $infoline);
452 opendir(DIR
, $sourcedir);
453 @sourcefiles = readdir(DIR
);
458 foreach $onefile (@sourcefiles)
460 if ((!($onefile eq ".")) && (!($onefile eq "..")))
462 my $sourcefile = $sourcedir . $installer::globals
::separator
. $onefile;
463 my $destfile = $destdir . $installer::globals
::separator
. $onefile;
464 if ( -f
$sourcefile ) # only files, no directories
466 copy_one_file
($sourcefile, $destfile);
472 #####################################################################
473 # Creating hard links to a complete directory with sub directories.
474 #####################################################################
476 sub hardlink_complete_directory
478 my ($sourcedir, $destdir) = @_;
480 my @sourcefiles = ();
482 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
483 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
485 if ( ! -d
$destdir ) { create_directory
($destdir); }
488 push(@installer::globals
::logfileinfo
, $infoline);
489 $infoline = "Creating hard links for all files from directory $sourcedir to directory $destdir\n";
490 push(@installer::globals
::logfileinfo
, $infoline);
492 opendir(DIR
, $sourcedir);
493 @sourcefiles = readdir(DIR
);
498 foreach $onefile (@sourcefiles)
500 if ((!($onefile eq ".")) && (!($onefile eq "..")))
502 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
503 my $dest = $destdir . $installer::globals
::separator
. $onefile;
504 if ( -f
$source ) # only files, no directories
506 hardlink_one_file
($source, $dest);
508 if ( -d
$source ) # recursive
510 hardlink_complete_directory
($source, $dest);
516 #####################################################################
517 # Creating hard links to a complete directory with sub directories.
518 #####################################################################
520 sub softlink_complete_directory
522 my ($sourcedir, $destdir, $depth) = @_;
524 my @sourcefiles = ();
526 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
527 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
529 if ( ! -d
$destdir ) { create_directory
($destdir); }
532 push(@installer::globals
::logfileinfo
, $infoline);
533 $infoline = "Creating soft links for all files from directory $sourcedir to directory $destdir\n";
534 push(@installer::globals
::logfileinfo
, $infoline);
536 opendir(DIR
, $sourcedir);
537 @sourcefiles = readdir(DIR
);
542 foreach $onefile (@sourcefiles)
544 if ((!($onefile eq ".")) && (!($onefile eq "..")))
546 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
547 my $dest = $destdir . $installer::globals
::separator
. $onefile;
548 if ( -f
$source ) # only files, no directories
550 my $localsource = $source;
551 if ( $depth > 0 ) { for ( my $i = 1; $i <= $depth; $i++ ) { $localsource = "../" . $localsource; } }
552 softlink_one_file
($localsource, $dest);
554 if ( -d
$source ) # recursive
556 my $newdepth = $depth + 1;
557 softlink_complete_directory
($source, $dest, $newdepth);
563 #####################################################
564 # Copying a complete directory with sub directories.
565 #####################################################
567 sub copy_complete_directory
569 my ($sourcedir, $destdir) = @_;
571 my @sourcefiles = ();
573 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
574 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
576 if ( ! -d
$destdir ) { create_directory
($destdir); }
579 push(@installer::globals
::logfileinfo
, $infoline);
580 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
581 push(@installer::globals
::logfileinfo
, $infoline);
583 opendir(DIR
, $sourcedir);
584 @sourcefiles = readdir(DIR
);
589 foreach $onefile (@sourcefiles)
591 if ((!($onefile eq ".")) && (!($onefile eq "..")))
593 my $source = $sourcedir . $installer::globals
::separator
. $onefile;
594 my $dest = $destdir . $installer::globals
::separator
. $onefile;
595 if ( -f
$source ) # only files, no directories
597 copy_one_file
($source, $dest);
599 if ( -d
$source ) # recursive
601 if ((!( $source =~ /packages\/SUNW
/ )) && (!( $source =~ /packages\
/OOO/ ))) # do not copy complete Solaris packages!
603 copy_complete_directory
($source, $dest);
610 #####################################################
611 # Copying all files with a specified file extension
612 # from one directory to another directory.
613 #####################################################
615 sub copy_directory_with_fileextension
617 my ($sourcedir, $destdir, $extension) = @_;
619 my @sourcefiles = ();
621 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//;
622 $destdir =~ s/\Q$installer::globals::separator\E\s*$//;
625 push(@installer::globals
::logfileinfo
, $infoline);
626 $infoline = "Copying files with extension $extension from directory $sourcedir to directory $destdir\n";
627 push(@installer::globals
::logfileinfo
, $infoline);
629 opendir(DIR
, $sourcedir);
630 @sourcefiles = readdir(DIR
);
635 foreach $onefile (@sourcefiles)
637 if ((!($onefile eq ".")) && (!($onefile eq "..")))
639 if ( $onefile =~ /\.$extension\s*$/ ) # only copying specified files
641 my $sourcefile = $sourcedir . $installer::globals
::separator
. $onefile;
642 my $destfile = $destdir . $installer::globals
::separator
. $onefile;
643 if ( -f
$sourcefile ) # only files, no directories
645 copy_one_file
($sourcefile, $destfile);
652 ########################################################
653 # Renaming all files with a specified file extension
654 # in a specified directory.
655 # Example: "Feature.idt.01" -> "Feature.idt"
656 ########################################################
658 sub rename_files_with_fileextension
660 my ($dir, $extension) = @_;
662 my @sourcefiles = ();
664 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
667 push(@installer::globals
::logfileinfo
, $infoline);
668 $infoline = "Renaming files with extension \"$extension\" in the directory $dir\n";
669 push(@installer::globals
::logfileinfo
, $infoline);
672 @sourcefiles = readdir(DIR
);
677 foreach $onefile (@sourcefiles)
679 if ((!($onefile eq ".")) && (!($onefile eq "..")))
681 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ ) # only renaming specified files
684 my $sourcefile = $dir . $installer::globals
::separator
. $onefile;
685 $destfile = $dir . $installer::globals
::separator
. $destfile;
686 if ( -f
$sourcefile ) # only files, no directories
688 rename_one_file
($sourcefile, $destfile);
695 ########################################################
696 # Finding all files with a specified file extension
697 # in a specified directory.
698 ########################################################
700 sub find_file_with_file_extension
702 my ($extension, $dir) = @_;
706 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
709 push(@installer::globals
::logfileinfo
, $infoline);
710 $infoline = "Searching files with extension \"$extension\" in the directory $dir\n";
711 push(@installer::globals
::logfileinfo
, $infoline);
714 my @sourcefiles = sort readdir(DIR
);
719 foreach $onefile (@sourcefiles)
721 if ((!($onefile eq ".")) && (!($onefile eq "..")))
723 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ )
725 push(@allfiles, $onefile)
733 ##############################################################
734 # Creating a unique directory, for example "01_inprogress_7"
735 # in the install directory.
736 ##############################################################
738 sub make_numbered_dir
740 my ($newstring, $olddir) = @_;
742 my $basedir = $olddir;
743 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$basedir);
745 my $alldirs = get_all_directories
($basedir);
747 # searching for the highest number extension
751 for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
753 if ( ${$alldirs}[$i] =~ /\_(\d+)\s*$/ )
756 if ( $number > $maxnumber ) { $maxnumber = $number; }
760 my $newnumber = $maxnumber + 1;
762 my $newdir = $olddir . "_" . $newstring . "_" . $newnumber;
766 if ( move
($olddir, $newdir) )
768 my $infoline = "\nMoved directory from $olddir to $newdir\n";
769 push(@installer::globals
::logfileinfo
, $infoline);
770 $returndir = $newdir;
774 my $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"make_numbered_dir\"\n";
775 push(@installer::globals
::logfileinfo
, $infoline);
776 $returndir = $olddir;
782 #####################################################################################
783 # Renaming a directory by exchanging a string, for example from "01_inprogress_7"
784 # to "01_witherror_7".
785 #####################################################################################
787 sub rename_string_in_directory
789 my ($olddir, $oldstring, $newstring) = @_;
791 my $newdir = $olddir;
794 $newdir =~ s/$oldstring/$newstring/g;
796 if (( -d
$newdir ) && ( $olddir ne $newdir )) { remove_complete_directory
($newdir, 1); }
798 if ( move
($olddir, $newdir) )
800 $infoline = "\nMoved directory from $olddir to $newdir\n";
801 push(@installer::globals
::logfileinfo
, $infoline);
805 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_string_in_directory\"\n";
806 push(@installer::globals
::logfileinfo
, $infoline);
812 ######################################################
813 # Returning the complete directory name,
814 # input is the first part of the directory name.
815 ######################################################
817 sub get_directoryname
819 my ($searchdir, $startstring) = @_;
825 opendir(DIR
, $searchdir);
827 foreach $direntry (readdir (DIR
))
829 next if $direntry eq ".";
830 next if $direntry eq "..";
832 if (( -d
$direntry ) && ( $direntry =~ /^\s*\Q$startstring\E/ ))
834 $dirname = $direntry;
842 if ( ! $founddir ) { installer
::exiter
::exit_program
("ERROR: Did not find directory beginning with $startstring in directory $searchdir", "get_directoryname"); }
848 ###################################
849 # Renaming a directory
850 ###################################
854 my ($olddir, $newdir) = @_;
858 if ( move
($olddir, $newdir) )
860 $infoline = "\nMoved directory from $olddir to $newdir\n";
861 push(@installer::globals
::logfileinfo
, $infoline);
865 installer
::exiter
::exit_program
("ERROR: Could not move directory from $olddir to $newdir $!", "rename_directory");
871 ##############################################################
872 # Creating a directory next to an existing directory
873 ##############################################################
875 sub create_directory_next_to_directory
877 my ($topdir, $dirname) = @_;
879 my $basedir = $topdir;
880 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$basedir);
882 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
884 my $newdir = $basedir . $installer::globals
::separator
. $dirname;
886 create_directory
($newdir);
891 ##############################################################
892 # Collecting all directories inside a directory
893 ##############################################################
895 sub get_all_directories
902 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
904 opendir(DIR
, $basedir);
906 foreach $direntry (readdir (DIR
))
908 next if $direntry eq ".";
909 next if $direntry eq "..";
911 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
913 if ( -d
$completeentry ) { push(@alldirs, $completeentry); }
921 ##############################################################
922 # Collecting all directories inside a directory
923 # Returning without path
924 ##############################################################
926 sub get_all_directories_without_path
933 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
935 opendir(DIR
, $basedir);
937 foreach $direntry (readdir (DIR
))
939 next if $direntry eq ".";
940 next if $direntry eq "..";
942 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
944 if ( -d
$completeentry ) { push(@alldirs, $direntry); }
952 ##############################################################
953 # Collecting all files and directories inside one directory
954 ##############################################################
963 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
965 opendir(DIR
, $basedir);
967 foreach $direntry (readdir (DIR
))
969 next if $direntry eq ".";
970 next if $direntry eq "..";
972 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
974 if (( -f
$completeentry ) || ( -d
$completeentry )) { push(@allcontent, $completeentry); }
982 ##############################################################
983 # Finding the new content in a directory
984 ##############################################################
986 sub find_new_content_in_directory
988 my ( $basedir, $oldcontent ) = @_;
995 $basedir =~ s/\Q$installer::globals::separator\E\s*$//;
997 opendir(DIR
, $basedir);
999 foreach $direntry (readdir (DIR
))
1001 next if $direntry eq ".";
1002 next if $direntry eq "..";
1004 my $completeentry = $basedir . $installer::globals
::separator
. $direntry;
1006 if (( -f
$completeentry ) || ( -d
$completeentry ))
1008 push(@allcontent, $completeentry);
1009 if (! grep {$_ eq $completeentry} @
{$oldcontent})
1011 push(@newcontent, $completeentry);
1018 return (\
@newcontent, \
@allcontent);
1021 ##############################################################
1022 # Trying to create a directory, no error if this fails
1023 ##############################################################
1025 sub try_to_create_directory
1027 my ($directory) = @_;
1029 my $returnvalue = 1;
1030 my $created_directory = 0;
1032 if (!(-d
$directory))
1034 $returnvalue = mkdir($directory, 0775);
1038 $created_directory = 1;
1039 my $infoline = "\nCreated directory: $directory\n";
1040 push(@installer::globals
::logfileinfo
, $infoline);
1042 chmod 0775, $directory;
1046 $created_directory = 0;
1051 $created_directory = 1;
1054 return $created_directory;
1057 ##############################################################
1058 # Creating a complete directory structure
1059 ##############################################################
1061 sub create_directory_structure
1063 my ($directory) = @_;
1065 if ( ! try_to_create_directory
($directory) )
1067 my $parentdir = $directory;
1068 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$parentdir);
1070 my $infoline = "INFO: Did not create directory $directory\n";
1071 push(@installer::globals
::logfileinfo
, $infoline);
1072 $infoline = "Now trying to create parent directory $parentdir\n";
1073 push(@installer::globals
::logfileinfo
, $infoline);
1075 create_directory_structure
($parentdir); # recursive
1078 create_directory
($directory); # now it has to succeed
1081 ######################################################
1082 # Removing a complete directory with subdirectories
1083 ######################################################
1085 sub remove_complete_directory
1087 my ($directory, $start) = @_;
1092 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1094 if ( -d
$directory )
1099 push(@installer::globals
::logfileinfo
, $infoline);
1100 $infoline = "Removing directory $directory\n";
1101 push(@installer::globals
::logfileinfo
, $infoline);
1104 opendir(DIR
, $directory);
1105 @content = readdir(DIR
);
1110 foreach $oneitem (@content)
1112 if ((!($oneitem eq ".")) && (!($oneitem eq "..")))
1114 my $item = $directory . $installer::globals
::separator
. $oneitem;
1116 if ( -f
$item || -l
$item ) # deleting files or links
1121 if ( -d
$item ) # recursive
1123 remove_complete_directory
($item, 0);
1128 # try to remove empty directory
1130 my $returnvalue = rmdir $directory;
1132 if ( ! $returnvalue )
1134 $infoline = "Warning: Problem with removing empty dir $directory\n";
1135 push(@installer::globals
::logfileinfo
, $infoline);
1138 # try a little bit harder (sometimes there is a performance problem)
1139 if ( -d
$directory )
1141 for ( my $j = 1; $j <= 3; $j++ )
1143 if ( -d
$directory )
1146 push(@installer::globals
::logfileinfo
, $infoline);
1147 $infoline = "Warning (Try $j): Problems with removing directory $directory\n";
1148 push(@installer::globals
::logfileinfo
, $infoline);
1150 $returnvalue = rmdir $directory;
1154 $infoline = "Successfully removed empty dir $directory\n";
1155 push(@installer::globals
::logfileinfo
, $infoline);
1157 $infoline = "Warning: rmdir $directory failed.\n";
1158 push(@installer::globals
::logfileinfo
, $infoline);
1166 ######################################################
1167 # Creating a unique directory with pid extension
1168 ######################################################
1170 sub create_pid_directory
1172 my ($directory) = @_;
1174 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1175 my $pid = $$; # process id
1176 my $time = time(); # time
1178 $directory = $directory . "_" . $pid . $time;
1180 if ( ! -d
$directory ) { create_directory
($directory); }
1181 else { installer
::exiter
::exit_program
("ERROR: Directory $directory already exists!", "create_pid_directory"); }
1186 ##############################################################
1187 # Reading all files from a directory and its subdirectories
1188 ##############################################################
1190 sub read_complete_directory
1192 my ($directory, $pathstring, $filecollector) = @_;
1195 opendir(DIR
, $directory);
1196 @content = readdir(DIR
);
1201 foreach $onefile (@content)
1203 if ((!($onefile eq ".")) && (!($onefile eq "..")))
1205 my $completefilename = $directory . $installer::globals
::separator
. $onefile;
1207 if ( $pathstring ne "" ) { $sep = $installer::globals
::separator
; }
1209 if ( ! -d
$completefilename ) # only files, no directories
1211 my $content = $pathstring . $sep . $onefile;
1212 push(@
{$filecollector}, $content);
1214 else # recursive for directories
1216 my $newpathstring = $pathstring . $sep . $onefile;
1217 read_complete_directory
($completefilename, $newpathstring, $filecollector);
1223 ##############################################################
1224 # Reading all files from a directory and its subdirectories
1226 ##############################################################
1228 sub read_full_directory
{
1229 my ( $currentdir, $pathstring, $collector ) = @_;
1234 unless (opendir(DH
, $currentdir))
1238 while (defined ($item = readdir(DH
)))
1240 next if($item eq "." or $item eq "..");
1241 $fullname = $currentdir . $installer::globals
::separator
. $item;
1243 if ( $pathstring ne "" ) { $sep = $installer::globals
::separator
; }
1247 my $newpathstring = $pathstring . $sep . $item;
1248 read_full_directory
($fullname, $newpathstring, $collector) if(-d
$fullname);
1252 my $content = $pathstring . $sep . $item;
1253 push(@
{$collector}, $content);
1260 ##############################################################
1261 # Removing all empty directories below a specified directory
1262 ##############################################################
1264 sub remove_empty_dirs_in_folder
1271 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
1276 @content = readdir(DIR
);
1281 foreach $oneitem (@content)
1283 if ((!($oneitem eq ".")) && (!($oneitem eq "..")))
1285 my $item = $dir . $installer::globals
::separator
. $oneitem;
1287 if ( -d
$item ) # recursive
1289 remove_empty_dirs_in_folder
($item);
1294 # try to remove empty directory
1295 my $returnvalue = rmdir $dir;
1299 $infoline = "Successfully removed empty dir $dir\n";
1300 push(@installer::globals
::logfileinfo
, $infoline);
1307 ######################################################
1309 ######################################################
1313 my ($systemcall) = @_;
1315 my $returnvalue = system($systemcall);
1317 my $infoline = "Systemcall: $systemcall\n";
1318 push( @installer::globals
::logfileinfo
, $infoline);
1322 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
1323 push( @installer::globals
::logfileinfo
, $infoline);
1327 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
1328 push( @installer::globals
::logfileinfo
, $infoline);