1#************************************************************************* 2# 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# Copyright 2000, 2010 Oracle and/or its affiliates. 6# 7# OpenOffice.org - a multi-platform office productivity suite 8# 9# This file is part of OpenOffice.org. 10# 11# OpenOffice.org is free software: you can redistribute it and/or modify 12# it under the terms of the GNU Lesser General Public License version 3 13# only, as published by the Free Software Foundation. 14# 15# OpenOffice.org is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU Lesser General Public License version 3 for more details 19# (a copy is included in the LICENSE file that accompanied this code). 20# 21# You should have received a copy of the GNU Lesser General Public License 22# version 3 along with OpenOffice.org. If not, see 23# <http://www.openoffice.org/license.html> 24# for a copy of the LGPLv3 License. 25# 26#************************************************************************* 27 28package installer::systemactions; 29 30use Cwd; 31use File::Copy; 32use installer::converter; 33use installer::exiter; 34use installer::globals; 35use installer::pathanalyzer; 36use installer::remover; 37 38###################################################### 39# Creating a new direcotory 40###################################################### 41 42sub create_directory 43{ 44 my ($directory) = @_; 45 46 my $returnvalue = 1; 47 my $infoline = ""; 48 49 if (!(-d $directory)) 50 { 51 $returnvalue = mkdir($directory, 0775); 52 53 if ($returnvalue) 54 { 55 $infoline = "\nCreated directory: $directory\n"; 56 push(@installer::globals::logfileinfo, $infoline); 57 58 my $localcall = "chmod 0775 $directory \>\/dev\/null 2\>\&1"; 59 system($localcall); 60 61 # chmod 0775 is not sufficient on mac to remove sticky tag 62 $localcall = "chmod a-s $directory \>\/dev\/null 2\>\&1"; 63 system($localcall); 64 } 65 else 66 { 67 # New solution in parallel packing: It is possible, that the directory now exists, although it 68 # was not created in this process. There is only an important error, if the directory does not 69 # exist now. 70 71 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n"; 72 push(@installer::globals::logfileinfo, $infoline); 73 74 if (!(-d $directory)) 75 { 76 # Problem with parallel packaging? -> Try a little harder, before exiting. 77 # Did someone else remove the parent directory in the meantime? 78 my $parentdir = $directory; 79 installer::pathanalyzer::get_path_from_fullqualifiedname(\$parentdir); 80 if (!(-d $parentdir)) 81 { 82 $returnvalue = mkdir($parentdir, 0775); 83 84 if ($returnvalue) 85 { 86 $infoline = "\nAttention: Successfully created parent directory (should already be created before): $parentdir\n"; 87 push(@installer::globals::logfileinfo, $infoline); 88 89 my $localcall = "chmod 775 $parentdir \>\/dev\/null 2\>\&1"; 90 system($localcall); 91 } 92 else 93 { 94 $infoline = "\Error: \"$directory\" could not be created. Even the parent directory \"$parentdir\" does not exist and could not be created.\n"; 95 push(@installer::globals::logfileinfo, $infoline); 96 if ( -d $parentdir ) 97 { 98 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n"; 99 push(@installer::globals::logfileinfo, $infoline); 100 } 101 else 102 { 103 # Now it is time to exit, even the parent could not be created. 104 installer::exiter::exit_program("ERROR: Could not create parent directory \"$parentdir\"", "create_directory"); 105 } 106 } 107 } 108 109 # At this point we have to assume, that the parent directory exist. 110 # Trying once more to create the desired directory 111 112 $returnvalue = mkdir($directory, 0775); 113 114 if ($returnvalue) 115 { 116 $infoline = "\nAttention: Created directory \"$directory\" in the second try.\n"; 117 push(@installer::globals::logfileinfo, $infoline); 118 119 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1"; 120 system($localcall); 121 } 122 else 123 { 124 if ( -d $directory ) 125 { 126 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n"; 127 push(@installer::globals::logfileinfo, $infoline); 128 } 129 else 130 { 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"); 133 } 134 } 135 } 136 else 137 { 138 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n"; 139 push(@installer::globals::logfileinfo, $infoline); 140 } 141 } 142 } 143 else 144 { 145 $infoline = "\nAlready existing directory, did not create: $directory\n"; 146 push(@installer::globals::logfileinfo, $infoline); 147 } 148} 149 150###################################################### 151# Creating a new direcotory with defined privileges 152###################################################### 153 154sub create_directory_with_privileges 155{ 156 my ($directory, $privileges) = @_; 157 158 my $returnvalue = 1; 159 my $infoline = ""; 160 161 if (!(-d $directory)) 162 { 163 my $localprivileges = oct("0".$privileges); # changes "777" to 0777 164 $returnvalue = mkdir($directory, $localprivileges); 165 166 if ($returnvalue) 167 { 168 $infoline = "\nCreated directory: $directory\n"; 169 push(@installer::globals::logfileinfo, $infoline); 170 171 my $localcall = "chmod $privileges $directory \>\/dev\/null 2\>\&1"; 172 system($localcall); 173 } 174 else 175 { 176 # New solution in parallel packing: It is possible, that the directory now exists, although it 177 # was not created in this process. There is only an important error, if the directory does not 178 # exist now. 179 180 $infoline = "\nDid not succeed in creating directory: \"$directory\". Further attempts will follow.\n"; 181 push(@installer::globals::logfileinfo, $infoline); 182 183 if (!(-d $directory)) 184 { 185 # Problem with parallel packaging? -> Try a little harder, before exiting. 186 # Did someone else remove the parent directory in the meantime? 187 my $parentdir = $directory; 188 installer::pathanalyzer::get_path_from_fullqualifiedname(\$parentdir); 189 if (!(-d $parentdir)) 190 { 191 $returnvalue = mkdir($directory, $localprivileges); 192 193 if ($returnvalue) 194 { 195 $infoline = "\nAttention: Successfully created parent directory (should already be created before): $parentdir\n"; 196 push(@installer::globals::logfileinfo, $infoline); 197 198 my $localcall = "chmod $privileges $parentdir \>\/dev\/null 2\>\&1"; 199 system($localcall); 200 } 201 else 202 { 203 $infoline = "\Error: \"$directory\" could not be created. Even the parent directory \"$parentdir\" does not exist and could not be created.\n"; 204 push(@installer::globals::logfileinfo, $infoline); 205 if ( -d $parentdir ) 206 { 207 $infoline = "\nAttention: Finally the parent directory \"$parentdir\" exists, but I could not create it.\n"; 208 push(@installer::globals::logfileinfo, $infoline); 209 } 210 else 211 { 212 # Now it is time to exit, even the parent could not be created. 213 installer::exiter::exit_program("ERROR: Could not create parent directory \"$parentdir\"", "create_directory_with_privileges"); 214 } 215 } 216 } 217 218 # At this point we have to assume, that the parent directory exist. 219 # Trying once more to create the desired directory 220 221 $returnvalue = mkdir($directory, $localprivileges); 222 223 if ($returnvalue) 224 { 225 $infoline = "\nAttention: Created directory \"$directory\" in the second try.\n"; 226 push(@installer::globals::logfileinfo, $infoline); 227 228 my $localcall = "chmod $privileges $directory \>\/dev\/null 2\>\&1"; 229 system($localcall); 230 } 231 else 232 { 233 if ( -d $directory ) 234 { 235 $infoline = "\nAttention: Finally the directory \"$directory\" exists, but I could not create it.\n"; 236 push(@installer::globals::logfileinfo, $infoline); 237 } 238 else 239 { 240 # It is time to exit, even the second try failed. 241 installer::exiter::exit_program("ERROR: Failed to create the directory: $directory", "create_directory_with_privileges"); 242 } 243 } 244 } 245 else 246 { 247 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n"; 248 push(@installer::globals::logfileinfo, $infoline); 249 } 250 } 251 } 252 else 253 { 254 $infoline = "\nAlready existing directory, did not create: $directory\n"; 255 push(@installer::globals::logfileinfo, $infoline); 256 257 my $localcall = "chmod $privileges $directory \>\/dev\/null 2\>\&1"; 258 system($localcall); 259 } 260} 261 262###################################################### 263# Removing a new direcotory 264###################################################### 265 266sub remove_empty_directory 267{ 268 my ($directory) = @_; 269 270 my $returnvalue = 1; 271 272 if (-d $directory) 273 { 274 my $systemcall = "rmdir $directory"; 275 276 $returnvalue = system($systemcall); 277 278 my $infoline = "Systemcall: $systemcall\n"; 279 push( @installer::globals::logfileinfo, $infoline); 280 281 if ($returnvalue) 282 { 283 $infoline = "ERROR: Could not remove \"$directory\"!\n"; 284 push( @installer::globals::logfileinfo, $infoline); 285 } 286 else 287 { 288 $infoline = "Success: Removed \"$directory\"!\n"; 289 push( @installer::globals::logfileinfo, $infoline); 290 } 291 } 292} 293 294####################################################################### 295# Calculating the number of languages in the string 296####################################################################### 297 298sub get_number_of_langs 299{ 300 my ($languagestring) = @_; 301 302 my $number = 1; 303 304 my $workstring = $languagestring; 305 306 while ( $workstring =~ /^\s*(.*)_(.*?)\s*$/ ) 307 { 308 $workstring = $1; 309 $number++; 310 } 311 312 return $number; 313} 314 315####################################################################### 316# Creating the directories, in which files are generated or unzipped 317####################################################################### 318 319sub create_directories 320{ 321 my ($newdirectory, $languagesref) =@_; 322 323 $installer::globals::unpackpath =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes 324 325 my $path = ""; 326 327 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 328 { 329 if ( $installer::globals::temppathdefined ) { $path = $installer::globals::temppath; } 330 else { $path = $installer::globals::unpackpath; } 331 $path =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes 332 $path = $path . $installer::globals::separator; 333 } 334 elsif ( ( $newdirectory eq "jds" ) ) 335 { 336 if ( $installer::globals::jdstemppathdefined ) { $path = $installer::globals::jdstemppath; } 337 else { $path = $installer::globals::unpackpath; } 338 $path =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes 339 $path = $path . $installer::globals::separator; 340 installer::systemactions::create_directory($path); 341 } 342 else 343 { 344 $path = $installer::globals::unpackpath . $installer::globals::separator; 345 346 # special handling, if LOCALINSTALLDIR is set 347 if (( $installer::globals::localinstalldirset ) && ( $newdirectory eq "install" )) 348 { 349 $installer::globals::localinstalldir =~ s/\Q$installer::globals::separator\E\s*$//; 350 $path = $installer::globals::localinstalldir . $installer::globals::separator; 351 } 352 } 353 354 $infoline = "create_directories: Using $path for $newdirectory !\n"; 355 push( @installer::globals::logfileinfo, $infoline); 356 357 if ($newdirectory eq "unzip" ) # special handling for common directory 358 { 359 $path = $path . ".." . $installer::globals::separator . "common" . $installer::globals::productextension . $installer::globals::separator; 360 create_directory($path); 361 362 $path = $path . $newdirectory . $installer::globals::separator; 363 create_directory($path); 364 } 365 else 366 { 367 my $localproductname = $installer::globals::product; 368 my $localproductsubdir = ""; 369 370 if ( $installer::globals::product =~ /^\s*(.+?)\_\_(.+?)\s*$/ ) 371 { 372 $localproductname = $1; 373 $localproductsubdir = $2; 374 } 375 376 if ( $installer::globals::languagepack ) { $path = $path . $localproductname . "_languagepack" . $installer::globals::separator; } 377 elsif ( $installer::globals::patch ) { $path = $path . $localproductname . "_patch" . $installer::globals::separator; } 378 else { $path = $path . $localproductname . $installer::globals::separator; } 379 380 create_directory($path); 381 382 if ( $localproductsubdir ) 383 { 384 $path = $path . $localproductsubdir . $installer::globals::separator; 385 create_directory($path); 386 } 387 388 $path = $path . $installer::globals::installertypedir . $installer::globals::separator; 389 create_directory($path); 390 391 $path = $path . $newdirectory . $installer::globals::separator; 392 create_directory($path); 393 394 my $locallanguagesref = ""; 395 396 if ( $$languagesref ) { $locallanguagesref = $$languagesref; } 397 398 if (!($locallanguagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files 399 { 400 my $languagestring = $$languagesref; 401 402 if (length($languagestring) > $installer::globals::max_lang_length ) 403 { 404 my $number_of_languages = get_number_of_langs($languagestring); 405 chomp(my $shorter = `echo $languagestring | md5sum | sed -e "s/ .*//g"`); 406 # $languagestring = $shorter; 407 my $id = substr($shorter, 0, 8); # taking only the first 8 digits 408 $languagestring = "lang_" . $number_of_languages . "_id_" . $id; 409 } 410 411 $path = $path . $languagestring . $installer::globals::separator; 412 create_directory($path); 413 } 414 } 415 416 installer::remover::remove_ending_pathseparator(\$path); 417 418 $path = installer::converter::make_path_conform($path); 419 420 return $path; 421} 422 423######################## 424# Copying one file 425######################## 426 427sub copy_one_file 428{ 429 my ($source, $dest) = @_; 430 431 my ($returnvalue, $infoline); 432 433 my $copyreturn = copy($source, $dest); 434 435 if ($copyreturn) 436 { 437 $infoline = "Copy: $source to $dest\n"; 438 $returnvalue = 1; 439 } 440 else 441 { 442 $infoline = "ERROR: Could not copy $source to $dest\n"; 443 $returnvalue = 0; 444 } 445 446 push(@installer::globals::logfileinfo, $infoline); 447 448 if ( !$returnvalue ) { 449 return $returnvalue; 450 } 451 452 # taking care of file attributes 453 if ($installer::globals::iswin && -f $dest) { 454 my $mode = -x $source ? 0775 : 0664; 455 my $mode_str = sprintf("%o", $mode); 456 my $chmodreturn = chmod($mode, $dest); 457 if ($chmodreturn) 458 { 459 $infoline = "chmod $mode_str, $dest\n"; 460 $returnvalue = 1; 461 } 462 else 463 { 464 $infoline = "WARNING: Could not chmod $dest: $!\n"; 465 $returnvalue = 0; 466 } 467 468 push(@installer::globals::logfileinfo, $infoline); 469 } 470 471 return $returnvalue; 472} 473 474########################## 475# Hard linking one file 476########################## 477 478sub hardlink_one_file 479{ 480 my ($source, $dest) = @_; 481 482 my ($returnvalue, $infoline); 483 484 my $copyreturn = link($source, $dest); 485 486 if ($copyreturn) 487 { 488 $infoline = "Link: $source to $dest\n"; 489 $returnvalue = 1; 490 } 491 else 492 { 493 $infoline = "ERROR: Could not link $source to $dest\n"; 494 $returnvalue = 0; 495 } 496 497 push(@installer::globals::logfileinfo, $infoline); 498 499 return $returnvalue; 500} 501 502########################## 503# Soft linking one file 504########################## 505 506sub softlink_one_file 507{ 508 my ($source, $dest) = @_; 509 510 my ($returnvalue, $infoline); 511 512 my $linkreturn = symlink($source, $dest); 513 514 if ($linkreturn) 515 { 516 $infoline = "Symlink: $source to $dest\n"; 517 $returnvalue = 1; 518 } 519 else 520 { 521 $infoline = "ERROR: Could not symlink $source to $dest\n"; 522 $returnvalue = 0; 523 } 524 525 push(@installer::globals::logfileinfo, $infoline); 526 527 return $returnvalue; 528} 529 530######################## 531# Renaming one file 532######################## 533 534sub rename_one_file 535{ 536 my ($source, $dest) = @_; 537 538 my ($returnvalue, $infoline); 539 540 my $renamereturn = rename($source, $dest); 541 542 if ($renamereturn) 543 { 544 $infoline = "Rename: $source to $dest\n"; 545 $returnvalue = 1; 546 } 547 else 548 { 549 $infoline = "ERROR: Could not rename $source to $dest\n"; 550 $returnvalue = 0; 551 } 552 553 push(@installer::globals::logfileinfo, $infoline); 554 555 return $returnvalue; 556} 557 558########################################## 559# Copying all files from one directory 560# to another directory 561########################################## 562 563sub copy_directory 564{ 565 my ($sourcedir, $destdir) = @_; 566 567 my @sourcefiles = (); 568 569 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//; 570 $destdir =~ s/\Q$installer::globals::separator\E\s*$//; 571 572 my $infoline = "\n"; 573 push(@installer::globals::logfileinfo, $infoline); 574 $infoline = "Copying files from directory $sourcedir to directory $destdir\n"; 575 push(@installer::globals::logfileinfo, $infoline); 576 577 opendir(DIR, $sourcedir); 578 @sourcefiles = readdir(DIR); 579 closedir(DIR); 580 581 my $onefile; 582 583 foreach $onefile (@sourcefiles) 584 { 585 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 586 { 587 my $sourcefile = $sourcedir . $installer::globals::separator . $onefile; 588 my $destfile = $destdir . $installer::globals::separator . $onefile; 589 if ( -f $sourcefile ) # only files, no directories 590 { 591 copy_one_file($sourcefile, $destfile); 592 } 593 } 594 } 595} 596 597########################################## 598# Copying all files from one directory 599# to another directory 600########################################## 601 602sub is_empty_dir 603{ 604 my ($dir) = @_; 605 606 my $directory_is_empty = 1; 607 my @sourcefiles = (); 608 609 opendir(DIR, $dir); 610 @sourcefiles = readdir(DIR); 611 closedir(DIR); 612 613 my $onefile; 614 my @realcontent = (); 615 616 foreach $onefile (@sourcefiles) 617 { 618 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 619 { 620 push(@realcontent, $onefile); 621 } 622 } 623 624 if ( $#realcontent > -1 ) { $directory_is_empty = 0; } 625 626 return $directory_is_empty; 627} 628 629##################################################################### 630# Creating hard links to a complete directory with sub directories. 631##################################################################### 632 633sub hardlink_complete_directory 634{ 635 my ($sourcedir, $destdir) = @_; 636 637 my @sourcefiles = (); 638 639 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//; 640 $destdir =~ s/\Q$installer::globals::separator\E\s*$//; 641 642 if ( ! -d $destdir ) { create_directory($destdir); } 643 644 my $infoline = "\n"; 645 push(@installer::globals::logfileinfo, $infoline); 646 $infoline = "Creating hard links for all files from directory $sourcedir to directory $destdir\n"; 647 push(@installer::globals::logfileinfo, $infoline); 648 649 opendir(DIR, $sourcedir); 650 @sourcefiles = readdir(DIR); 651 closedir(DIR); 652 653 my $onefile; 654 655 foreach $onefile (@sourcefiles) 656 { 657 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 658 { 659 my $source = $sourcedir . $installer::globals::separator . $onefile; 660 my $dest = $destdir . $installer::globals::separator . $onefile; 661 if ( -f $source ) # only files, no directories 662 { 663 hardlink_one_file($source, $dest); 664 } 665 if ( -d $source ) # recursive 666 { 667 hardlink_complete_directory($source, $dest); 668 } 669 } 670 } 671} 672 673##################################################################### 674# Creating hard links to a complete directory with sub directories. 675##################################################################### 676 677sub softlink_complete_directory 678{ 679 my ($sourcedir, $destdir, $depth) = @_; 680 681 my @sourcefiles = (); 682 683 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//; 684 $destdir =~ s/\Q$installer::globals::separator\E\s*$//; 685 686 if ( ! -d $destdir ) { create_directory($destdir); } 687 688 my $infoline = "\n"; 689 push(@installer::globals::logfileinfo, $infoline); 690 $infoline = "Creating soft links for all files from directory $sourcedir to directory $destdir\n"; 691 push(@installer::globals::logfileinfo, $infoline); 692 693 opendir(DIR, $sourcedir); 694 @sourcefiles = readdir(DIR); 695 closedir(DIR); 696 697 my $onefile; 698 699 foreach $onefile (@sourcefiles) 700 { 701 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 702 { 703 my $source = $sourcedir . $installer::globals::separator . $onefile; 704 my $dest = $destdir . $installer::globals::separator . $onefile; 705 if ( -f $source ) # only files, no directories 706 { 707 my $localsource = $source; 708 if ( $depth > 0 ) { for ( my $i = 1; $i <= $depth; $i++ ) { $localsource = "../" . $localsource; } } 709 softlink_one_file($localsource, $dest); 710 } 711 if ( -d $source ) # recursive 712 { 713 my $newdepth = $depth + 1; 714 softlink_complete_directory($source, $dest, $newdepth); 715 } 716 } 717 } 718} 719 720##################################################### 721# Copying a complete directory with sub directories. 722##################################################### 723 724sub copy_complete_directory 725{ 726 my ($sourcedir, $destdir) = @_; 727 728 my @sourcefiles = (); 729 730 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//; 731 $destdir =~ s/\Q$installer::globals::separator\E\s*$//; 732 733 if ( ! -d $destdir ) { create_directory($destdir); } 734 735 my $infoline = "\n"; 736 push(@installer::globals::logfileinfo, $infoline); 737 $infoline = "Copying files from directory $sourcedir to directory $destdir\n"; 738 push(@installer::globals::logfileinfo, $infoline); 739 740 opendir(DIR, $sourcedir); 741 @sourcefiles = readdir(DIR); 742 closedir(DIR); 743 744 my $onefile; 745 746 foreach $onefile (@sourcefiles) 747 { 748 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 749 { 750 my $source = $sourcedir . $installer::globals::separator . $onefile; 751 my $dest = $destdir . $installer::globals::separator . $onefile; 752 if ( -f $source ) # only files, no directories 753 { 754 copy_one_file($source, $dest); 755 } 756 if ( -d $source ) # recursive 757 { 758 if ((!( $source =~ /packages\/SUNW/ )) && (!( $source =~ /packages\/OOO/ ))) # do not copy complete Solaris packages! 759 { 760 copy_complete_directory($source, $dest); 761 } 762 } 763 } 764 } 765} 766 767##################################################################################### 768# Copying a complete directory with sub directories, but not the CVS directories. 769##################################################################################### 770 771sub copy_complete_directory_without_cvs 772{ 773 my ($sourcedir, $destdir) = @_; 774 775 my @sourcefiles = (); 776 777 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//; 778 $destdir =~ s/\Q$installer::globals::separator\E\s*$//; 779 780 if ( ! -d $destdir ) { create_directory($destdir); } 781 782 my $infoline = "\n"; 783 push(@installer::globals::logfileinfo, $infoline); 784 $infoline = "Copying files from directory $sourcedir to directory $destdir (without CVS)\n"; 785 push(@installer::globals::logfileinfo, $infoline); 786 787 opendir(DIR, $sourcedir); 788 @sourcefiles = readdir(DIR); 789 closedir(DIR); 790 791 my $onefile; 792 793 foreach $onefile (@sourcefiles) 794 { 795 if ((!($onefile eq ".")) && (!($onefile eq "..")) && (!($onefile eq "CVS"))) 796 { 797 my $source = $sourcedir . $installer::globals::separator . $onefile; 798 my $dest = $destdir . $installer::globals::separator . $onefile; 799 if ( -f $source ) # only files, no directories 800 { 801 copy_one_file($source, $dest); 802 } 803 if ( -d $source ) # recursive 804 { 805 copy_complete_directory_without_cvs($source, $dest); 806 } 807 } 808 } 809} 810 811##################################################### 812# Copying all files with a specified file extension 813# from one directory to another directory. 814##################################################### 815 816sub copy_directory_with_fileextension 817{ 818 my ($sourcedir, $destdir, $extension) = @_; 819 820 my @sourcefiles = (); 821 822 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//; 823 $destdir =~ s/\Q$installer::globals::separator\E\s*$//; 824 825 $infoline = "\n"; 826 push(@installer::globals::logfileinfo, $infoline); 827 $infoline = "Copying files with extension $extension from directory $sourcedir to directory $destdir\n"; 828 push(@installer::globals::logfileinfo, $infoline); 829 830 opendir(DIR, $sourcedir); 831 @sourcefiles = readdir(DIR); 832 closedir(DIR); 833 834 my $onefile; 835 836 foreach $onefile (@sourcefiles) 837 { 838 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 839 { 840 if ( $onefile =~ /\.$extension\s*$/ ) # only copying specified files 841 { 842 my $sourcefile = $sourcedir . $installer::globals::separator . $onefile; 843 my $destfile = $destdir . $installer::globals::separator . $onefile; 844 if ( -f $sourcefile ) # only files, no directories 845 { 846 copy_one_file($sourcefile, $destfile); 847 } 848 } 849 } 850 } 851} 852 853######################################################### 854# Copying all files without a specified file extension 855# from one directory to another directory. 856######################################################### 857 858sub copy_directory_except_fileextension 859{ 860 my ($sourcedir, $destdir, $extension) = @_; 861 862 my @sourcefiles = (); 863 864 $sourcedir =~ s/\Q$installer::globals::separator\E\s*$//; 865 $destdir =~ s/\Q$installer::globals::separator\E\s*$//; 866 867 $infoline = "\n"; 868 push(@installer::globals::logfileinfo, $infoline); 869 $infoline = "Copying files without extension $extension from directory $sourcedir to directory $destdir\n"; 870 push(@installer::globals::logfileinfo, $infoline); 871 872 opendir(DIR, $sourcedir); 873 @sourcefiles = readdir(DIR); 874 closedir(DIR); 875 876 my $onefile; 877 878 foreach $onefile (@sourcefiles) 879 { 880 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 881 { 882 if ( ! ( $onefile =~ /\.$extension\s*$/ )) # only copying not having the specified extension 883 { 884 my $sourcefile = $sourcedir . $installer::globals::separator . $onefile; 885 my $destfile = $destdir . $installer::globals::separator . $onefile; 886 if ( -f $sourcefile ) # only files, no directories 887 { 888 copy_one_file($sourcefile, $destfile); 889 } 890 } 891 } 892 } 893} 894 895######################################################## 896# Renaming all files with a specified file extension 897# in a specified directory. 898# Example: "Feature.idt.01" -> "Feature.idt" 899######################################################## 900 901sub rename_files_with_fileextension 902{ 903 my ($dir, $extension) = @_; 904 905 my @sourcefiles = (); 906 907 $dir =~ s/\Q$installer::globals::separator\E\s*$//; 908 909 my $infoline = "\n"; 910 push(@installer::globals::logfileinfo, $infoline); 911 $infoline = "Renaming files with extension \"$extension\" in the directory $dir\n"; 912 push(@installer::globals::logfileinfo, $infoline); 913 914 opendir(DIR, $dir); 915 @sourcefiles = readdir(DIR); 916 closedir(DIR); 917 918 my $onefile; 919 920 foreach $onefile (@sourcefiles) 921 { 922 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 923 { 924 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ ) # only renaming specified files 925 { 926 my $destfile = $1; 927 my $sourcefile = $dir . $installer::globals::separator . $onefile; 928 $destfile = $dir . $installer::globals::separator . $destfile; 929 if ( -f $sourcefile ) # only files, no directories 930 { 931 rename_one_file($sourcefile, $destfile); 932 } 933 } 934 } 935 } 936} 937 938######################################################## 939# Finding all files with a specified file extension 940# in a specified directory. 941######################################################## 942 943sub find_file_with_file_extension 944{ 945 my ($extension, $dir) = @_; 946 947 my @allfiles = (); 948 949 $dir =~ s/\Q$installer::globals::separator\E\s*$//; 950 951 my $infoline = "\n"; 952 push(@installer::globals::logfileinfo, $infoline); 953 $infoline = "Searching files with extension \"$extension\" in the directory $dir\n"; 954 push(@installer::globals::logfileinfo, $infoline); 955 956 opendir(DIR, $dir); 957 @sourcefiles = sort readdir(DIR); 958 closedir(DIR); 959 960 my $onefile; 961 962 foreach $onefile (@sourcefiles) 963 { 964 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 965 { 966 if ( $onefile =~ /^\s*(\S.*?)\.$extension\s*$/ ) 967 { 968 push(@allfiles, $onefile) 969 } 970 } 971 } 972 973 return \@allfiles; 974} 975 976############################################################## 977# Creating a unique directory, for example "01_inprogress_7" 978# in the install directory. 979############################################################## 980 981sub make_numbered_dir 982{ 983 my ($newstring, $olddir) = @_; 984 985 my $basedir = $olddir; 986 installer::pathanalyzer::get_path_from_fullqualifiedname(\$basedir); 987 988 my $alldirs = get_all_directories($basedir); 989 990 # searching for the highest number extension 991 992 my $maxnumber = 0; 993 994 for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) 995 { 996 if ( ${$alldirs}[$i] =~ /\_(\d+)\s*$/ ) 997 { 998 my $number = $1; 999 if ( $number > $maxnumber ) { $maxnumber = $number; } 1000 } 1001 } 1002 1003 my $newnumber = $maxnumber + 1; 1004 1005 my $newdir = $olddir . "_" . $newstring . "_" . $newnumber; 1006 1007 my $returndir = ""; 1008 1009 if ( move($olddir, $newdir) ) 1010 { 1011 $infoline = "\nMoved directory from $olddir to $newdir\n"; 1012 push(@installer::globals::logfileinfo, $infoline); 1013 $returndir = $newdir; 1014 } 1015 else 1016 { 1017 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"make_numbered_dir\"\n"; 1018 push(@installer::globals::logfileinfo, $infoline); 1019 $returndir = $olddir; 1020 } 1021 1022 return $returndir; 1023} 1024 1025############################################################## 1026# Determining the highest number in the install directory. 1027############################################################## 1028 1029sub determine_maximum_number 1030{ 1031 my ($dir, $languagestringref) = @_; 1032 1033 my $basedir = $dir; 1034 installer::pathanalyzer::get_path_from_fullqualifiedname(\$basedir); 1035 1036 my $alldirs = get_all_directories($basedir); 1037 1038 my $maxnumber = 1; 1039 1040 # In control.pm the installation directory is determined as: 1041 # $installer::globals::build . "_" . $installer::globals::lastminor . "_" . 1042 # "native_inprogress-number_" . $$languagesref . "\." . $installer::globals::buildid; 1043 1044 # searching for the highest number extension after the first "-", which belongs to 1045 # $installer::globals::build, $installer::globals::lastminor and $installer::globals::buildid 1046 # In this step not looking for the language! 1047 1048 my @correctbuildiddirs = (); 1049 1050 for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) 1051 { 1052 my $onedir = ${$alldirs}[$i]; 1053 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$onedir); 1054 1055 if ( $onedir =~ /^\s*\Q$installer::globals::build\E\_\Q$installer::globals::lastminor\E\_(.*?)\-(\d+)\_(.*?)\.\Q$installer::globals::buildid\E\s*$/ ) 1056 { 1057 my $number = $2; 1058 if ( $number > $maxnumber ) { $maxnumber = $number; } 1059 push(@correctbuildiddirs, $onedir); 1060 } 1061 } 1062 1063 # From all directories with correct $installer::globals::build, $installer::globals::lastminor 1064 # and $installer::globals::buildid, those directories, which already have the maximum number 1065 # have to be selected 1066 1067 my @maximumnumberdirs = (); 1068 1069 for ( my $i = 0; $i <= $#correctbuildiddirs; $i++ ) 1070 { 1071 my $onedir = $correctbuildiddirs[$i]; 1072 1073 if ( $onedir =~ /^\s*(.*?)\-(\d+)\_(.*?)\.(.*?)\s*$/ ) 1074 { 1075 my $number = $2; 1076 1077 if ( $number == $maxnumber ) 1078 { 1079 push(@maximumnumberdirs, $onedir); 1080 } 1081 } 1082 } 1083 1084 # @maximumnumberdirs contains only those directories with correct $installer::globals::build, 1085 # $installer::globals::lastminor and $installer::globals::buildid, which already have the maximum number. 1086 # If the current language is part of this directory, the number has to be increased. 1087 1088 my $increase_counter = 0; 1089 1090 for ( my $i = 0; $i <= $#maximumnumberdirs; $i++ ) 1091 { 1092 my $onedir = $maximumnumberdirs[$i]; 1093 1094 if ( $onedir =~ /^\s*(.*?)\-(\d+)\_(.*?)\.(.*?)\s*$/ ) 1095 { 1096 my $number = $2; 1097 my $languagestring = $3; 1098 1099 if ( $languagestring eq $$languagestringref ) 1100 { 1101 $increase_counter = 1; 1102 } 1103 } 1104 } 1105 1106 if ( $increase_counter ) 1107 { 1108 $maxnumber = $maxnumber + 1; 1109 } 1110 1111 return $maxnumber; 1112} 1113 1114##################################################################################### 1115# Renaming a directory by exchanging a string, for example from "01_inprogress_7" 1116# to "01_witherror_7". 1117##################################################################################### 1118 1119sub rename_string_in_directory 1120{ 1121 my ($olddir, $oldstring, $newstring) = @_; 1122 1123 my $newdir = $olddir; 1124 my $infoline = ""; 1125 1126 $newdir =~ s/$oldstring/$newstring/g; 1127 1128 if (( -d $newdir ) && ( $olddir ne $newdir )) { remove_complete_directory($newdir, 1); } 1129 1130 if ( move($olddir, $newdir) ) 1131 { 1132 $infoline = "\nMoved directory from $olddir to $newdir\n"; 1133 push(@installer::globals::logfileinfo, $infoline); 1134 } 1135 else 1136 { 1137 $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_string_in_directory\"\n"; 1138 push(@installer::globals::logfileinfo, $infoline); 1139 } 1140 1141 return $newdir; 1142} 1143 1144###################################################### 1145# Returning the complete directory name, 1146# input is the first part of the directory name. 1147###################################################### 1148 1149sub get_directoryname 1150{ 1151 my ($searchdir, $startstring) = @_; 1152 1153 my $dirname = ""; 1154 my $founddir = 0; 1155 my $direntry; 1156 1157 opendir(DIR, $searchdir); 1158 1159 foreach $direntry (readdir (DIR)) 1160 { 1161 next if $direntry eq "."; 1162 next if $direntry eq ".."; 1163 1164 if (( -d $direntry ) && ( $direntry =~ /^\s*\Q$startstring\E/ )) 1165 { 1166 $dirname = $direntry; 1167 $founddir = 1; 1168 last; 1169 } 1170 } 1171 1172 closedir(DIR); 1173 1174 if ( ! $founddir ) { installer::exiter::exit_program("ERROR: Did not find directory beginning with $startstring in directory $searchdir", "get_directoryname"); } 1175 1176 return $dirname; 1177} 1178 1179 1180################################### 1181# Renaming a directory 1182################################### 1183 1184sub rename_directory 1185{ 1186 my ($olddir, $newdir) = @_; 1187 1188 my $infoline = ""; 1189 1190 if ( move($olddir, $newdir) ) 1191 { 1192 $infoline = "\nMoved directory from $olddir to $newdir\n"; 1193 push(@installer::globals::logfileinfo, $infoline); 1194 } 1195 else 1196 { 1197 installer::exiter::exit_program("ERROR: Could not move directory from $olddir to $newdir", "rename_directory"); 1198 # $infoline = "\nATTENTION: Could not move directory from $olddir to $newdir, \"rename_directory\"\n"; 1199 # push(@installer::globals::logfileinfo, $infoline); 1200 } 1201 1202 return $newdir; 1203} 1204 1205############################################################## 1206# Creating a directory next to an existing directory 1207############################################################## 1208 1209sub create_directory_next_to_directory 1210{ 1211 my ($topdir, $dirname) = @_; 1212 1213 my $basedir = $topdir; 1214 installer::pathanalyzer::get_path_from_fullqualifiedname(\$basedir); 1215 1216 $basedir =~ s/\Q$installer::globals::separator\E\s*$//; 1217 1218 my $newdir = $basedir . $installer::globals::separator . $dirname; 1219 1220 create_directory($newdir); 1221 1222 return $newdir; 1223} 1224 1225############################################################## 1226# Collecting all directories inside a directory 1227############################################################## 1228 1229sub get_all_directories 1230{ 1231 my ($basedir) = @_; 1232 1233 my @alldirs = (); 1234 my $direntry; 1235 1236 $basedir =~ s/\Q$installer::globals::separator\E\s*$//; 1237 1238 opendir(DIR, $basedir); 1239 1240 foreach $direntry (readdir (DIR)) 1241 { 1242 next if $direntry eq "."; 1243 next if $direntry eq ".."; 1244 1245 my $completeentry = $basedir . $installer::globals::separator . $direntry; 1246 1247 if ( -d $completeentry ) { push(@alldirs, $completeentry); } 1248 } 1249 1250 closedir(DIR); 1251 1252 return \@alldirs; 1253} 1254 1255############################################################## 1256# Collecting all directories inside a directory 1257# Returning without path 1258############################################################## 1259 1260sub get_all_directories_without_path 1261{ 1262 my ($basedir) = @_; 1263 1264 my @alldirs = (); 1265 my $direntry; 1266 1267 $basedir =~ s/\Q$installer::globals::separator\E\s*$//; 1268 1269 opendir(DIR, $basedir); 1270 1271 foreach $direntry (readdir (DIR)) 1272 { 1273 next if $direntry eq "."; 1274 next if $direntry eq ".."; 1275 1276 my $completeentry = $basedir . $installer::globals::separator . $direntry; 1277 1278 if ( -d $completeentry ) { push(@alldirs, $direntry); } 1279 } 1280 1281 closedir(DIR); 1282 1283 return \@alldirs; 1284} 1285 1286############################################################## 1287# Collecting all files inside one directory 1288############################################################## 1289 1290sub get_all_files_from_one_directory 1291{ 1292 my ($basedir) = @_; 1293 1294 my @allfiles = (); 1295 my $direntry; 1296 1297 $basedir =~ s/\Q$installer::globals::separator\E\s*$//; 1298 1299 opendir(DIR, $basedir); 1300 1301 foreach $direntry (readdir (DIR)) 1302 { 1303 next if $direntry eq "."; 1304 next if $direntry eq ".."; 1305 1306 my $completeentry = $basedir . $installer::globals::separator . $direntry; 1307 1308 if ( -f $completeentry ) { push(@allfiles, $completeentry); } 1309 } 1310 1311 closedir(DIR); 1312 1313 return \@allfiles; 1314} 1315 1316############################################################## 1317# Collecting all files inside one directory 1318############################################################## 1319 1320sub get_all_files_from_one_directory_without_path 1321{ 1322 my ($basedir) = @_; 1323 1324 my @allfiles = (); 1325 my $direntry; 1326 1327 $basedir =~ s/\Q$installer::globals::separator\E\s*$//; 1328 1329 opendir(DIR, $basedir); 1330 1331 foreach $direntry (readdir (DIR)) 1332 { 1333 next if $direntry eq "."; 1334 next if $direntry eq ".."; 1335 1336 my $completeentry = $basedir . $installer::globals::separator . $direntry; 1337 1338 if ( -f $completeentry ) { push(@allfiles, $direntry); } 1339 } 1340 1341 closedir(DIR); 1342 1343 return \@allfiles; 1344} 1345 1346############################################################## 1347# Collecting all files and directories inside one directory 1348############################################################## 1349 1350sub read_directory 1351{ 1352 my ($basedir) = @_; 1353 1354 my @allcontent = (); 1355 my $direntry; 1356 1357 $basedir =~ s/\Q$installer::globals::separator\E\s*$//; 1358 1359 opendir(DIR, $basedir); 1360 1361 foreach $direntry (readdir (DIR)) 1362 { 1363 next if $direntry eq "."; 1364 next if $direntry eq ".."; 1365 1366 my $completeentry = $basedir . $installer::globals::separator . $direntry; 1367 1368 if (( -f $completeentry ) || ( -d $completeentry )) { push(@allcontent, $completeentry); } 1369 } 1370 1371 closedir(DIR); 1372 1373 return \@allcontent; 1374} 1375 1376############################################################## 1377# Finding the new content in a directory 1378############################################################## 1379 1380sub find_new_content_in_directory 1381{ 1382 my ( $basedir, $oldcontent ) = @_; 1383 1384 my @newcontent = (); 1385 my @allcontent = (); 1386 1387 my $direntry; 1388 1389 $basedir =~ s/\Q$installer::globals::separator\E\s*$//; 1390 1391 opendir(DIR, $basedir); 1392 1393 foreach $direntry (readdir (DIR)) 1394 { 1395 next if $direntry eq "."; 1396 next if $direntry eq ".."; 1397 1398 my $completeentry = $basedir . $installer::globals::separator . $direntry; 1399 1400 if (( -f $completeentry ) || ( -d $completeentry )) 1401 { 1402 push(@allcontent, $completeentry); 1403 if (! installer::existence::exists_in_array($completeentry, $oldcontent)) 1404 { 1405 push(@newcontent, $completeentry); 1406 } 1407 } 1408 } 1409 1410 closedir(DIR); 1411 1412 return (\@newcontent, \@allcontent); 1413} 1414 1415############################################################## 1416# Trying to create a directory, no error if this fails 1417############################################################## 1418 1419sub try_to_create_directory 1420{ 1421 my ($directory) = @_; 1422 1423 my $returnvalue = 1; 1424 my $created_directory = 0; 1425 1426 if (!(-d $directory)) 1427 { 1428 $returnvalue = mkdir($directory, 0775); 1429 1430 if ($returnvalue) 1431 { 1432 $created_directory = 1; 1433 $infoline = "\nCreated directory: $directory\n"; 1434 push(@installer::globals::logfileinfo, $infoline); 1435 1436 my $localcall = "chmod 0775 $directory \>\/dev\/null 2\>\&1"; 1437 system($localcall); 1438 1439 # chmod 0775 is not sufficient on mac to remove sticky tag 1440 $localcall = "chmod a-s $directory \>\/dev\/null 2\>\&1"; 1441 system($localcall); 1442 } 1443 else 1444 { 1445 $created_directory = 0; 1446 } 1447 } 1448 else 1449 { 1450 $created_directory = 1; 1451 } 1452 1453 return $created_directory; 1454} 1455 1456############################################################## 1457# Creating a complete directory structure 1458############################################################## 1459 1460sub create_directory_structure 1461{ 1462 my ($directory) = @_; 1463 1464 if ( ! try_to_create_directory($directory) ) 1465 { 1466 my $parentdir = $directory; 1467 installer::pathanalyzer::get_path_from_fullqualifiedname(\$parentdir); 1468 1469 my $infoline = "INFO: Did not create directory $directory\n"; 1470 push(@installer::globals::logfileinfo, $infoline); 1471 $infoline = "Now trying to create parent directory $parentdir\n"; 1472 push(@installer::globals::logfileinfo, $infoline); 1473 1474 create_directory_structure($parentdir); # recursive 1475 } 1476 1477 create_directory($directory); # now it has to succeed 1478} 1479 1480###################################################### 1481# Removing a complete directory with subdirectories 1482###################################################### 1483 1484sub remove_complete_directory 1485{ 1486 my ($directory, $start) = @_; 1487 1488 my @content = (); 1489 my $infoline = ""; 1490 1491 $directory =~ s/\Q$installer::globals::separator\E\s*$//; 1492 1493 if ( -d $directory ) 1494 { 1495 if ( $start ) 1496 { 1497 $infoline = "\n"; 1498 push(@installer::globals::logfileinfo, $infoline); 1499 $infoline = "Removing directory $directory\n"; 1500 push(@installer::globals::logfileinfo, $infoline); 1501 } 1502 1503 opendir(DIR, $directory); 1504 @content = readdir(DIR); 1505 closedir(DIR); 1506 1507 my $oneitem; 1508 1509 foreach $oneitem (@content) 1510 { 1511 if ((!($oneitem eq ".")) && (!($oneitem eq ".."))) 1512 { 1513 my $item = $directory . $installer::globals::separator . $oneitem; 1514 1515 if ( -f $item || -l $item ) # deleting files or links 1516 { 1517 unlink($item); 1518 } 1519 1520 if ( -d $item ) # recursive 1521 { 1522 remove_complete_directory($item, 0); 1523 } 1524 } 1525 } 1526 1527 # try to remove empty directory 1528 1529 my $returnvalue = rmdir $directory; 1530 1531 if ( ! $returnvalue ) 1532 { 1533 $infoline = "Warning: Problem with removing empty dir $directory\n"; 1534 push(@installer::globals::logfileinfo, $infoline); 1535 } 1536 1537 # try a little bit harder (sometimes there is a performance problem) 1538 if ( -d $directory ) 1539 { 1540 for ( my $j = 1; $j <= 3; $j++ ) 1541 { 1542 if ( -d $directory ) 1543 { 1544 $infoline = "\n"; 1545 push(@installer::globals::logfileinfo, $infoline); 1546 $infoline = "Warning (Try $j): Problems with removing directory $directory\n"; 1547 push(@installer::globals::logfileinfo, $infoline); 1548 1549 $returnvalue = rmdir $directory; 1550 1551 if ( $returnvalue ) 1552 { 1553 $infoline = "Successfully removed empty dir $directory\n"; 1554 push(@installer::globals::logfileinfo, $infoline); 1555 } else { 1556 $infoline = "Warning: rmdir $directory failed.\n"; 1557 push(@installer::globals::logfileinfo, $infoline); 1558 } 1559 } 1560 } 1561 } 1562 } 1563} 1564 1565###################################################### 1566# Creating a unique directory with number extension 1567###################################################### 1568 1569sub create_unique_directory 1570{ 1571 my ($directory) = @_; 1572 1573 $directory =~ s/\Q$installer::globals::separator\E\s*$//; 1574 $directory = $directory . "_INCREASINGNUMBER"; 1575 1576 my $counter = 1; 1577 my $created = 0; 1578 my $localdirectory = ""; 1579 1580 do 1581 { 1582 $localdirectory = $directory; 1583 $localdirectory =~ s/INCREASINGNUMBER/$counter/; 1584 $counter++; 1585 1586 if ( ! -d $localdirectory ) 1587 { 1588 create_directory($localdirectory); 1589 $created = 1; 1590 } 1591 } 1592 while ( ! $created ); 1593 1594 return $localdirectory; 1595} 1596 1597###################################################### 1598# Creating a unique directory with pid extension 1599###################################################### 1600 1601sub create_pid_directory 1602{ 1603 my ($directory) = @_; 1604 1605 $directory =~ s/\Q$installer::globals::separator\E\s*$//; 1606 my $pid = $$; # process id 1607 my $time = time(); # time 1608 1609 $directory = $directory . "_" . $pid . $time; 1610 1611 if ( ! -d $directory ) { create_directory($directory); } 1612 else { installer::exiter::exit_program("ERROR: Directory $directory already exists!", "create_pid_directory"); } 1613 1614 return $directory; 1615} 1616 1617############################################################## 1618# Reading all files from a directory and its subdirectories 1619############################################################## 1620 1621sub read_complete_directory 1622{ 1623 my ($directory, $pathstring, $filecollector) = @_; 1624 1625 my @content = (); 1626 opendir(DIR, $directory); 1627 @content = readdir(DIR); 1628 closedir(DIR); 1629 1630 my $onefile; 1631 1632 foreach $onefile (@content) 1633 { 1634 if ((!($onefile eq ".")) && (!($onefile eq ".."))) 1635 { 1636 my $completefilename = $directory . $installer::globals::separator . $onefile; 1637 my $sep = ""; 1638 if ( $pathstring ne "" ) { $sep = $installer::globals::separator; } 1639 1640 if ( ! -d $completefilename ) # only files, no directories 1641 { 1642 my $content = $pathstring . $sep . $onefile; 1643 push(@{$filecollector}, $content); 1644 } 1645 else # recursive for directories 1646 { 1647 my $newpathstring = $pathstring . $sep . $onefile; 1648 read_complete_directory($completefilename, $newpathstring, $filecollector); 1649 } 1650 } 1651 } 1652} 1653 1654############################################################## 1655# Reading all files from a directory and its subdirectories 1656# Version 2 1657############################################################## 1658 1659sub read_full_directory { 1660 my ( $currentdir, $pathstring, $collector ) = @_; 1661 my $item; 1662 my $fullname; 1663 local *DH; 1664 1665 unless (opendir(DH, $currentdir)) 1666 { 1667 return; 1668 } 1669 while (defined ($item = readdir(DH))) 1670 { 1671 next if($item eq "." or $item eq ".."); 1672 $fullname = $currentdir . $installer::globals::separator . $item; 1673 my $sep = ""; 1674 if ( $pathstring ne "" ) { $sep = $installer::globals::separator; } 1675 1676 if( -d $fullname) 1677 { 1678 my $newpathstring = $pathstring . $sep . $item; 1679 read_full_directory($fullname, $newpathstring, $collector) if(-d $fullname); 1680 } 1681 else 1682 { 1683 my $content = $pathstring . $sep . $item; 1684 push(@{$collector}, $content); 1685 } 1686 } 1687 closedir(DH); 1688 return 1689} 1690 1691############################################################## 1692# Removing all empty directories below a specified directory 1693############################################################## 1694 1695sub remove_empty_dirs_in_folder 1696{ 1697 my ( $dir ) = @_; 1698 1699 my @content = (); 1700 my $infoline = ""; 1701 1702 $dir =~ s/\Q$installer::globals::separator\E\s*$//; 1703 1704 if ( -d $dir ) 1705 { 1706 opendir(DIR, $dir); 1707 @content = readdir(DIR); 1708 closedir(DIR); 1709 1710 my $oneitem; 1711 1712 foreach $oneitem (@content) 1713 { 1714 if ((!($oneitem eq ".")) && (!($oneitem eq ".."))) 1715 { 1716 my $item = $dir . $installer::globals::separator . $oneitem; 1717 1718 if ( -d $item ) # recursive 1719 { 1720 remove_empty_dirs_in_folder($item); 1721 } 1722 } 1723 } 1724 1725 # try to remove empty directory 1726 my $returnvalue = rmdir $dir; 1727 1728 if ( $returnvalue ) 1729 { 1730 $infoline = "Successfully removed empty dir $dir\n"; 1731 push(@installer::globals::logfileinfo, $infoline); 1732 } 1733 1734 } 1735 1736} 1737 17381; 1739