merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / modules / pre2par / systemactions.pm
blob80bbd852616921616507675eb2423a972a55964f
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: systemactions.pm,v $
11 # $Revision: 1.6 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
33 package pre2par::systemactions;
35 use File::Copy;
36 use pre2par::exiter;
37 use pre2par::globals;
39 ######################################################
40 # Creating a new direcotory
41 ######################################################
43 sub create_directory
45 my ($directory) = @_;
47 my $returnvalue = 1;
48 my $infoline = "";
50 if ($directory eq "" )
52 return 0;
55 if (!(-d $directory))
57 $returnvalue = mkdir($directory, 0775);
59 if ($returnvalue)
61 $infoline = "Created directory: $directory\n";
62 push(@pre2par::globals::logfileinfo, $infoline);
64 if ($pre2par::globals::isunix)
66 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
67 system($localcall);
70 else
72 # New solution in parallel packing: It is possible, that the directory now exists, although it
73 # was not created in this process. There is only an important error, if the directory does not
74 # exist now.
76 if (!(-d $directory))
78 pre2par::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
80 else
82 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
83 push(@pre2par::globals::logfileinfo, $infoline);
87 else
89 $infoline = "\nAlready existing directory, did not create: $directory\n";
90 push(@pre2par::globals::logfileinfo, $infoline);
94 #######################################################################
95 # Creating the directories, in which files are generated or unzipped
96 #######################################################################
98 sub create_directories
100 my ($directory, $languagesref) =@_;
102 $pre2par::globals::unpackpath =~ s/\Q$pre2par::globals::separator\E\s*$//; # removing ending slashes and backslashes
104 my $path = $pre2par::globals::unpackpath; # this path already exists
106 $path = $path . $pre2par::globals::separator . $pre2par::globals::build . $pre2par::globals::separator;
107 create_directory($path);
109 $path = $path . $pre2par::globals::minor . $pre2par::globals::separator;
110 create_directory($path);
112 if ($directory eq "unzip" )
114 $path = $path . "common" . $pre2par::globals::productextension . $pre2par::globals::separator;
115 create_directory($path);
117 $path = $path . $directory . $pre2par::globals::separator;
118 create_directory($path);
120 else
122 $path = $path . $pre2par::globals::compiler . $pre2par::globals::productextension . $pre2par::globals::separator;
123 create_directory($path);
125 $path = $path . $pre2par::globals::product . $pre2par::globals::separator;
126 create_directory($path);
128 $path = $path . $directory . $pre2par::globals::separator;
129 create_directory($path);
131 if (!($$languagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
133 $path = $path . $$languagesref . $pre2par::globals::separator;
134 create_directory($path);
138 $path =~ s/\Q$pre2par::globals::separator\E\s*$//;
140 return $path;
143 ########################
144 # Copying one file
145 ########################
147 sub copy_one_file
149 my ($source, $dest) = @_;
151 my ($copyreturn, $returnvalue, $infoline);
153 $copyreturn = copy($source, $dest);
155 if ($copyreturn)
157 $infoline = "Copy: $source to $dest\n";
158 $returnvalue = 1;
160 else
162 $infoline = "Error: Could not copy $source to $dest\n";
163 $returnvalue = 0;
166 push(@pre2par::globals::logfileinfo, $infoline);
168 return $returnvalue;
171 ##########################################
172 # Copying all files from one directory
173 # to another directory
174 ##########################################
176 sub copy_directory
178 my ($sourcedir, $destdir) = @_;
180 my ($onefile, $sourcefile, $destfile);
181 my @sourcefiles = ();
183 $sourcedir =~ s/\Q$pre2par::globals::separator\E\s*$//;
184 $destdir =~ s/\Q$pre2par::globals::separator\E\s*$//;
186 $infoline = "\n";
187 push(@pre2par::globals::logfileinfo, $infoline);
188 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
189 push(@pre2par::globals::logfileinfo, $infoline);
191 opendir(DIR, $sourcedir);
192 @sourcefiles = readdir(DIR);
193 closedir(DIR);
195 foreach $onefile (@sourcefiles)
197 if ((!($onefile eq ".")) && (!($onefile eq "..")))
199 $sourcefile = $sourcedir . $pre2par::globals::separator . $onefile;
200 $destfile = $destdir . $pre2par::globals::separator . $onefile;
201 if ( -f $sourcefile ) # only files, no directories
203 copy_one_file($sourcefile, $destfile);