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