1*cdf0e10cSrcweir#*************************************************************************
2*cdf0e10cSrcweir#
3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# This file is part of OpenOffice.org.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir#
21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir#*************************************************************************
27*cdf0e10cSrcweir
28*cdf0e10cSrcweir
29*cdf0e10cSrcweirpackage pre2par::systemactions;
30*cdf0e10cSrcweir
31*cdf0e10cSrcweiruse File::Copy;
32*cdf0e10cSrcweiruse pre2par::exiter;
33*cdf0e10cSrcweiruse pre2par::globals;
34*cdf0e10cSrcweir
35*cdf0e10cSrcweir######################################################
36*cdf0e10cSrcweir# Creating a new direcotory
37*cdf0e10cSrcweir######################################################
38*cdf0e10cSrcweir
39*cdf0e10cSrcweirsub create_directory
40*cdf0e10cSrcweir{
41*cdf0e10cSrcweir	my ($directory) = @_;
42*cdf0e10cSrcweir
43*cdf0e10cSrcweir	my $returnvalue = 1;
44*cdf0e10cSrcweir	my $infoline = "";
45*cdf0e10cSrcweir
46*cdf0e10cSrcweir	if ($directory eq "" )
47*cdf0e10cSrcweir	{
48*cdf0e10cSrcweir		return 0;
49*cdf0e10cSrcweir	}
50*cdf0e10cSrcweir
51*cdf0e10cSrcweir	if (!(-d $directory))
52*cdf0e10cSrcweir	{
53*cdf0e10cSrcweir		$returnvalue = mkdir($directory, 0775);
54*cdf0e10cSrcweir
55*cdf0e10cSrcweir		if ($returnvalue)
56*cdf0e10cSrcweir		{
57*cdf0e10cSrcweir			$infoline = "Created directory: $directory\n";
58*cdf0e10cSrcweir			push(@pre2par::globals::logfileinfo, $infoline);
59*cdf0e10cSrcweir
60*cdf0e10cSrcweir			if ($pre2par::globals::isunix)
61*cdf0e10cSrcweir			{
62*cdf0e10cSrcweir				my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
63*cdf0e10cSrcweir				system($localcall);
64*cdf0e10cSrcweir			}
65*cdf0e10cSrcweir		}
66*cdf0e10cSrcweir		else
67*cdf0e10cSrcweir		{
68*cdf0e10cSrcweir			# New solution in parallel packing: It is possible, that the directory now exists, although it
69*cdf0e10cSrcweir			# was not created in this process. There is only an important error, if the directory does not
70*cdf0e10cSrcweir			# exist now.
71*cdf0e10cSrcweir
72*cdf0e10cSrcweir			if (!(-d $directory))
73*cdf0e10cSrcweir			{
74*cdf0e10cSrcweir				pre2par::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
75*cdf0e10cSrcweir			}
76*cdf0e10cSrcweir			else
77*cdf0e10cSrcweir			{
78*cdf0e10cSrcweir				$infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
79*cdf0e10cSrcweir				push(@pre2par::globals::logfileinfo, $infoline);
80*cdf0e10cSrcweir			}
81*cdf0e10cSrcweir		}
82*cdf0e10cSrcweir	}
83*cdf0e10cSrcweir	else
84*cdf0e10cSrcweir	{
85*cdf0e10cSrcweir		$infoline = "\nAlready existing directory, did not create: $directory\n";
86*cdf0e10cSrcweir		push(@pre2par::globals::logfileinfo, $infoline);
87*cdf0e10cSrcweir	}
88*cdf0e10cSrcweir}
89*cdf0e10cSrcweir
90*cdf0e10cSrcweir#######################################################################
91*cdf0e10cSrcweir# Creating the directories, in which files are generated or unzipped
92*cdf0e10cSrcweir#######################################################################
93*cdf0e10cSrcweir
94*cdf0e10cSrcweirsub create_directories
95*cdf0e10cSrcweir{
96*cdf0e10cSrcweir	my ($directory, $languagesref) =@_;
97*cdf0e10cSrcweir
98*cdf0e10cSrcweir	$pre2par::globals::unpackpath =~ s/\Q$pre2par::globals::separator\E\s*$//;	# removing ending slashes and backslashes
99*cdf0e10cSrcweir
100*cdf0e10cSrcweir	my $path = $pre2par::globals::unpackpath;	 # this path already exists
101*cdf0e10cSrcweir
102*cdf0e10cSrcweir	$path = $path . $pre2par::globals::separator . $pre2par::globals::build . $pre2par::globals::separator;
103*cdf0e10cSrcweir	create_directory($path);
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir	$path = $path . $pre2par::globals::minor . $pre2par::globals::separator;
106*cdf0e10cSrcweir	create_directory($path);
107*cdf0e10cSrcweir
108*cdf0e10cSrcweir	if ($directory eq "unzip" )
109*cdf0e10cSrcweir	{
110*cdf0e10cSrcweir		$path = $path . "common" . $pre2par::globals::productextension . $pre2par::globals::separator;
111*cdf0e10cSrcweir		create_directory($path);
112*cdf0e10cSrcweir
113*cdf0e10cSrcweir		$path = $path . $directory . $pre2par::globals::separator;
114*cdf0e10cSrcweir		create_directory($path);
115*cdf0e10cSrcweir	}
116*cdf0e10cSrcweir	else
117*cdf0e10cSrcweir	{
118*cdf0e10cSrcweir		$path = $path . $pre2par::globals::compiler . $pre2par::globals::productextension . $pre2par::globals::separator;
119*cdf0e10cSrcweir		create_directory($path);
120*cdf0e10cSrcweir
121*cdf0e10cSrcweir		$path = $path . $pre2par::globals::product . $pre2par::globals::separator;
122*cdf0e10cSrcweir		create_directory($path);
123*cdf0e10cSrcweir
124*cdf0e10cSrcweir		$path = $path . $directory . $pre2par::globals::separator;
125*cdf0e10cSrcweir		create_directory($path);
126*cdf0e10cSrcweir
127*cdf0e10cSrcweir		if (!($$languagesref eq "" ))	# this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
128*cdf0e10cSrcweir		{
129*cdf0e10cSrcweir			$path = $path . $$languagesref . $pre2par::globals::separator;
130*cdf0e10cSrcweir			create_directory($path);
131*cdf0e10cSrcweir		}
132*cdf0e10cSrcweir	}
133*cdf0e10cSrcweir
134*cdf0e10cSrcweir	$path =~ s/\Q$pre2par::globals::separator\E\s*$//;
135*cdf0e10cSrcweir
136*cdf0e10cSrcweir	return $path;
137*cdf0e10cSrcweir}
138*cdf0e10cSrcweir
139*cdf0e10cSrcweir########################
140*cdf0e10cSrcweir# Copying one file
141*cdf0e10cSrcweir########################
142*cdf0e10cSrcweir
143*cdf0e10cSrcweirsub copy_one_file
144*cdf0e10cSrcweir{
145*cdf0e10cSrcweir	my ($source, $dest) = @_;
146*cdf0e10cSrcweir
147*cdf0e10cSrcweir	my ($copyreturn, $returnvalue, $infoline);
148*cdf0e10cSrcweir
149*cdf0e10cSrcweir	$copyreturn = copy($source, $dest);
150*cdf0e10cSrcweir
151*cdf0e10cSrcweir	if ($copyreturn)
152*cdf0e10cSrcweir	{
153*cdf0e10cSrcweir		$infoline = "Copy: $source to $dest\n";
154*cdf0e10cSrcweir		$returnvalue = 1;
155*cdf0e10cSrcweir	}
156*cdf0e10cSrcweir	else
157*cdf0e10cSrcweir	{
158*cdf0e10cSrcweir		$infoline = "Error: Could not copy $source to $dest\n";
159*cdf0e10cSrcweir		$returnvalue = 0;
160*cdf0e10cSrcweir	}
161*cdf0e10cSrcweir
162*cdf0e10cSrcweir	push(@pre2par::globals::logfileinfo, $infoline);
163*cdf0e10cSrcweir
164*cdf0e10cSrcweir	return $returnvalue;
165*cdf0e10cSrcweir}
166*cdf0e10cSrcweir
167*cdf0e10cSrcweir##########################################
168*cdf0e10cSrcweir# Copying all files from one directory
169*cdf0e10cSrcweir# to another directory
170*cdf0e10cSrcweir##########################################
171*cdf0e10cSrcweir
172*cdf0e10cSrcweirsub copy_directory
173*cdf0e10cSrcweir{
174*cdf0e10cSrcweir	my ($sourcedir, $destdir) = @_;
175*cdf0e10cSrcweir
176*cdf0e10cSrcweir	my ($onefile, $sourcefile, $destfile);
177*cdf0e10cSrcweir	my @sourcefiles = ();
178*cdf0e10cSrcweir
179*cdf0e10cSrcweir	$sourcedir =~ s/\Q$pre2par::globals::separator\E\s*$//;
180*cdf0e10cSrcweir	$destdir =~ s/\Q$pre2par::globals::separator\E\s*$//;
181*cdf0e10cSrcweir
182*cdf0e10cSrcweir	$infoline = "\n";
183*cdf0e10cSrcweir	push(@pre2par::globals::logfileinfo, $infoline);
184*cdf0e10cSrcweir	$infoline = "Copying files from directory $sourcedir to directory $destdir\n";
185*cdf0e10cSrcweir	push(@pre2par::globals::logfileinfo, $infoline);
186*cdf0e10cSrcweir
187*cdf0e10cSrcweir	opendir(DIR, $sourcedir);
188*cdf0e10cSrcweir	@sourcefiles = readdir(DIR);
189*cdf0e10cSrcweir	closedir(DIR);
190*cdf0e10cSrcweir
191*cdf0e10cSrcweir	foreach $onefile (@sourcefiles)
192*cdf0e10cSrcweir	{
193*cdf0e10cSrcweir		if ((!($onefile eq ".")) && (!($onefile eq "..")))
194*cdf0e10cSrcweir		{
195*cdf0e10cSrcweir			$sourcefile = $sourcedir . $pre2par::globals::separator . $onefile;
196*cdf0e10cSrcweir			$destfile = $destdir . $pre2par::globals::separator . $onefile;
197*cdf0e10cSrcweir			if ( -f $sourcefile ) 	# only files, no directories
198*cdf0e10cSrcweir			{
199*cdf0e10cSrcweir				copy_one_file($sourcefile, $destfile);
200*cdf0e10cSrcweir			}
201*cdf0e10cSrcweir		}
202*cdf0e10cSrcweir	}
203*cdf0e10cSrcweir}
204*cdf0e10cSrcweir
205*cdf0e10cSrcweir
206*cdf0e10cSrcweir1;
207