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