1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: files.pm,v $
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 packager
::files
;
37 ############################################
39 ############################################
47 packager
::exiter
::exit_program
("ERROR: Cannot find file $arg", "check_file");
55 if ( ! open( IN
, $localfile ) ) {
56 # try again - sometimes we get errors caused by race conditions in parallel builds
58 open( IN
, $localfile ) or packager
::exiter
::exit_program
("ERROR: Cannot open file: $localfile", "read_file");
66 ###########################################
68 ###########################################
72 my ($savefile, $savecontent) = @_;
73 open( OUT
, ">$savefile" );
74 print OUT @
{$savecontent};
76 if (! -f
$savefile) { packager
::exiter
::exit_program
("ERROR: Cannot write file: $savefile", "save_file"); }
79 ######################################################
80 # Creating a new direcotory
81 ######################################################
91 $returnvalue = mkdir($directory, 0775);
95 $infoline = "\nCreated directory: $directory\n";
96 push(@packager::globals
::logfileinfo
, $infoline);
98 if ($packager::globals
::isunix
)
100 my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
106 packager
::exiter
::exit_program
("ERROR: Could not create directory: $directory", "create_directory");
111 ######################################################
112 # Creating a unique directory with number extension
113 ######################################################
115 sub create_unique_directory
117 my ($directory) = @_;
119 $directory =~ s/\Q$packager::globals::separator\E\s*$//;
120 $directory = $directory . "_INCREASINGNUMBER";
124 my $localdirectory = "";
128 $localdirectory = $directory;
129 $localdirectory =~ s/INCREASINGNUMBER/$counter/;
132 if ( ! -d
$localdirectory )
134 create_directory
($localdirectory);
138 while ( ! $created );
140 return $localdirectory;
143 ######################################################
144 # Removing a complete directory with subdirectories
145 ######################################################
147 sub remove_complete_directory
149 my ($directory) = @_;
153 $directory =~ s/\Q$packager::globals::separator\E\s*$//;
157 opendir(DIR
, $directory);
158 @content = readdir(DIR
);
163 foreach $oneitem (@content)
165 if ((!($oneitem eq ".")) && (!($oneitem eq "..")))
167 my $item = $directory . $packager::globals
::separator
. $oneitem;
169 if ( -f
$item ) # deleting files
174 if ( -d
$item ) # recursive
176 remove_complete_directory
($item, 0);
181 # try to remove empty directory