xref: /trunk/main/solenv/bin/modules/par2script/systemactions.pm (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 par2script::systemactions;
30
31use File::Copy;
32use par2script::exiter;
33use par2script::globals;
34
35######################################################
36# Creating a new direcotory
37######################################################
38
39sub create_directory
40{
41    my ($directory) = @_;
42
43    my $returnvalue = 1;
44
45    if (!(-d $directory))
46    {
47        $returnvalue = mkdir($directory, 0775);
48
49        if ($returnvalue)
50        {
51            $infoline = "Created directory: $directory\n";
52            push(@par2script::globals::logfileinfo, $infoline);
53
54            if ($par2script::globals::isunix)
55            {
56                my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1";
57                system($localcall);
58            }
59        }
60        else
61        {
62            par2script::exiter::exit_program("Error: Could not create directory: $directory", "create_directory");
63        }
64    }
65}
66
67#######################################################################
68# Creating the directories, in which files are generated or unzipped
69#######################################################################
70
71sub create_directories
72{
73    my ($directory, $languagesref) =@_;
74
75    $par2script::globals::unpackpath =~ s/\Q$par2script::globals::separator\E\s*$//;    # removing ending slashes and backslashes
76
77    my $path = $par2script::globals::unpackpath;     # this path already exists
78
79    $path = $path . $par2script::globals::separator . $par2script::globals::build . $par2script::globals::separator;
80    create_directory($path);
81
82    $path = $path . $par2script::globals::minor . $par2script::globals::separator;
83    create_directory($path);
84
85    if ($directory eq "unzip" )
86    {
87        $path = $path . "common" . $par2script::globals::productextension . $par2script::globals::separator;
88        create_directory($path);
89
90        $path = $path . $directory . $par2script::globals::separator;
91        create_directory($path);
92    }
93    else
94    {
95        $path = $path . $par2script::globals::compiler . $par2script::globals::productextension . $par2script::globals::separator;
96        create_directory($path);
97
98        $path = $path . $par2script::globals::product . $par2script::globals::separator;
99        create_directory($path);
100
101        $path = $path . $directory . $par2script::globals::separator;
102        create_directory($path);
103
104        if (!($$languagesref eq "" ))   # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files
105        {
106            $path = $path . $$languagesref . $par2script::globals::separator;
107            create_directory($path);
108        }
109    }
110
111    $path =~ s/\Q$par2script::globals::separator\E\s*$//;
112
113    return $path;
114}
115
116########################
117# Copying one file
118########################
119
120sub copy_one_file
121{
122    my ($source, $dest) = @_;
123
124    my ($copyreturn, $returnvalue);
125    my $infoline;
126
127    $copyreturn = copy($source, $dest);
128
129    if ($copyreturn)
130    {
131        $infoline = "Copy: $source to $dest\n";
132        $returnvalue = 1;
133    }
134    else
135    {
136        $infoline = "Error: Could not copy $source to $dest\n";
137        $returnvalue = 0;
138    }
139
140    push(@par2script::globals::logfileinfo, $infoline);
141
142    return $returnvalue;
143}
144
145##########################################
146# Copying all files from one directory
147# to another directory
148##########################################
149
150sub copy_directory
151{
152    my ($sourcedir, $destdir) = @_;
153
154    my ($onefile, $sourcefile, $destfile);
155    my @sourcefiles = ();
156
157    $sourcedir =~ s/\Q$par2script::globals::separator\E\s*$//;
158    $destdir =~ s/\Q$par2script::globals::separator\E\s*$//;
159
160    $infoline = "\n";
161    push(@par2script::globals::logfileinfo, $infoline);
162    $infoline = "Copying files from directory $sourcedir to directory $destdir\n";
163    push(@par2script::globals::logfileinfo, $infoline);
164
165    opendir(DIR, $sourcedir);
166    @sourcefiles = readdir(DIR);
167    closedir(DIR);
168
169    foreach $onefile (@sourcefiles)
170    {
171        if ((!($onefile eq ".")) && (!($onefile eq "..")))
172        {
173            $sourcefile = $sourcedir . $par2script::globals::separator . $onefile;
174            $destfile = $destdir . $par2script::globals::separator . $onefile;
175            if ( -f $sourcefile )   # only files, no directories
176            {
177                copy_one_file($sourcefile, $destfile);
178            }
179        }
180    }
181}
182
183
1841;
185