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