Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / par2script / systemactions.pm
blob7c9ecbe90fbb3a1a00c27b27b683cdeb29ad31e6
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 package par2script::systemactions;
22 use File::Copy;
23 use par2script::exiter;
24 use par2script::globals;
26 ######################################################
27 # Creating a new direcotory
28 ######################################################
30 sub create_directory
32 my ($directory) = @_;
34 my $returnvalue = 1;
36 if (!(-d $directory))
38 $returnvalue = mkdir($directory, 0775);
40 if ($returnvalue)
42 $infoline = "Created directory: $directory\n";
43 push(@par2script::globals::logfileinfo, $infoline);
45 if ($par2script::globals::isunix)
47 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
48 system($localcall);
51 else
53 par2script::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
58 #######################################################################
59 # Creating the directories, in which files are generated or unzipped
60 #######################################################################
62 sub create_directories
64 my ($directory, $languagesref) =@_;
66 $par2script::globals::unpackpath =~ s/\Q$par2script::globals::separator\E\s*$//; # removing ending slashes and backslashes
68 my $path = $par2script::globals::unpackpath; # this path already exists
70 $path = $path . $par2script::globals::separator . $par2script::globals::build . $par2script::globals::separator;
71 create_directory($path);
73 $path = $path . $par2script::globals::minor . $par2script::globals::separator;
74 create_directory($path);
76 if ($directory eq "unzip" )
79 else
81 $path = $path . $par2script::globals::platformid . $par2script::globals::separator;
82 create_directory($path);
84 $path = $path . $par2script::globals::product . $par2script::globals::separator;
85 create_directory($path);
87 $path = $path . $directory . $par2script::globals::separator;
88 create_directory($path);
90 if (!($$languagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
92 $path = $path . $$languagesref . $par2script::globals::separator;
93 create_directory($path);
97 $path =~ s/\Q$par2script::globals::separator\E\s*$//;
99 return $path;
102 ########################
103 # Copying one file
104 ########################
106 sub copy_one_file
108 my ($source, $dest) = @_;
110 my ($copyreturn, $returnvalue);
111 my $infoline;
113 $copyreturn = copy($source, $dest);
115 if ($copyreturn)
117 $infoline = "Copy: $source to $dest\n";
118 $returnvalue = 1;
120 else
122 $infoline = "Error: Could not copy $source to $dest $!\n";
123 $returnvalue = 0;
126 push(@par2script::globals::logfileinfo, $infoline);
128 return $returnvalue;
131 ##########################################
132 # Copying all files from one directory
133 # to another directory
134 ##########################################
136 sub copy_directory
138 my ($sourcedir, $destdir) = @_;
140 my ($onefile, $sourcefile, $destfile);
141 my @sourcefiles = ();
143 $sourcedir =~ s/\Q$par2script::globals::separator\E\s*$//;
144 $destdir =~ s/\Q$par2script::globals::separator\E\s*$//;
146 $infoline = "\n";
147 push(@par2script::globals::logfileinfo, $infoline);
148 $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
149 push(@par2script::globals::logfileinfo, $infoline);
151 opendir(DIR, $sourcedir);
152 @sourcefiles = readdir(DIR);
153 closedir(DIR);
155 foreach $onefile (@sourcefiles)
157 if ((!($onefile eq ".")) && (!($onefile eq "..")))
159 $sourcefile = $sourcedir . $par2script::globals::separator . $onefile;
160 $destfile = $destdir . $par2script::globals::separator . $onefile;
161 if ( -f $sourcefile ) # only files, no directories
163 copy_one_file($sourcefile, $destfile);