Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / installer / systemactions.pm
blob0c17b48436e75ed9158b84948266dd35b0a7712c
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;
21 use Cwd;
22 use File::Copy;
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 ######################################################
33 sub create_directory
35 my ($directory) = @_;
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) = @_;
48 my $returnvalue = 1;
49 my $infoline = "";
50 my $localprivileges = oct("0".$privileges); # changes "777" to 0777
52 if (!(-d $directory))
54 $returnvalue = mkdir($directory, $localprivileges);
56 if ($returnvalue)
58 $infoline = "\nCreated directory: $directory\n";
59 push(@installer::globals::logfileinfo, $infoline);
61 chmod $localprivileges, $directory;
63 else
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
67 # exist now.
69 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n";
70 push(@installer::globals::logfileinfo, $infoline);
72 if (!(-d $directory))
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);
78 if (!(-d $parentdir))
80 $returnvalue = mkdir($directory, $localprivileges);
82 if ($returnvalue)
84 $infoline = "\nAttention: Successfully created parent directory (should already be created before): $parentdir\n";
85 push(@installer::globals::logfileinfo, $infoline);
87 chmod $localprivileges, $parentdir;
89 else
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);
93 if ( -d $parentdir )
95 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n";
96 push(@installer::globals::logfileinfo, $infoline);
98 else
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);
111 if ($returnvalue)
113 $infoline = "\nAttention: Created directory \"$directory\" in the second try.\n";
114 push(@installer::globals::logfileinfo, $infoline);
116 chmod $localprivileges, $directory;
118 else
120 if ( -d $directory )
122 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n";
123 push(@installer::globals::logfileinfo, $infoline);
125 else
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");
132 else
134 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
135 push(@installer::globals::logfileinfo, $infoline);
139 else
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) = @_;
156 my $number = 1;
158 my $workstring = $languagestring;
160 while ( $workstring =~ /^\s*(.*)_(.*?)\s*$/ )
162 $workstring = $1;
163 $number++;
166 return $number;
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
179 my $path = "";
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;
188 else
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
206 else
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);
245 else
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);
270 return $path;
273 ########################
274 # Copying one file
275 ########################
277 sub copy_one_file
279 my ($source, $dest) = @_;
281 my ($returnvalue, $infoline, $copyreturn);
283 if ( -l $source ) {
284 $copyreturn = symlink(readlink("$source"), "$dest");
286 else {
287 $copyreturn = copy($source, $dest);
290 if ($copyreturn)
292 $infoline = "Copy: $source to $dest\n";
293 $returnvalue = 1;
295 else
297 $infoline = "ERROR: Could not copy $source to $dest $!\n";
298 $returnvalue = 0;
301 push(@installer::globals::logfileinfo, $infoline);
303 if ( !$returnvalue ) {
304 return $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);
312 if ($chmodreturn)
314 $infoline = "chmod $mode_str, $dest\n";
315 $returnvalue = 1;
317 else
319 $infoline = "WARNING: Could not chmod $dest: $!\n";
320 $returnvalue = 0;
323 push(@installer::globals::logfileinfo, $infoline);
326 return $returnvalue;
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);
341 if ($copyreturn)
343 $infoline = "Link: $source to $dest\n";
344 $returnvalue = 1;
346 else
348 $infoline = "ERROR: Could not link $source to $dest\n";
349 $returnvalue = 0;
352 push(@installer::globals::logfileinfo, $infoline);
354 return $returnvalue;
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);
369 if ($linkreturn)
371 $infoline = "Symlink: $source to $dest\n";
372 $returnvalue = 1;
374 else
376 $infoline = "ERROR: Could not symlink $source to $dest\n";
377 $returnvalue = 0;
380 push(@installer::globals::logfileinfo, $infoline);
382 return $returnvalue;
385 ########################
386 # Renaming one file
387 ########################
389 sub rename_one_file
391 my ($source, $dest) = @_;
393 my ($returnvalue, $infoline);
395 my $renamereturn = rename($source, $dest);
397 if ($renamereturn)
399 $infoline = "Rename: $source to $dest\n";
400 $returnvalue = 1;
402 else
404 $infoline = "ERROR: Could not rename $source to $dest\n";
405 $returnvalue = 0;
408 push(@installer::globals::logfileinfo, $infoline);
410 return $returnvalue;
413 ##########################################
414 # Copying all files from one directory
415 # to another directory
416 ##########################################
418 sub copy_directory
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*$//;
427 my $infoline = "\n";
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);
434 closedir(DIR);
436 my $onefile;
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 ##########################################
457 sub is_empty_dir
459 my ($dir) = @_;
461 my $directory_is_empty = 1;
462 my @sourcefiles = ();
464 opendir(DIR, $dir);
465 @sourcefiles = readdir(DIR);
466 closedir(DIR);
468 my $onefile;
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); }
499 my $infoline = "\n";
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);
506 closedir(DIR);
508 my $onefile;
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); }
543 my $infoline = "\n";
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);
550 closedir(DIR);
552 my $onefile;
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); }
590 my $infoline = "\n";
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);
597 closedir(DIR);
599 my $onefile;
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*$//;
636 $infoline = "\n";
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);
643 closedir(DIR);
645 my $onefile;
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*$//;
678 my $infoline = "\n";
679 push(@installer::globals::logfileinfo, $infoline);
680 $infoline = "Renaming files with extension \"$extension\" in the directory $dir\n";
681 push(@installer::globals::logfileinfo, $infoline);
683 opendir(DIR, $dir);
684 @sourcefiles = readdir(DIR);
685 closedir(DIR);
687 my $onefile;
689 foreach $onefile (@sourcefiles)
691 if ((!($onefile eq ".")) && (!($onefile eq "..")))
693 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ ) # only renaming specified files
695 my $destfile = $1;
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) = @_;
716 my @allfiles = ();
718 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
720 my $infoline = "\n";
721 push(@installer::globals::logfileinfo, $infoline);
722 $infoline = "Searching files with extension \"$extension\" in the directory $dir\n";
723 push(@installer::globals::logfileinfo, $infoline);
725 opendir(DIR, $dir);
726 @sourcefiles = sort readdir(DIR);
727 closedir(DIR);
729 my $onefile;
731 foreach $onefile (@sourcefiles)
733 if ((!($onefile eq ".")) && (!($onefile eq "..")))
735 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ )
737 push(@allfiles, $onefile)
742 return \@allfiles;
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
761 my $maxnumber = 0;
763 for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
765 if ( ${$alldirs}[$i] =~ /\_(\d+)\s*$/ )
767 my $number = $1;
768 if ( $number > $maxnumber ) { $maxnumber = $number; }
772 my $newnumber = $maxnumber + 1;
774 my $newdir = $olddir . "_" . $newstring . "_" . $newnumber;
776 my $returndir = "";
778 if ( move($olddir, $newdir) )
780 $infoline = "\nMoved directory from $olddir to $newdir\n";
781 push(@installer::globals::logfileinfo, $infoline);
782 $returndir = $newdir;
784 else
786 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"make_numbered_dir\"\n";
787 push(@installer::globals::logfileinfo, $infoline);
788 $returndir = $olddir;
791 return $returndir;
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;
804 my $infoline = "";
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);
815 else
817 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_string_in_directory\"\n";
818 push(@installer::globals::logfileinfo, $infoline);
821 return $newdir;
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) = @_;
833 my $dirname = "";
834 my $founddir = 0;
835 my $direntry;
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;
847 $founddir = 1;
848 last;
852 closedir(DIR);
854 if ( ! $founddir ) { installer::exiter::exit_program("ERROR: Did not find directory beginning with $startstring in directory $searchdir", "get_directoryname"); }
856 return $dirname;
860 ###################################
861 # Renaming a directory
862 ###################################
864 sub rename_directory
866 my ($olddir, $newdir) = @_;
868 my $infoline = "";
870 if ( move($olddir, $newdir) )
872 $infoline = "\nMoved directory from $olddir to $newdir\n";
873 push(@installer::globals::logfileinfo, $infoline);
875 else
877 installer::exiter::exit_program("ERROR: Could not move directory from $olddir to $newdir $!", "rename_directory");
880 return $newdir;
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);
900 return $newdir;
903 ##############################################################
904 # Collecting all directories inside a directory
905 ##############################################################
907 sub get_all_directories
909 my ($basedir) = @_;
911 my @alldirs = ();
912 my $direntry;
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); }
928 closedir(DIR);
930 return \@alldirs;
933 ##############################################################
934 # Collecting all directories inside a directory
935 # Returning without path
936 ##############################################################
938 sub get_all_directories_without_path
940 my ($basedir) = @_;
942 my @alldirs = ();
943 my $direntry;
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); }
959 closedir(DIR);
961 return \@alldirs;
964 ##############################################################
965 # Collecting all files and directories inside one directory
966 ##############################################################
968 sub read_directory
970 my ($basedir) = @_;
972 my @allcontent = ();
973 my $direntry;
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); }
989 closedir(DIR);
991 return \@allcontent;
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 = ();
1005 my $direntry;
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);
1028 closedir(DIR);
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);
1048 if ($returnvalue)
1050 $created_directory = 1;
1051 $infoline = "\nCreated directory: $directory\n";
1052 push(@installer::globals::logfileinfo, $infoline);
1054 chmod 0775, $directory;
1056 else
1058 $created_directory = 0;
1061 else
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) = @_;
1101 my @content = ();
1102 my $infoline = "";
1104 $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1106 if ( -d $directory )
1108 if ( $start )
1110 $infoline = "\n";
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);
1118 closedir(DIR);
1120 my $oneitem;
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
1130 unlink($item);
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 )
1157 $infoline = "\n";
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;
1164 if ( $returnvalue )
1166 $infoline = "Successfully removed empty dir $directory\n";
1167 push(@installer::globals::logfileinfo, $infoline);
1168 } else {
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"); }
1195 return $directory;
1198 ##############################################################
1199 # Reading all files from a directory and its subdirectories
1200 ##############################################################
1202 sub read_complete_directory
1204 my ($directory, $pathstring, $filecollector) = @_;
1206 my @content = ();
1207 opendir(DIR, $directory);
1208 @content = readdir(DIR);
1209 closedir(DIR);
1211 my $onefile;
1213 foreach $onefile (@content)
1215 if ((!($onefile eq ".")) && (!($onefile eq "..")))
1217 my $completefilename = $directory . $installer::globals::separator . $onefile;
1218 my $sep = "";
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
1237 # Version 2
1238 ##############################################################
1240 sub read_full_directory {
1241 my ( $currentdir, $pathstring, $collector ) = @_;
1242 my $item;
1243 my $fullname;
1244 local *DH;
1246 unless (opendir(DH, $currentdir))
1248 return;
1250 while (defined ($item = readdir(DH)))
1252 next if($item eq "." or $item eq "..");
1253 $fullname = $currentdir . $installer::globals::separator . $item;
1254 my $sep = "";
1255 if ( $pathstring ne "" ) { $sep = $installer::globals::separator; }
1257 if( -d $fullname)
1259 my $newpathstring = $pathstring . $sep . $item;
1260 read_full_directory($fullname, $newpathstring, $collector) if(-d $fullname);
1262 else
1264 my $content = $pathstring . $sep . $item;
1265 push(@{$collector}, $content);
1268 closedir(DH);
1269 return
1272 ##############################################################
1273 # Removing all empty directories below a specified directory
1274 ##############################################################
1276 sub remove_empty_dirs_in_folder
1278 my ( $dir ) = @_;
1280 my @content = ();
1281 my $infoline = "";
1283 $dir =~ s/\Q$installer::globals::separator\E\s*$//;
1285 if ( -d $dir )
1287 opendir(DIR, $dir);
1288 @content = readdir(DIR);
1289 closedir(DIR);
1291 my $oneitem;
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;
1309 if ( $returnvalue )
1311 $infoline = "Successfully removed empty dir $dir\n";
1312 push(@installer::globals::logfileinfo, $infoline);
1319 ######################################################
1320 # Making systemcall
1321 ######################################################
1323 sub make_systemcall
1325 my ($systemcall) = @_;
1327 my $returnvalue = system($systemcall);
1329 my $infoline = "Systemcall: $systemcall\n";
1330 push( @installer::globals::logfileinfo, $infoline);
1332 if ($returnvalue)
1334 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
1335 push( @installer::globals::logfileinfo, $infoline);
1337 else
1339 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
1340 push( @installer::globals::logfileinfo, $infoline);