xref: /trunk/main/solenv/bin/modules/pre2par/systemactions.pm (revision fc9fd3f14a55d77b35643a64034752a178b2a5b0)
1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28
29package pre2par::systemactions;
30
31use File::Copy;
32use pre2par::exiter;
33use pre2par::globals;
34
35######################################################
36# Creating a new direcotory
37######################################################
38
39sub create_directory
40{
41    my ($directory) = @_;
42
43    my $returnvalue = 1;
44    my $infoline = "";
45
46    if ($directory eq "" )
47    {
48        return 0;
49    }
50
51    if (!(-d $directory))
52    {
53        $returnvalue = mkdir($directory, 0775);
54
55        if ($returnvalue)
56        {
57            $infoline = "Created directory: $directory\n";
58            push(@pre2par::globals::logfileinfo, $infoline);
59
60            if ($pre2par::globals::isunix)
61            {
62                my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
63                system($localcall);
64            }
65        }
66        else
67        {
68            # New solution in parallel packing: It is possible, that the directory now exists, although it
69            # was not created in this process. There is only an important error, if the directory does not
70            # exist now.
71
72            if (!(-d $directory))
73            {
74                pre2par::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
75            }
76            else
77            {
78                $infoline = "\nAnother process created this directory in exactly this moment :-) : $directory\n";
79                push(@pre2par::globals::logfileinfo, $infoline);
80            }
81        }
82    }
83    else
84    {
85        $infoline = "\nAlready existing directory, did not create: $directory\n";
86        push(@pre2par::globals::logfileinfo, $infoline);
87    }
88}
89
90#######################################################################
91# Creating the directories, in which files are generated or unzipped
92#######################################################################
93
94sub create_directories
95{
96    my ($directory, $languagesref) =@_;
97
98    $pre2par::globals::unpackpath =~ s/\Q$pre2par::globals::separator\E\s*$//;  # removing ending slashes and backslashes
99
100    my $path = $pre2par::globals::unpackpath;    # this path already exists
101
102    $path = $path . $pre2par::globals::separator . $pre2par::globals::build . $pre2par::globals::separator;
103    create_directory($path);
104
105    $path = $path . $pre2par::globals::minor . $pre2par::globals::separator;
106    create_directory($path);
107
108    if ($directory eq "unzip" )
109    {
110        $path = $path . "common" . $pre2par::globals::productextension . $pre2par::globals::separator;
111        create_directory($path);
112
113        $path = $path . $directory . $pre2par::globals::separator;
114        create_directory($path);
115    }
116    else
117    {
118        $path = $path . $pre2par::globals::compiler . $pre2par::globals::productextension . $pre2par::globals::separator;
119        create_directory($path);
120
121        $path = $path . $pre2par::globals::product . $pre2par::globals::separator;
122        create_directory($path);
123
124        $path = $path . $directory . $pre2par::globals::separator;
125        create_directory($path);
126
127        if (!($$languagesref eq "" ))   # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
128        {
129            $path = $path . $$languagesref . $pre2par::globals::separator;
130            create_directory($path);
131        }
132    }
133
134    $path =~ s/\Q$pre2par::globals::separator\E\s*$//;
135
136    return $path;
137}
138
139########################
140# Copying one file
141########################
142
143sub copy_one_file
144{
145    my ($source, $dest) = @_;
146
147    my ($copyreturn, $returnvalue, $infoline);
148
149    $copyreturn = copy($source, $dest);
150
151    if ($copyreturn)
152    {
153        $infoline = "Copy: $source to $dest\n";
154        $returnvalue = 1;
155    }
156    else
157    {
158        $infoline = "Error: Could not copy $source to $dest\n";
159        $returnvalue = 0;
160    }
161
162    push(@pre2par::globals::logfileinfo, $infoline);
163
164    return $returnvalue;
165}
166
167##########################################
168# Copying all files from one directory
169# to another directory
170##########################################
171
172sub copy_directory
173{
174    my ($sourcedir, $destdir) = @_;
175
176    my ($onefile, $sourcefile, $destfile);
177    my @sourcefiles = ();
178
179    $sourcedir =~ s/\Q$pre2par::globals::separator\E\s*$//;
180    $destdir =~ s/\Q$pre2par::globals::separator\E\s*$//;
181
182    $infoline = "\n";
183    push(@pre2par::globals::logfileinfo, $infoline);
184    $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
185    push(@pre2par::globals::logfileinfo, $infoline);
186
187    opendir(DIR, $sourcedir);
188    @sourcefiles = readdir(DIR);
189    closedir(DIR);
190
191    foreach $onefile (@sourcefiles)
192    {
193        if ((!($onefile eq ".")) && (!($onefile eq "..")))
194        {
195            $sourcefile = $sourcedir . $pre2par::globals::separator . $onefile;
196            $destfile = $destdir . $pre2par::globals::separator . $onefile;
197            if ( -f $sourcefile )   # only files, no directories
198            {
199                copy_one_file($sourcefile, $destfile);
200            }
201        }
202    }
203}
204
205
2061;
207