19780544fSAndrew Rist#**************************************************************
2fd26fe28SMatthias Seidel#
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
10fd26fe28SMatthias Seidel#
11*58f9c062Smseidel#    http://www.apache.org/licenses/LICENSE-2.0
12fd26fe28SMatthias Seidel#
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.
19fd26fe28SMatthias Seidel#
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######################################################
35fd26fe28SMatthias Seidel# Creating a new directory
36cdf0e10cSrcweir######################################################
37cdf0e10cSrcweir
38cdf0e10cSrcweirsub create_directory
39cdf0e10cSrcweir{
40cdf0e10cSrcweir	my ($directory) = @_;
41fd26fe28SMatthias Seidel
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);
53fd26fe28SMatthias Seidel
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";
59fd26fe28SMatthias Seidel			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
65fd26fe28SMatthias Seidel			# exist now.
66cdf0e10cSrcweir
67b274bc22SAndre Fischer			$installer::logger::Lang->print("\n");
68b274bc22SAndre Fischer			$installer::logger::Lang->printf(
69fd26fe28SMatthias Seidel				"Did not succeed in creating directory: \"%s\". Further attempts will follow.\n",
70fd26fe28SMatthias Seidel				$directory);
71fd26fe28SMatthias Seidel
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(
86fd26fe28SMatthias Seidel							"Attention: Successfully created parent directory (should already be created before): %s\n",
87fd26fe28SMatthias Seidel							$parentdir);
88fd26fe28SMatthias Seidel
89cdf0e10cSrcweir						my $localcall = "chmod 775 $parentdir \>\/dev\/null 2\>\&1";
90cdf0e10cSrcweir						system($localcall);
91cdf0e10cSrcweir					}
92cdf0e10cSrcweir					else
93cdf0e10cSrcweir					{
94d29d84faSdamjan						$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(
100fd26fe28SMatthias Seidel								"Attention: Finally the parent directory \"%s\" exists, but I could not create it.\n",
101fd26fe28SMatthias Seidel								$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						}
108fd26fe28SMatthias Seidel					}
109cdf0e10cSrcweir				}
110fd26fe28SMatthias Seidel
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(
120fd26fe28SMatthias Seidel						"Attention: Created directory \"\" in the second try.\n",
121fd26fe28SMatthias Seidel						$directory);;
122fd26fe28SMatthias Seidel
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(
132fd26fe28SMatthias Seidel							"Attention: Finally the directory \"%s\" exists, but I could not create it.\n",
133fd26fe28SMatthias Seidel							$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");
139fd26fe28SMatthias Seidel					}
140fd26fe28SMatthias Seidel				}
141cdf0e10cSrcweir			}
142cdf0e10cSrcweir			else
143cdf0e10cSrcweir			{
144b274bc22SAndre Fischer				$installer::logger::Lang->print("\n");
145b274bc22SAndre Fischer				$installer::logger::Lang->printf(
146fd26fe28SMatthias Seidel					"Another process created this directory in exactly this moment :-) : %s\n",
147fd26fe28SMatthias Seidel					$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######################################################
158fd26fe28SMatthias Seidel# Creating a new directory with defined privileges
159cdf0e10cSrcweir######################################################
160cdf0e10cSrcweir
161cdf0e10cSrcweirsub create_directory_with_privileges
162cdf0e10cSrcweir{
163cdf0e10cSrcweir	my ($directory, $privileges) = @_;
164fd26fe28SMatthias Seidel
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);
177fd26fe28SMatthias Seidel
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
185fd26fe28SMatthias Seidel			# exist now.
186cdf0e10cSrcweir
187b274bc22SAndre Fischer			$installer::logger::Lang->print("\n");
188b274bc22SAndre Fischer			$installer::logger::Lang->printf(
189fd26fe28SMatthias Seidel				"Did not succeed in creating directory: \"%s\". Further attempts will follow.\n",
190fd26fe28SMatthias Seidel				$directory);
191fd26fe28SMatthias Seidel
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(
206fd26fe28SMatthias Seidel							"Attention: Successfully created parent directory (should already be created before): %s\n",
207fd26fe28SMatthias Seidel							$parentdir);
208fd26fe28SMatthias Seidel
209cdf0e10cSrcweir						my $localcall = "chmod $privileges $parentdir \>\/dev\/null 2\>\&1";
210cdf0e10cSrcweir						system($localcall);
211cdf0e10cSrcweir					}
212cdf0e10cSrcweir					else
213cdf0e10cSrcweir					{
214d29d84faSdamjan						$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(
220fd26fe28SMatthias Seidel								"Attention: Finally the parent directory \"%s\" exists, but I could not create it.\n",
221fd26fe28SMatthias Seidel								$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						}
228fd26fe28SMatthias Seidel					}
229cdf0e10cSrcweir				}
230fd26fe28SMatthias Seidel
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",
240fd26fe28SMatthias Seidel						$directory);
241fd26fe28SMatthias Seidel
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");
250fd26fe28SMatthias Seidel						$installer::logger::Lang->printf(
251fd26fe28SMatthias Seidel							"Attention: Finally the directory \"\" exists, but I could not create it.\n",
252fd26fe28SMatthias Seidel							$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");
258fd26fe28SMatthias Seidel					}
259fd26fe28SMatthias Seidel				}
260cdf0e10cSrcweir			}
261cdf0e10cSrcweir			else
262cdf0e10cSrcweir			{
263b274bc22SAndre Fischer				$installer::logger::Lang->print("\n");
264b274bc22SAndre Fischer				$installer::logger::Lang->printf(
265fd26fe28SMatthias Seidel					"Another process created this directory in exactly this moment :-) : %s\n",
266fd26fe28SMatthias Seidel					$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)
284fd26fe28SMatthias Seidel	Return
285fd26fe28SMatthias Seidel		 1 if there are no files in the directory pointed to by $path
286fd26fe28SMatthias Seidel		 0 if there are files
287fd26fe28SMatthias Seidel		-1 if there is an error accessing the directory.
288b274bc22SAndre Fischer=cut
289b274bc22SAndre Fischersub is_directory_empty ($)
290b274bc22SAndre Fischer{
291fd26fe28SMatthias Seidel	my ($path) = @_;
292b274bc22SAndre Fischer
293fd26fe28SMatthias Seidel	opendir my $dir, $path or return -1;
294b274bc22SAndre Fischer
295fd26fe28SMatthias Seidel	my $result = 1;
296fd26fe28SMatthias Seidel	while (my $entry = readdir($dir))
297fd26fe28SMatthias Seidel	{
298fd26fe28SMatthias Seidel		if ($entry !~ /^\.+$/)
299fd26fe28SMatthias Seidel		{
300fd26fe28SMatthias Seidel			$result = 0;
301fd26fe28SMatthias Seidel			last;
302fd26fe28SMatthias Seidel		}
303fd26fe28SMatthias Seidel	}
304b274bc22SAndre Fischer
305fd26fe28SMatthias Seidel	return $result;
306b274bc22SAndre Fischer}
307b274bc22SAndre Fischer
308b274bc22SAndre Fischer
309b274bc22SAndre Fischer
310b274bc22SAndre Fischer
311cdf0e10cSrcweir######################################################
312fd26fe28SMatthias Seidel# Removing a new directory
313cdf0e10cSrcweir######################################################
314cdf0e10cSrcweir
315cdf0e10cSrcweirsub remove_empty_directory
316cdf0e10cSrcweir{
317cdf0e10cSrcweir	my ($directory) = @_;
318cdf0e10cSrcweir
319cdf0e10cSrcweir	my $returnvalue = 1;
320cdf0e10cSrcweir
321cdf0e10cSrcweir	if (-d $directory)
322b274bc22SAndre Fischer	{
323fd26fe28SMatthias Seidel		if ( ! is_directory_empty($directory))
324fd26fe28SMatthias Seidel		{
325b274bc22SAndre Fischer			$installer::logger::Lang->printf("directory '%s' is not empty and can not be removed\n", $directory);
326fd26fe28SMatthias Seidel			return;
327fd26fe28SMatthias Seidel		}
328fd26fe28SMatthias Seidel		else
329fd26fe28SMatthias Seidel		{
330fd26fe28SMatthias Seidel			my $systemcall = "rmdir $directory";
331fd26fe28SMatthias Seidel
332fd26fe28SMatthias Seidel			$returnvalue = system($systemcall);
333fd26fe28SMatthias Seidel
334fd26fe28SMatthias Seidel			$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
335fd26fe28SMatthias Seidel
336fd26fe28SMatthias Seidel			if ($returnvalue)
337fd26fe28SMatthias Seidel			{
338fd26fe28SMatthias Seidel				$installer::logger::Lang->printf("ERROR: Could not remove \"%s\"!\n", $directory);
339fd26fe28SMatthias Seidel			}
340fd26fe28SMatthias Seidel			else
341fd26fe28SMatthias Seidel			{
342fd26fe28SMatthias Seidel				$installer::logger::Lang->printf("Success: Removed \"%s\"!\n", $directory);
343fd26fe28SMatthias Seidel			}
344fd26fe28SMatthias Seidel		}
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;
357fd26fe28SMatthias Seidel
358cdf0e10cSrcweir	my $workstring = $languagestring;
359fd26fe28SMatthias Seidel
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) =@_;
376fd26fe28SMatthias Seidel
377fd26fe28SMatthias Seidel	$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; }
385fd26fe28SMatthias Seidel		$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; }
392fd26fe28SMatthias Seidel		$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;
399fd26fe28SMatthias Seidel
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
411fd26fe28SMatthias Seidel	if ($newdirectory eq "unzip" ) # special handling for common directory
412cdf0e10cSrcweir	{
413fd26fe28SMatthias Seidel		$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);
447fd26fe28SMatthias Seidel
448cdf0e10cSrcweir		my $locallanguagesref = "";
449fd26fe28SMatthias Seidel
450cdf0e10cSrcweir		if ( $$languagesref ) { $locallanguagesref = $$languagesref; }
451cdf0e10cSrcweir
452fd26fe28SMatthias Seidel		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
456fd26fe28SMatthias Seidel			$path = $path . $languagestring . $installer::globals::separator;
457cdf0e10cSrcweir			create_directory($path);
458cdf0e10cSrcweir		}
459cdf0e10cSrcweir	}
460fd26fe28SMatthias Seidel
461cdf0e10cSrcweir	installer::remover::remove_ending_pathseparator(\$path);
462cdf0e10cSrcweir
463cdf0e10cSrcweir	$path = installer::converter::make_path_conform($path);
464fd26fe28SMatthias Seidel
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);
477fd26fe28SMatthias Seidel
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);
485fd26fe28SMatthias Seidel
486cdf0e10cSrcweir	if ($copyreturn)
487cdf0e10cSrcweir	{
488cdf0e10cSrcweir		$infoline = "Copy: $source to $dest\n";
489cdf0e10cSrcweir		$returnvalue = 1;
490cdf0e10cSrcweir	}
491cdf0e10cSrcweir	else
492cdf0e10cSrcweir	{
49343cf7aa4SJürgen Schmidt		$infoline = "ERROR: Could not copy #$source# to $dest\n";
494cdf0e10cSrcweir		$returnvalue = 0;
495cdf0e10cSrcweir	}
496cdf0e10cSrcweir
497b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
498cdf0e10cSrcweir
499fd26fe28SMatthias Seidel	if ( !$returnvalue ) {
500fd26fe28SMatthias Seidel		return $returnvalue;
501fd26fe28SMatthias Seidel	}
502fd26fe28SMatthias Seidel
503fd26fe28SMatthias Seidel	# taking care of file attributes
504fd26fe28SMatthias Seidel	if ($installer::globals::iswin && -f $dest) {
505fd26fe28SMatthias Seidel		my $mode = -x $source ? 0775 : 0664;
506fd26fe28SMatthias Seidel		my $mode_str = sprintf("%o", $mode);
507fd26fe28SMatthias Seidel		my $chmodreturn = chmod($mode, $dest);
508fd26fe28SMatthias Seidel		if ($chmodreturn)
509fd26fe28SMatthias Seidel		{
510fd26fe28SMatthias Seidel			$infoline = "chmod $mode_str, $dest\n";
511fd26fe28SMatthias Seidel			$returnvalue = 1;
512fd26fe28SMatthias Seidel		}
513fd26fe28SMatthias Seidel		else
514fd26fe28SMatthias Seidel		{
515fd26fe28SMatthias Seidel			$infoline = "WARNING: Could not chmod $dest: $!\n";
516fd26fe28SMatthias Seidel			$returnvalue = 0;
517fd26fe28SMatthias Seidel		}
518fd26fe28SMatthias Seidel
519fd26fe28SMatthias Seidel		$installer::logger::Lang->print($infoline);
520fd26fe28SMatthias Seidel	}
521fd26fe28SMatthias Seidel
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);
534fd26fe28SMatthias Seidel
535cdf0e10cSrcweir	my $copyreturn = link($source, $dest);
536fd26fe28SMatthias Seidel
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);
549fd26fe28SMatthias Seidel
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);
562fd26fe28SMatthias Seidel
563cdf0e10cSrcweir	my $linkreturn = symlink($source, $dest);
564fd26fe28SMatthias Seidel
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);
577fd26fe28SMatthias Seidel
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);
592fd26fe28SMatthias Seidel
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	}
603fd26fe28SMatthias Seidel
604b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
605fd26fe28SMatthias Seidel
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) = @_;
617fd26fe28SMatthias Seidel
618cdf0e10cSrcweir	my @sourcefiles = ();
619fd26fe28SMatthias Seidel
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);
627fd26fe28SMatthias Seidel
628cdf0e10cSrcweir	opendir(DIR, $sourcedir);
629cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
630cdf0e10cSrcweir	closedir(DIR);
631cdf0e10cSrcweir
632cdf0e10cSrcweir	my $onefile;
633fd26fe28SMatthias Seidel
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;
640fd26fe28SMatthias Seidel			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) = @_;
656fd26fe28SMatthias Seidel
657cdf0e10cSrcweir	my $directory_is_empty = 1;
658cdf0e10cSrcweir	my @sourcefiles = ();
659fd26fe28SMatthias Seidel
660cdf0e10cSrcweir	opendir(DIR, $dir);
661cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
662cdf0e10cSrcweir	closedir(DIR);
663cdf0e10cSrcweir
664cdf0e10cSrcweir	my $onefile;
665cdf0e10cSrcweir	my @realcontent = ();
666fd26fe28SMatthias Seidel
667cdf0e10cSrcweir	foreach $onefile (@sourcefiles)
668cdf0e10cSrcweir	{
669cdf0e10cSrcweir		if ((!($onefile eq ".")) && (!($onefile eq "..")))
670cdf0e10cSrcweir		{
671cdf0e10cSrcweir			push(@realcontent, $onefile);
672cdf0e10cSrcweir		}
673cdf0e10cSrcweir	}
674fd26fe28SMatthias Seidel
675cdf0e10cSrcweir	if ( $#realcontent > -1 ) { $directory_is_empty = 0; }
676fd26fe28SMatthias Seidel
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) = @_;
687fd26fe28SMatthias Seidel
688cdf0e10cSrcweir	my @sourcefiles = ();
689fd26fe28SMatthias Seidel
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);
699fd26fe28SMatthias Seidel
700cdf0e10cSrcweir	opendir(DIR, $sourcedir);
701cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
702cdf0e10cSrcweir	closedir(DIR);
703cdf0e10cSrcweir
704cdf0e10cSrcweir	my $onefile;
705fd26fe28SMatthias Seidel
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;
712fd26fe28SMatthias Seidel			if ( -f $source ) # only files, no directories
713cdf0e10cSrcweir			{
714cdf0e10cSrcweir				hardlink_one_file($source, $dest);
715cdf0e10cSrcweir			}
716fd26fe28SMatthias Seidel			if ( -d $source ) # recursive
717cdf0e10cSrcweir			{
718cdf0e10cSrcweir				hardlink_complete_directory($source, $dest);
719cdf0e10cSrcweir			}
720cdf0e10cSrcweir		}
721fd26fe28SMatthias Seidel	}
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) = @_;
731fd26fe28SMatthias Seidel
732cdf0e10cSrcweir	my @sourcefiles = ();
733fd26fe28SMatthias Seidel
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);
743fd26fe28SMatthias Seidel
744cdf0e10cSrcweir	opendir(DIR, $sourcedir);
745cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
746cdf0e10cSrcweir	closedir(DIR);
747cdf0e10cSrcweir
748cdf0e10cSrcweir	my $onefile;
749fd26fe28SMatthias Seidel
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;
756fd26fe28SMatthias Seidel			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			}
762fd26fe28SMatthias Seidel			if ( -d $source ) # recursive
763cdf0e10cSrcweir			{
764cdf0e10cSrcweir				my $newdepth = $depth + 1;
765cdf0e10cSrcweir				softlink_complete_directory($source, $dest, $newdepth);
766cdf0e10cSrcweir			}
767cdf0e10cSrcweir		}
768fd26fe28SMatthias Seidel	}
769cdf0e10cSrcweir}
770cdf0e10cSrcweir
771cdf0e10cSrcweir#####################################################
772cdf0e10cSrcweir# Copying a complete directory with sub directories.
773cdf0e10cSrcweir#####################################################
774cdf0e10cSrcweir
775cdf0e10cSrcweirsub copy_complete_directory
776cdf0e10cSrcweir{
777cdf0e10cSrcweir	my ($sourcedir, $destdir) = @_;
778fd26fe28SMatthias Seidel
779cdf0e10cSrcweir	my @sourcefiles = ();
780fd26fe28SMatthias Seidel
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);
790fd26fe28SMatthias Seidel
791cdf0e10cSrcweir	opendir(DIR, $sourcedir);
792cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
793cdf0e10cSrcweir	closedir(DIR);
794cdf0e10cSrcweir
795cdf0e10cSrcweir	my $onefile;
796fd26fe28SMatthias Seidel
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;
803fd26fe28SMatthias Seidel			if ( -f $source ) # only files, no directories
804cdf0e10cSrcweir			{
805cdf0e10cSrcweir				copy_one_file($source, $dest);
806cdf0e10cSrcweir			}
807fd26fe28SMatthias Seidel			if ( -d $source ) # recursive
808cdf0e10cSrcweir			{
809fd26fe28SMatthias Seidel				if ((!( $source =~ /packages\/SUNW/ )) && (!( $source =~ /packages\/OOO/ ))) # do not copy complete Solaris packages!
810cdf0e10cSrcweir				{
811cdf0e10cSrcweir					copy_complete_directory($source, $dest);
812cdf0e10cSrcweir				}
813cdf0e10cSrcweir			}
814cdf0e10cSrcweir		}
815fd26fe28SMatthias Seidel	}
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) = @_;
825fd26fe28SMatthias Seidel
826cdf0e10cSrcweir	my @sourcefiles = ();
827fd26fe28SMatthias Seidel
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);
837fd26fe28SMatthias Seidel
838cdf0e10cSrcweir	opendir(DIR, $sourcedir);
839cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
840cdf0e10cSrcweir	closedir(DIR);
841cdf0e10cSrcweir
842cdf0e10cSrcweir	my $onefile;
843fd26fe28SMatthias Seidel
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;
850fd26fe28SMatthias Seidel			if ( -f $source ) # only files, no directories
851cdf0e10cSrcweir			{
852cdf0e10cSrcweir				copy_one_file($source, $dest);
853cdf0e10cSrcweir			}
854fd26fe28SMatthias Seidel			if ( -d $source ) # recursive
855cdf0e10cSrcweir			{
856cdf0e10cSrcweir				copy_complete_directory_without_cvs($source, $dest);
857cdf0e10cSrcweir			}
858cdf0e10cSrcweir		}
859fd26fe28SMatthias Seidel	}
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) = @_;
870fd26fe28SMatthias Seidel
871cdf0e10cSrcweir	my @sourcefiles = ();
872fd26fe28SMatthias Seidel
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);
880fd26fe28SMatthias Seidel
881cdf0e10cSrcweir	opendir(DIR, $sourcedir);
882cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
883cdf0e10cSrcweir	closedir(DIR);
884cdf0e10cSrcweir
885cdf0e10cSrcweir	my $onefile;
886fd26fe28SMatthias Seidel
887cdf0e10cSrcweir	foreach $onefile (@sourcefiles)
888cdf0e10cSrcweir	{
889cdf0e10cSrcweir		if ((!($onefile eq ".")) && (!($onefile eq "..")))
890cdf0e10cSrcweir		{
891fd26fe28SMatthias Seidel			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;
895fd26fe28SMatthias Seidel				if ( -f $sourcefile ) # only files, no directories
896cdf0e10cSrcweir				{
897cdf0e10cSrcweir					copy_one_file($sourcefile, $destfile);
898cdf0e10cSrcweir				}
899cdf0e10cSrcweir			}
900cdf0e10cSrcweir		}
901fd26fe28SMatthias Seidel	}
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) = @_;
912fd26fe28SMatthias Seidel
913cdf0e10cSrcweir	my @sourcefiles = ();
914fd26fe28SMatthias Seidel
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);
922fd26fe28SMatthias Seidel
923cdf0e10cSrcweir	opendir(DIR, $sourcedir);
924cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
925cdf0e10cSrcweir	closedir(DIR);
926cdf0e10cSrcweir
927cdf0e10cSrcweir	my $onefile;
928fd26fe28SMatthias Seidel
929cdf0e10cSrcweir	foreach $onefile (@sourcefiles)
930cdf0e10cSrcweir	{
931cdf0e10cSrcweir		if ((!($onefile eq ".")) && (!($onefile eq "..")))
932cdf0e10cSrcweir		{
933fd26fe28SMatthias Seidel			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;
937fd26fe28SMatthias Seidel				if ( -f $sourcefile ) # only files, no directories
938cdf0e10cSrcweir				{
939cdf0e10cSrcweir					copy_one_file($sourcefile, $destfile);
940cdf0e10cSrcweir				}
941cdf0e10cSrcweir			}
942cdf0e10cSrcweir		}
943fd26fe28SMatthias Seidel	}
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) = @_;
955fd26fe28SMatthias Seidel
956cdf0e10cSrcweir	my @sourcefiles = ();
957fd26fe28SMatthias Seidel
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);
964fd26fe28SMatthias Seidel
965cdf0e10cSrcweir	opendir(DIR, $dir);
966cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
967cdf0e10cSrcweir	closedir(DIR);
968cdf0e10cSrcweir
969cdf0e10cSrcweir	my $onefile;
970fd26fe28SMatthias Seidel
971cdf0e10cSrcweir	foreach $onefile (@sourcefiles)
972cdf0e10cSrcweir	{
973cdf0e10cSrcweir		if ((!($onefile eq ".")) && (!($onefile eq "..")))
974cdf0e10cSrcweir		{
975fd26fe28SMatthias Seidel			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;
980fd26fe28SMatthias Seidel				if ( -f $sourcefile ) # only files, no directories
981cdf0e10cSrcweir				{
982cdf0e10cSrcweir					rename_one_file($sourcefile, $destfile);
983cdf0e10cSrcweir				}
984cdf0e10cSrcweir			}
985cdf0e10cSrcweir		}
986fd26fe28SMatthias Seidel	}
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) = @_;
997fd26fe28SMatthias Seidel
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);
1006fd26fe28SMatthias Seidel
1007cdf0e10cSrcweir	opendir(DIR, $dir);
1008cdf0e10cSrcweir	@sourcefiles = sort readdir(DIR);
1009cdf0e10cSrcweir	closedir(DIR);
1010cdf0e10cSrcweir
1011cdf0e10cSrcweir	my $onefile;
1012fd26fe28SMatthias Seidel
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	}
1023fd26fe28SMatthias Seidel
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) = @_;
1035fd26fe28SMatthias Seidel
1036cdf0e10cSrcweir	my $basedir = $olddir;
1037cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$basedir);
1038cdf0e10cSrcweir
1039cdf0e10cSrcweir	my $alldirs = get_all_directories($basedir);
1040fd26fe28SMatthias Seidel
1041cdf0e10cSrcweir	# searching for the highest number extension
1042cdf0e10cSrcweir
1043cdf0e10cSrcweir	my $maxnumber = 0;
1044fd26fe28SMatthias Seidel
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;
1055fd26fe28SMatthias Seidel
1056cdf0e10cSrcweir	my $newdir = $olddir . "_" . $newstring . "_" . $newnumber;
1057fd26fe28SMatthias Seidel
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",
1070fd26fe28SMatthias Seidel			$olddir,
1071fd26fe28SMatthias Seidel			$newdir);
1072cdf0e10cSrcweir		$returndir = $olddir;
1073cdf0e10cSrcweir	}
1074fd26fe28SMatthias Seidel
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) = @_;
1085fd26fe28SMatthias Seidel
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;
1096fd26fe28SMatthias Seidel
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 = ();
1102fd26fe28SMatthias Seidel
1103cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
1104cdf0e10cSrcweir	{
1105cdf0e10cSrcweir		my $onedir = ${$alldirs}[$i];
1106cdf0e10cSrcweir		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$onedir);
1107fd26fe28SMatthias Seidel
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;
1129fd26fe28SMatthias Seidel
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;
1151fd26fe28SMatthias Seidel
1152cdf0e10cSrcweir			if ( $languagestring eq $$languagestringref )
1153cdf0e10cSrcweir			{
1154cdf0e10cSrcweir				$increase_counter = 1;
1155cdf0e10cSrcweir			}
1156cdf0e10cSrcweir		}
1157cdf0e10cSrcweir	}
1158cdf0e10cSrcweir
1159cdf0e10cSrcweir	if ( $increase_counter )
1160cdf0e10cSrcweir	{
1161cdf0e10cSrcweir		$maxnumber = $maxnumber + 1;
1162cdf0e10cSrcweir	}
1163fd26fe28SMatthias Seidel
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) = @_;
1175fd26fe28SMatthias Seidel
1176cdf0e10cSrcweir	my $newdir = $olddir;
1177cdf0e10cSrcweir	my $infoline = "";
1178fd26fe28SMatthias Seidel
1179cdf0e10cSrcweir	$newdir =~ s/$oldstring/$newstring/g;
1180fd26fe28SMatthias Seidel
1181cdf0e10cSrcweir	if (( -d $newdir ) && ( $olddir ne $newdir )) { remove_complete_directory($newdir, 1); }
1182fd26fe28SMatthias Seidel
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(
1192fd26fe28SMatthias Seidel			"ATTENTION: Could not move directory from %s to %s, \"rename_string_in_directory\"\n",
1193fd26fe28SMatthias Seidel			$olddir, $newdir);
1194cdf0e10cSrcweir	}
1195fd26fe28SMatthias Seidel
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) = @_;
1207fd26fe28SMatthias Seidel
1208cdf0e10cSrcweir	my $dirname = "";
1209cdf0e10cSrcweir	my $founddir = 0;
1210cdf0e10cSrcweir	my $direntry;
1211fd26fe28SMatthias Seidel
1212cdf0e10cSrcweir	opendir(DIR, $searchdir);
1213fd26fe28SMatthias Seidel
1214cdf0e10cSrcweir	foreach $direntry (readdir (DIR))
1215cdf0e10cSrcweir	{
1216cdf0e10cSrcweir		next if $direntry eq ".";
1217cdf0e10cSrcweir		next if $direntry eq "..";
1218fd26fe28SMatthias Seidel
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"); }
1230fd26fe28SMatthias Seidel
1231cdf0e10cSrcweir	return $dirname;
1232cdf0e10cSrcweir}
1233cdf0e10cSrcweir
1234cdf0e10cSrcweir
1235cdf0e10cSrcweir###################################
1236cdf0e10cSrcweir# Renaming a directory
1237cdf0e10cSrcweir###################################
1238cdf0e10cSrcweir
1239cdf0e10cSrcweirsub rename_directory
1240cdf0e10cSrcweir{
1241cdf0e10cSrcweir	my ($olddir, $newdir) = @_;
1242fd26fe28SMatthias Seidel
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
1246fd26fe28SMatthias Seidel	# workaround with sleep, should be investigated with a new packaging mechanism
1247fd26fe28SMatthias Seidel	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	}
1257fd26fe28SMatthias Seidel
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*$//;
1273fd26fe28SMatthias Seidel
1274cdf0e10cSrcweir	my $newdir = $basedir . $installer::globals::separator . $dirname;
1275fd26fe28SMatthias Seidel
1276cdf0e10cSrcweir	create_directory($newdir);
1277fd26fe28SMatthias Seidel
1278cdf0e10cSrcweir	return $newdir;
1279cdf0e10cSrcweir}
1280cdf0e10cSrcweir
1281cdf0e10cSrcweir##############################################################
1282cdf0e10cSrcweir# Collecting all directories inside a directory
1283cdf0e10cSrcweir##############################################################
1284cdf0e10cSrcweir
1285cdf0e10cSrcweirsub get_all_directories
1286cdf0e10cSrcweir{
1287cdf0e10cSrcweir	my ($basedir) = @_;
1288fd26fe28SMatthias Seidel
1289cdf0e10cSrcweir	my @alldirs = ();
1290cdf0e10cSrcweir	my $direntry;
1291fd26fe28SMatthias Seidel
1292cdf0e10cSrcweir	$basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1293cdf0e10cSrcweir
1294cdf0e10cSrcweir	opendir(DIR, $basedir);
1295fd26fe28SMatthias Seidel
1296cdf0e10cSrcweir	foreach $direntry (readdir (DIR))
1297cdf0e10cSrcweir	{
1298cdf0e10cSrcweir		next if $direntry eq ".";
1299cdf0e10cSrcweir		next if $direntry eq "..";
1300fd26fe28SMatthias Seidel
1301cdf0e10cSrcweir		my $completeentry = $basedir . $installer::globals::separator . $direntry;
1302cdf0e10cSrcweir
1303cdf0e10cSrcweir		if ( -d $completeentry ) { push(@alldirs, $completeentry); }
1304cdf0e10cSrcweir	}
1305cdf0e10cSrcweir
1306cdf0e10cSrcweir	closedir(DIR);
1307fd26fe28SMatthias Seidel
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) = @_;
1319fd26fe28SMatthias Seidel
1320cdf0e10cSrcweir	my @alldirs = ();
1321cdf0e10cSrcweir	my $direntry;
1322fd26fe28SMatthias Seidel
1323cdf0e10cSrcweir	$basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1324cdf0e10cSrcweir
1325cdf0e10cSrcweir	opendir(DIR, $basedir);
1326fd26fe28SMatthias Seidel
1327cdf0e10cSrcweir	foreach $direntry (readdir (DIR))
1328cdf0e10cSrcweir	{
1329cdf0e10cSrcweir		next if $direntry eq ".";
1330cdf0e10cSrcweir		next if $direntry eq "..";
1331fd26fe28SMatthias Seidel
1332cdf0e10cSrcweir		my $completeentry = $basedir . $installer::globals::separator . $direntry;
1333cdf0e10cSrcweir
1334cdf0e10cSrcweir		if ( -d $completeentry ) { push(@alldirs, $direntry); }
1335cdf0e10cSrcweir	}
1336cdf0e10cSrcweir
1337cdf0e10cSrcweir	closedir(DIR);
1338fd26fe28SMatthias Seidel
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) = @_;
1349fd26fe28SMatthias Seidel
1350cdf0e10cSrcweir	my @allfiles = ();
1351cdf0e10cSrcweir	my $direntry;
1352fd26fe28SMatthias Seidel
1353cdf0e10cSrcweir	$basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1354cdf0e10cSrcweir
1355cdf0e10cSrcweir	opendir(DIR, $basedir);
1356fd26fe28SMatthias Seidel
1357cdf0e10cSrcweir	foreach $direntry (readdir (DIR))
1358cdf0e10cSrcweir	{
1359cdf0e10cSrcweir		next if $direntry eq ".";
1360cdf0e10cSrcweir		next if $direntry eq "..";
1361fd26fe28SMatthias Seidel
1362cdf0e10cSrcweir		my $completeentry = $basedir . $installer::globals::separator . $direntry;
1363cdf0e10cSrcweir
1364cdf0e10cSrcweir		if ( -f $completeentry ) { push(@allfiles, $completeentry); }
1365cdf0e10cSrcweir	}
1366cdf0e10cSrcweir
1367cdf0e10cSrcweir	closedir(DIR);
1368fd26fe28SMatthias Seidel
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) = @_;
1379fd26fe28SMatthias Seidel
1380cdf0e10cSrcweir	my @allfiles = ();
1381cdf0e10cSrcweir	my $direntry;
1382fd26fe28SMatthias Seidel
1383cdf0e10cSrcweir	$basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1384cdf0e10cSrcweir
1385cdf0e10cSrcweir	opendir(DIR, $basedir);
1386fd26fe28SMatthias Seidel
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);
1398fd26fe28SMatthias Seidel
1399cdf0e10cSrcweir	return \@allfiles;
1400cdf0e10cSrcweir}
1401cdf0e10cSrcweir
1402cdf0e10cSrcweir##############################################################
1403cdf0e10cSrcweir# Collecting all files and directories inside one directory
1404cdf0e10cSrcweir##############################################################
1405cdf0e10cSrcweir
1406cdf0e10cSrcweirsub read_directory
1407cdf0e10cSrcweir{
1408cdf0e10cSrcweir	my ($basedir) = @_;
1409fd26fe28SMatthias Seidel
1410cdf0e10cSrcweir	my @allcontent = ();
1411cdf0e10cSrcweir	my $direntry;
1412fd26fe28SMatthias Seidel
1413cdf0e10cSrcweir	$basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1414cdf0e10cSrcweir
1415cdf0e10cSrcweir	opendir(DIR, $basedir);
1416fd26fe28SMatthias Seidel
1417cdf0e10cSrcweir	foreach $direntry (readdir (DIR))
1418cdf0e10cSrcweir	{
1419cdf0e10cSrcweir		next if $direntry eq ".";
1420cdf0e10cSrcweir		next if $direntry eq "..";
1421fd26fe28SMatthias Seidel
1422cdf0e10cSrcweir		my $completeentry = $basedir . $installer::globals::separator . $direntry;
1423cdf0e10cSrcweir
1424cdf0e10cSrcweir		if (( -f $completeentry ) || ( -d $completeentry )) { push(@allcontent, $completeentry); }
1425cdf0e10cSrcweir	}
1426cdf0e10cSrcweir
1427cdf0e10cSrcweir	closedir(DIR);
1428fd26fe28SMatthias Seidel
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 ) = @_;
1439fd26fe28SMatthias Seidel
1440cdf0e10cSrcweir	my @newcontent = ();
1441cdf0e10cSrcweir	my @allcontent = ();
1442fd26fe28SMatthias Seidel
1443cdf0e10cSrcweir	my $direntry;
1444fd26fe28SMatthias Seidel
1445cdf0e10cSrcweir	$basedir =~ s/\Q$installer::globals::separator\E\s*$//;
1446cdf0e10cSrcweir
1447cdf0e10cSrcweir	opendir(DIR, $basedir);
1448fd26fe28SMatthias Seidel
1449cdf0e10cSrcweir	foreach $direntry (readdir (DIR))
1450cdf0e10cSrcweir	{
1451cdf0e10cSrcweir		next if $direntry eq ".";
1452cdf0e10cSrcweir		next if $direntry eq "..";
1453fd26fe28SMatthias Seidel
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);
1462fd26fe28SMatthias Seidel			}
1463cdf0e10cSrcweir		}
1464cdf0e10cSrcweir	}
1465cdf0e10cSrcweir
1466cdf0e10cSrcweir	closedir(DIR);
1467fd26fe28SMatthias Seidel
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) = @_;
1478fd26fe28SMatthias Seidel
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);
1491fd26fe28SMatthias Seidel
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
1528fd26fe28SMatthias Seidel		create_directory_structure($parentdir); # recursive
1529cdf0e10cSrcweir	}
1530fd26fe28SMatthias Seidel
1531fd26fe28SMatthias Seidel	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 = "";
1544fd26fe28SMatthias Seidel
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		}
1554fd26fe28SMatthias Seidel
1555cdf0e10cSrcweir		opendir(DIR, $directory);
1556cdf0e10cSrcweir		@content = readdir(DIR);
1557cdf0e10cSrcweir		closedir(DIR);
1558cdf0e10cSrcweir
1559cdf0e10cSrcweir		my $oneitem;
1560fd26fe28SMatthias Seidel
1561cdf0e10cSrcweir		foreach $oneitem (@content)
1562cdf0e10cSrcweir		{
1563cdf0e10cSrcweir			if ((!($oneitem eq ".")) && (!($oneitem eq "..")))
1564cdf0e10cSrcweir			{
1565cdf0e10cSrcweir				my $item = $directory . $installer::globals::separator . $oneitem;
1566cdf0e10cSrcweir
1567fd26fe28SMatthias Seidel				if ( -f $item || -l $item ) # deleting files or links
1568cdf0e10cSrcweir				{
1569cdf0e10cSrcweir					unlink($item);
1570cdf0e10cSrcweir				}
1571cdf0e10cSrcweir
1572fd26fe28SMatthias Seidel				if ( -d $item ) # recursive
1573cdf0e10cSrcweir				{
1574cdf0e10cSrcweir					remove_complete_directory($item, 0);
1575cdf0e10cSrcweir				}
1576cdf0e10cSrcweir			}
1577cdf0e10cSrcweir		}
1578fd26fe28SMatthias Seidel
1579cdf0e10cSrcweir		# try to remove empty directory
1580b274bc22SAndre Fischer
1581fd26fe28SMatthias Seidel		if ( ! -d $directory)
1582fd26fe28SMatthias Seidel		{
1583fd26fe28SMatthias Seidel			$installer::logger::Info->printf("trying to remove directory that doesn't exist: %s\n", $directory);
1584fd26fe28SMatthias Seidel		}
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		}
1591fd26fe28SMatthias Seidel
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",
1601fd26fe28SMatthias Seidel						$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					}
1609fd26fe28SMatthias Seidel					else
1610fd26fe28SMatthias Seidel					{
1611b274bc22SAndre Fischer						$installer::logger::Lang->printf("Warning: rmdir %s failed.\n", $directory);
1612cdf0e10cSrcweir					}
1613cdf0e10cSrcweir				}
1614cdf0e10cSrcweir			}
1615cdf0e10cSrcweir		}
1616fd26fe28SMatthias Seidel	}
1617cdf0e10cSrcweir}
1618cdf0e10cSrcweir
1619cdf0e10cSrcweir######################################################
1620fd26fe28SMatthias Seidel# Creating a unique directory with number extension
1621cdf0e10cSrcweir######################################################
1622cdf0e10cSrcweir
1623cdf0e10cSrcweirsub create_unique_directory
1624cdf0e10cSrcweir{
1625cdf0e10cSrcweir	my ($directory) = @_;
1626fd26fe28SMatthias Seidel
1627cdf0e10cSrcweir	$directory =~ s/\Q$installer::globals::separator\E\s*$//;
1628cdf0e10cSrcweir	$directory = $directory . "_INCREASINGNUMBER";
1629fd26fe28SMatthias Seidel
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++;
1639fd26fe28SMatthias Seidel
1640cdf0e10cSrcweir		if ( ! -d $localdirectory )
1641cdf0e10cSrcweir		{
1642cdf0e10cSrcweir			create_directory($localdirectory);
1643cdf0e10cSrcweir			$created = 1;
1644fd26fe28SMatthias Seidel		}
1645cdf0e10cSrcweir	}
1646cdf0e10cSrcweir	while ( ! $created );
1647fd26fe28SMatthias Seidel
1648cdf0e10cSrcweir	return $localdirectory;
1649cdf0e10cSrcweir}
1650cdf0e10cSrcweir
1651cdf0e10cSrcweir######################################################
1652fd26fe28SMatthias Seidel# Creating a unique directory with pid extension
1653cdf0e10cSrcweir######################################################
1654cdf0e10cSrcweir
1655cdf0e10cSrcweirsub create_pid_directory
1656cdf0e10cSrcweir{
1657cdf0e10cSrcweir	my ($directory) = @_;
1658fd26fe28SMatthias Seidel
1659cdf0e10cSrcweir	$directory =~ s/\Q$installer::globals::separator\E\s*$//;
1660fd26fe28SMatthias Seidel	my $pid = $$; # process id
1661fd26fe28SMatthias Seidel	my $time = time(); # time
1662fd26fe28SMatthias Seidel
1663cdf0e10cSrcweir	$directory = $directory . "_" . $pid . $time;
1664cdf0e10cSrcweir
1665fd26fe28SMatthias Seidel	if ( ! -d $directory ) { create_directory($directory); }
1666cdf0e10cSrcweir	else { installer::exiter::exit_program("ERROR: Directory $directory already exists!", "create_pid_directory"); }
1667fd26fe28SMatthias Seidel
1668cdf0e10cSrcweir	return $directory;
1669cdf0e10cSrcweir}
1670cdf0e10cSrcweir
1671cdf0e10cSrcweir##############################################################
1672fd26fe28SMatthias Seidel# Reading all files from a directory and its subdirectories
1673cdf0e10cSrcweir##############################################################
1674cdf0e10cSrcweir
1675cdf0e10cSrcweirsub read_complete_directory
1676cdf0e10cSrcweir{
1677cdf0e10cSrcweir	my ($directory, $pathstring, $filecollector) = @_;
1678fd26fe28SMatthias Seidel
1679cdf0e10cSrcweir	my @content = ();
1680cdf0e10cSrcweir	opendir(DIR, $directory);
1681cdf0e10cSrcweir	@content = readdir(DIR);
1682cdf0e10cSrcweir	closedir(DIR);
1683cdf0e10cSrcweir
1684cdf0e10cSrcweir	my $onefile;
1685fd26fe28SMatthias Seidel
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
1694fd26fe28SMatthias Seidel			if ( ! -d $completefilename ) # only files, no directories
1695cdf0e10cSrcweir			{
1696cdf0e10cSrcweir				my $content = $pathstring . $sep . $onefile;
1697cdf0e10cSrcweir				push(@{$filecollector}, $content);
1698cdf0e10cSrcweir			}
1699fd26fe28SMatthias Seidel			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
1710fd26fe28SMatthias Seidel# 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
1720fd26fe28SMatthias Seidel	$installer::logger::Lang->printf("seaching files under '%s'\n", $currentdir);
1721fd26fe28SMatthias Seidel
1722fd26fe28SMatthias Seidel	my @directory_queue = [$currentdir, $pathstring];
1723fd26fe28SMatthias Seidel
1724fd26fe28SMatthias Seidel	while (scalar @directory_queue > 0)
1725fd26fe28SMatthias Seidel	{
1726fd26fe28SMatthias Seidel		my ($path, $relative_path) = @{shift @directory_queue};
1727fd26fe28SMatthias Seidel		my $start_count = scalar @$collector;
1728fd26fe28SMatthias Seidel
1729fd26fe28SMatthias Seidel		next unless opendir(DH, $path);
1730fd26fe28SMatthias Seidel
1731fd26fe28SMatthias Seidel		while (defined ($item = readdir(DH)))
1732fd26fe28SMatthias Seidel		{
1733fd26fe28SMatthias Seidel			next if($item eq "." or $item eq "..");
1734fd26fe28SMatthias Seidel			$fullname = $path . $installer::globals::separator . $item;
1735fd26fe28SMatthias Seidel			my $sep = "";
1736fd26fe28SMatthias Seidel			if ($relative_path ne "")
1737fd26fe28SMatthias Seidel			{
1738fd26fe28SMatthias Seidel				$sep = $installer::globals::separator;
1739fd26fe28SMatthias Seidel			}
1740fd26fe28SMatthias Seidel
1741fd26fe28SMatthias Seidel			if( -d $fullname)
1742fd26fe28SMatthias Seidel			{
1743fd26fe28SMatthias Seidel				push @directory_queue, [$fullname, $relative_path . $sep . $item];
1744fd26fe28SMatthias Seidel			}
1745fd26fe28SMatthias Seidel			else
1746fd26fe28SMatthias Seidel			{
1747fd26fe28SMatthias Seidel				my $content = $relative_path . $sep . $item;
1748fd26fe28SMatthias Seidel				push(@{$collector}, $content);
1749fd26fe28SMatthias Seidel			}
1750fd26fe28SMatthias Seidel		}
1751fd26fe28SMatthias Seidel		closedir(DH);
1752fd26fe28SMatthias Seidel		my $count = scalar @$collector - $start_count;
1753fd26fe28SMatthias Seidel		$installer::logger::Lang->printf("    found %d new files in '%s'\n", $count, $path);
1754fd26fe28SMatthias Seidel	}
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 = "";
1767fd26fe28SMatthias Seidel
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;
1777fd26fe28SMatthias Seidel
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		}
1790fd26fe28SMatthias Seidel
1791b274bc22SAndre Fischer		# try to remove empty directory
1792fd26fe28SMatthias Seidel		$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		}
1799fd26fe28SMatthias Seidel
1800cdf0e10cSrcweir	}
1801fd26fe28SMatthias Seidel
1802cdf0e10cSrcweir}
1803cdf0e10cSrcweir
1804cdf0e10cSrcweir1;
1805