update dev300-m58
[ooovba.git] / solenv / bin / modules / pre2par / systemactions.pm
blobde1084bcb8f217c9ae4bb2a604ac5156e88b1761
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 (!(-d $directory))
52 $returnvalue = mkdir($directory, 0775);
54 if ($returnvalue)
56 $infoline = "Created directory: $directory\n";
57 push(@pre2par::globals::logfileinfo, $infoline);
59 if ($pre2par::globals::isunix)
61 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
62 system($localcall);
65 else
67 # New solution in parallel packing: It is possible, that the directory now exists, although it
68 # was not created in this process. There is only an important error, if the directory does not
69 # exist now.
71 if (!(-d $directory))
73 pre2par::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
75 else
77 $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
78 push(@pre2par::globals::logfileinfo, $infoline);
82 else
84 $infoline = "\nAlready existing directory, did not create: $directory\n";
85 push(@pre2par::globals::logfileinfo, $infoline);
89 #######################################################################
90 # Creating the directories, in which files are generated or unzipped
91 #######################################################################
93 sub create_directories
95 my ($directory, $languagesref) =@_;
97 $pre2par::globals::unpackpath =~ s/\Q$pre2par::globals::separator\E\s*$//; # removing ending slashes and backslashes
99 my $path = $pre2par::globals::unpackpath; # this path already exists
101 $path = $path . $pre2par::globals::separator . $pre2par::globals::build . $pre2par::globals::separator;
102 create_directory($path);
104 $path = $path . $pre2par::globals::minor . $pre2par::globals::separator;
105 create_directory($path);
107 if ($directory eq "unzip" )
109 $path = $path . "common" . $pre2par::globals::productextension . $pre2par::globals::separator;
110 create_directory($path);
112 $path = $path . $directory . $pre2par::globals::separator;
113 create_directory($path);
115 else
117 $path = $path . $pre2par::globals::compiler . $pre2par::globals::productextension . $pre2par::globals::separator;
118 create_directory($path);
120 $path = $path . $pre2par::globals::product . $pre2par::globals::separator;
121 create_directory($path);
123 $path = $path . $directory . $pre2par::globals::separator;
124 create_directory($path);
126 if (!($$languagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
128 $path = $path . $$languagesref . $pre2par::globals::separator;
129 create_directory($path);
133 $path =~ s/\Q$pre2par::globals::separator\E\s*$//;
135 return $path;
138 ########################
139 # Copying one file
140 ########################
142 sub copy_one_file
144 my ($source, $dest) = @_;
146 my ($copyreturn, $returnvalue, $infoline);
148 $copyreturn = copy($source, $dest);
150 if ($copyreturn)
152 $infoline = "Copy: $source to $dest\n";
153 $returnvalue = 1;
155 else
157 $infoline = "Error: Could not copy $source to $dest\n";
158 $returnvalue = 0;
161 push(@pre2par::globals::logfileinfo, $infoline);
163 return $returnvalue;
166 ##########################################
167 # Copying all files from one directory
168 # to another directory
169 ##########################################
171 sub copy_directory
173 my ($sourcedir, $destdir) = @_;
175 my ($onefile, $sourcefile, $destfile);
176 my @sourcefiles = ();
178 $sourcedir =~ s/\Q$pre2par::globals::separator\E\s*$//;
179 $destdir =~ s/\Q$pre2par::globals::separator\E\s*$//;
181 $infoline = "\n";
182 push(@pre2par::globals::logfileinfo, $infoline);
183 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
184 push(@pre2par::globals::logfileinfo, $infoline);
186 opendir(DIR, $sourcedir);
187 @sourcefiles = readdir(DIR);
188 closedir(DIR);
190 foreach $onefile (@sourcefiles)
192 if ((!($onefile eq ".")) && (!($onefile eq "..")))
194 $sourcefile = $sourcedir . $pre2par::globals::separator . $onefile;
195 $destfile = $destdir . $pre2par::globals::separator . $onefile;
196 if ( -f $sourcefile ) # only files, no directories
198 copy_one_file($sourcefile, $destfile);