Update ooo320-m1
[ooovba.git] / solenv / bin / modules / par2script / systemactions.pm
blob311585eb73f44b12b154f23ae1a510df8d13d9bf
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.5 $
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 par2script::systemactions;
35 use File::Copy;
36 use par2script::exiter;
37 use par2script::globals;
39 ######################################################
40 # Creating a new direcotory
41 ######################################################
43 sub create_directory
45 my ($directory) = @_;
47 my $returnvalue = 1;
49 if (!(-d $directory))
51 $returnvalue = mkdir($directory, 0775);
53 if ($returnvalue)
55 $infoline = "Created directory: $directory\n";
56 push(@par2script::globals::logfileinfo, $infoline);
58 if ($par2script::globals::isunix)
60 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
61 system($localcall);
64 else
66 par2script::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
71 #######################################################################
72 # Creating the directories, in which files are generated or unzipped
73 #######################################################################
75 sub create_directories
77 my ($directory, $languagesref) =@_;
79 $par2script::globals::unpackpath =~ s/\Q$par2script::globals::separator\E\s*$//; # removing ending slashes and backslashes
81 my $path = $par2script::globals::unpackpath; # this path already exists
83 $path = $path . $par2script::globals::separator . $par2script::globals::build . $par2script::globals::separator;
84 create_directory($path);
86 $path = $path . $par2script::globals::minor . $par2script::globals::separator;
87 create_directory($path);
89 if ($directory eq "unzip" )
91 $path = $path . "common" . $par2script::globals::productextension . $par2script::globals::separator;
92 create_directory($path);
94 $path = $path . $directory . $par2script::globals::separator;
95 create_directory($path);
97 else
99 $path = $path . $par2script::globals::compiler . $par2script::globals::productextension . $par2script::globals::separator;
100 create_directory($path);
102 $path = $path . $par2script::globals::product . $par2script::globals::separator;
103 create_directory($path);
105 $path = $path . $directory . $par2script::globals::separator;
106 create_directory($path);
108 if (!($$languagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
110 $path = $path . $$languagesref . $par2script::globals::separator;
111 create_directory($path);
115 $path =~ s/\Q$par2script::globals::separator\E\s*$//;
117 return $path;
120 ########################
121 # Copying one file
122 ########################
124 sub copy_one_file
126 my ($source, $dest) = @_;
128 my ($copyreturn, $returnvalue);
129 my $infoline;
131 $copyreturn = copy($source, $dest);
133 if ($copyreturn)
135 $infoline = "Copy: $source to $dest\n";
136 $returnvalue = 1;
138 else
140 $infoline = "Error: Could not copy $source to $dest\n";
141 $returnvalue = 0;
144 push(@par2script::globals::logfileinfo, $infoline);
146 return $returnvalue;
149 ##########################################
150 # Copying all files from one directory
151 # to another directory
152 ##########################################
154 sub copy_directory
156 my ($sourcedir, $destdir) = @_;
158 my ($onefile, $sourcefile, $destfile);
159 my @sourcefiles = ();
161 $sourcedir =~ s/\Q$par2script::globals::separator\E\s*$//;
162 $destdir =~ s/\Q$par2script::globals::separator\E\s*$//;
164 $infoline = "\n";
165 push(@par2script::globals::logfileinfo, $infoline);
166 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
167 push(@par2script::globals::logfileinfo, $infoline);
169 opendir(DIR, $sourcedir);
170 @sourcefiles = readdir(DIR);
171 closedir(DIR);
173 foreach $onefile (@sourcefiles)
175 if ((!($onefile eq ".")) && (!($onefile eq "..")))
177 $sourcefile = $sourcedir . $par2script::globals::separator . $onefile;
178 $destfile = $destdir . $par2script::globals::separator . $onefile;
179 if ( -f $sourcefile ) # only files, no directories
181 copy_one_file($sourcefile, $destfile);