1*9780544fSAndrew Rist#************************************************************** 2*9780544fSAndrew Rist# 3*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 5*9780544fSAndrew Rist# distributed with this work for additional information 6*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 8*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 9*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10*9780544fSAndrew Rist# 11*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 14*9780544fSAndrew Rist# software distributed under the License is distributed on an 15*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 17*9780544fSAndrew Rist# specific language governing permissions and limitations 18*9780544fSAndrew Rist# under the License. 19*9780544fSAndrew Rist# 20*9780544fSAndrew Rist#************************************************************** 21*9780544fSAndrew Rist 22*9780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweirpackage pre2par::systemactions; 26cdf0e10cSrcweir 27cdf0e10cSrcweiruse File::Copy; 28cdf0e10cSrcweiruse pre2par::exiter; 29cdf0e10cSrcweiruse pre2par::globals; 30cdf0e10cSrcweir 31cdf0e10cSrcweir###################################################### 32cdf0e10cSrcweir# Creating a new direcotory 33cdf0e10cSrcweir###################################################### 34cdf0e10cSrcweir 35cdf0e10cSrcweirsub create_directory 36cdf0e10cSrcweir{ 37cdf0e10cSrcweir my ($directory) = @_; 38cdf0e10cSrcweir 39cdf0e10cSrcweir my $returnvalue = 1; 40cdf0e10cSrcweir my $infoline = ""; 41cdf0e10cSrcweir 42cdf0e10cSrcweir if ($directory eq "" ) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir return 0; 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir if (!(-d $directory)) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir $returnvalue = mkdir($directory, 0775); 50cdf0e10cSrcweir 51cdf0e10cSrcweir if ($returnvalue) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir $infoline = "Created directory: $directory\n"; 54cdf0e10cSrcweir push(@pre2par::globals::logfileinfo, $infoline); 55cdf0e10cSrcweir 56cdf0e10cSrcweir if ($pre2par::globals::isunix) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1"; 59cdf0e10cSrcweir system($localcall); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir } 62cdf0e10cSrcweir else 63cdf0e10cSrcweir { 64cdf0e10cSrcweir # New solution in parallel packing: It is possible, that the directory now exists, although it 65cdf0e10cSrcweir # was not created in this process. There is only an important error, if the directory does not 66cdf0e10cSrcweir # exist now. 67cdf0e10cSrcweir 68cdf0e10cSrcweir if (!(-d $directory)) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir pre2par::exiter::exit_program("Error: Could not create directory: $directory", "create_directory"); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir else 73cdf0e10cSrcweir { 74cdf0e10cSrcweir $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n"; 75cdf0e10cSrcweir push(@pre2par::globals::logfileinfo, $infoline); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir else 80cdf0e10cSrcweir { 81cdf0e10cSrcweir $infoline = "\nAlready existing directory, did not create: $directory\n"; 82cdf0e10cSrcweir push(@pre2par::globals::logfileinfo, $infoline); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir} 85cdf0e10cSrcweir 86cdf0e10cSrcweir####################################################################### 87cdf0e10cSrcweir# Creating the directories, in which files are generated or unzipped 88cdf0e10cSrcweir####################################################################### 89cdf0e10cSrcweir 90cdf0e10cSrcweirsub create_directories 91cdf0e10cSrcweir{ 92cdf0e10cSrcweir my ($directory, $languagesref) =@_; 93cdf0e10cSrcweir 94cdf0e10cSrcweir $pre2par::globals::unpackpath =~ s/\Q$pre2par::globals::separator\E\s*$//; # removing ending slashes and backslashes 95cdf0e10cSrcweir 96cdf0e10cSrcweir my $path = $pre2par::globals::unpackpath; # this path already exists 97cdf0e10cSrcweir 98cdf0e10cSrcweir $path = $path . $pre2par::globals::separator . $pre2par::globals::build . $pre2par::globals::separator; 99cdf0e10cSrcweir create_directory($path); 100cdf0e10cSrcweir 101cdf0e10cSrcweir $path = $path . $pre2par::globals::minor . $pre2par::globals::separator; 102cdf0e10cSrcweir create_directory($path); 103cdf0e10cSrcweir 104cdf0e10cSrcweir if ($directory eq "unzip" ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir $path = $path . "common" . $pre2par::globals::productextension . $pre2par::globals::separator; 107cdf0e10cSrcweir create_directory($path); 108cdf0e10cSrcweir 109cdf0e10cSrcweir $path = $path . $directory . $pre2par::globals::separator; 110cdf0e10cSrcweir create_directory($path); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir else 113cdf0e10cSrcweir { 114cdf0e10cSrcweir $path = $path . $pre2par::globals::compiler . $pre2par::globals::productextension . $pre2par::globals::separator; 115cdf0e10cSrcweir create_directory($path); 116cdf0e10cSrcweir 117cdf0e10cSrcweir $path = $path . $pre2par::globals::product . $pre2par::globals::separator; 118cdf0e10cSrcweir create_directory($path); 119cdf0e10cSrcweir 120cdf0e10cSrcweir $path = $path . $directory . $pre2par::globals::separator; 121cdf0e10cSrcweir create_directory($path); 122cdf0e10cSrcweir 123cdf0e10cSrcweir if (!($$languagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files 124cdf0e10cSrcweir { 125cdf0e10cSrcweir $path = $path . $$languagesref . $pre2par::globals::separator; 126cdf0e10cSrcweir create_directory($path); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir $path =~ s/\Q$pre2par::globals::separator\E\s*$//; 131cdf0e10cSrcweir 132cdf0e10cSrcweir return $path; 133cdf0e10cSrcweir} 134cdf0e10cSrcweir 135cdf0e10cSrcweir######################## 136cdf0e10cSrcweir# Copying one file 137cdf0e10cSrcweir######################## 138cdf0e10cSrcweir 139cdf0e10cSrcweirsub copy_one_file 140cdf0e10cSrcweir{ 141cdf0e10cSrcweir my ($source, $dest) = @_; 142cdf0e10cSrcweir 143cdf0e10cSrcweir my ($copyreturn, $returnvalue, $infoline); 144cdf0e10cSrcweir 145cdf0e10cSrcweir $copyreturn = copy($source, $dest); 146cdf0e10cSrcweir 147cdf0e10cSrcweir if ($copyreturn) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir $infoline = "Copy: $source to $dest\n"; 150cdf0e10cSrcweir $returnvalue = 1; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir else 153cdf0e10cSrcweir { 154cdf0e10cSrcweir $infoline = "Error: Could not copy $source to $dest\n"; 155cdf0e10cSrcweir $returnvalue = 0; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir push(@pre2par::globals::logfileinfo, $infoline); 159cdf0e10cSrcweir 160cdf0e10cSrcweir return $returnvalue; 161cdf0e10cSrcweir} 162cdf0e10cSrcweir 163cdf0e10cSrcweir########################################## 164cdf0e10cSrcweir# Copying all files from one directory 165cdf0e10cSrcweir# to another directory 166cdf0e10cSrcweir########################################## 167cdf0e10cSrcweir 168cdf0e10cSrcweirsub copy_directory 169cdf0e10cSrcweir{ 170cdf0e10cSrcweir my ($sourcedir, $destdir) = @_; 171cdf0e10cSrcweir 172cdf0e10cSrcweir my ($onefile, $sourcefile, $destfile); 173cdf0e10cSrcweir my @sourcefiles = (); 174cdf0e10cSrcweir 175cdf0e10cSrcweir $sourcedir =~ s/\Q$pre2par::globals::separator\E\s*$//; 176cdf0e10cSrcweir $destdir =~ s/\Q$pre2par::globals::separator\E\s*$//; 177cdf0e10cSrcweir 178cdf0e10cSrcweir $infoline = "\n"; 179cdf0e10cSrcweir push(@pre2par::globals::logfileinfo, $infoline); 180cdf0e10cSrcweir $infoline = "Copying files from directory $sourcedir to directory $destdir\n"; 181cdf0e10cSrcweir push(@pre2par::globals::logfileinfo, $infoline); 182cdf0e10cSrcweir 183cdf0e10cSrcweir opendir(DIR, $sourcedir); 184cdf0e10cSrcweir @sourcefiles = readdir(DIR); 185cdf0e10cSrcweir closedir(DIR); 186cdf0e10cSrcweir 187cdf0e10cSrcweir foreach $onefile (@sourcefiles) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir if ((!($onefile eq ".")) && (!($onefile eq ".."))) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir $sourcefile = $sourcedir . $pre2par::globals::separator . $onefile; 192cdf0e10cSrcweir $destfile = $destdir . $pre2par::globals::separator . $onefile; 193cdf0e10cSrcweir if ( -f $sourcefile ) # only files, no directories 194cdf0e10cSrcweir { 195cdf0e10cSrcweir copy_one_file($sourcefile, $destfile); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir } 198cdf0e10cSrcweir } 199cdf0e10cSrcweir} 200cdf0e10cSrcweir 201cdf0e10cSrcweir 202cdf0e10cSrcweir1; 203