602
|
1 |
# Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
#
|
|
15 |
#
|
|
16 |
# Description:
|
|
17 |
# RemoteSite::NetDrive::MultiVolumeExport.pm
|
|
18 |
#
|
|
19 |
|
|
20 |
package RemoteSite::NetDrive::MultiVolumeExport;
|
|
21 |
|
|
22 |
use strict;
|
|
23 |
use File::Copy;
|
|
24 |
use File::Basename;
|
|
25 |
|
|
26 |
use RemoteSite;
|
|
27 |
use RemoteSite::NetDrive;
|
|
28 |
use vars qw(@ISA);
|
|
29 |
@ISA=("RemoteSite::NetDrive");
|
|
30 |
|
|
31 |
|
|
32 |
#
|
|
33 |
# Constants,
|
|
34 |
#
|
|
35 |
|
|
36 |
use constant KLogDirName => '\sent_log';
|
|
37 |
|
|
38 |
|
|
39 |
#
|
|
40 |
# Initialization
|
|
41 |
#
|
|
42 |
|
|
43 |
sub Initialize {
|
|
44 |
my $self = shift;
|
|
45 |
my %args = @_;
|
|
46 |
$self->{maxExportVolumeSize} = $args{max_export_volume_size};
|
|
47 |
$self->SUPER::Initialize(@_);
|
|
48 |
$self->Connect();
|
|
49 |
$self->InitNextExportVolume();
|
|
50 |
}
|
|
51 |
|
|
52 |
|
|
53 |
#
|
|
54 |
# Public (from RemoteSite)
|
|
55 |
#
|
|
56 |
|
|
57 |
sub SendFile {
|
|
58 |
my $self = shift;
|
|
59 |
my $localFile = shift;
|
|
60 |
my $remoteFile = shift;
|
|
61 |
|
|
62 |
unless ($localFile and $remoteFile) {
|
|
63 |
$self->HandleError("Incorrect args passed to ".ref($self)."::SendFile");
|
|
64 |
}
|
|
65 |
unless (-e $localFile) {
|
|
66 |
$self->HandleError("Local file $localFile does not exist");
|
|
67 |
}
|
|
68 |
|
|
69 |
my $fileSize = Utils::FileSize($localFile);
|
|
70 |
if ($fileSize > $self->{maxExportVolumeSize}) {
|
|
71 |
die "Error: \"$localFile\" is larger than the maximum export volume size ($self->{maxExportVolumeSize})\n";
|
|
72 |
}
|
|
73 |
$self->{currentExportVolumeSize} += $fileSize;
|
|
74 |
if ($self->{currentExportVolumeSize} > $self->{maxExportVolumeSize}) {
|
|
75 |
$self->InitNextExportVolume();
|
|
76 |
$self->{currentExportVolumeSize} = $fileSize;
|
|
77 |
}
|
|
78 |
$self->SUPER::SendFile($localFile, Utils::ConcatenateDirNames($self->CurrentExportVolumeName(), $remoteFile));
|
|
79 |
$self->WriteIndexEntry($remoteFile);
|
|
80 |
}
|
|
81 |
|
|
82 |
sub GetFile {
|
|
83 |
my $self = shift;
|
|
84 |
$self->HandleError("Function 'GetFile' not supported by ".ref($self)."\n");
|
|
85 |
}
|
|
86 |
|
|
87 |
sub FileExists {
|
|
88 |
my $self = shift;
|
|
89 |
my $remoteFile = shift;
|
|
90 |
unless (defined $remoteFile) {
|
|
91 |
return 0;
|
|
92 |
}
|
|
93 |
$self->Connect();
|
|
94 |
$remoteFile = Utils::ConcatenateDirNames($self->LogDir(), $remoteFile);
|
|
95 |
return (-e $remoteFile);
|
|
96 |
}
|
|
97 |
|
|
98 |
sub DirList {
|
|
99 |
my $self = shift;
|
|
100 |
$self->HandleError("Function 'DirList' not supported by ".ref($self)."\n");
|
|
101 |
}
|
|
102 |
|
|
103 |
sub MakeDir {
|
|
104 |
my $self = shift;
|
|
105 |
$self->HandleError("Function 'MakeDir' not supported by ".ref($self)."\n");
|
|
106 |
}
|
|
107 |
|
|
108 |
sub FileSize {
|
|
109 |
my $self = shift;
|
|
110 |
my $file = shift;
|
|
111 |
my $volume = $self->LookupIndexEntry($file);
|
|
112 |
my $fullName = Utils::ConcatenateDirNames($self->Host(), $self->ExportVolumeName($volume));
|
|
113 |
$fullName = Utils::ConcatenateDirNames($fullName, $file);
|
|
114 |
return Utils::FileSize($fullName);
|
|
115 |
}
|
|
116 |
|
|
117 |
sub DeleteFile {
|
|
118 |
my $self = shift;
|
|
119 |
$self->HandleError("Function 'DeleteFile' not supported by ".ref($self)."\n");
|
|
120 |
}
|
|
121 |
|
|
122 |
sub MoveFile {
|
|
123 |
my $self = shift;
|
|
124 |
$self->HandleError("Function 'MoveFile' not supported by ".ref($self)."\n");
|
|
125 |
}
|
|
126 |
|
|
127 |
sub FileModifiedTime {
|
|
128 |
my $self = shift;
|
|
129 |
$self->HandleError("Function 'FileModifiedTime' not supported by ".ref($self)."\n");
|
|
130 |
}
|
|
131 |
|
|
132 |
|
|
133 |
#
|
|
134 |
# Private.
|
|
135 |
#
|
|
136 |
|
|
137 |
sub SetExportVolumePrefix {
|
|
138 |
my $self = shift;
|
|
139 |
$self->{exportVolumePrefex} = time . '__#';
|
|
140 |
}
|
|
141 |
|
|
142 |
sub CurrentExportVolumeName {
|
|
143 |
my $self = shift;
|
|
144 |
return $self->ExportVolumeName($self->{currentExportVolume});
|
|
145 |
}
|
|
146 |
|
|
147 |
sub ExportVolumeName {
|
|
148 |
my $self = shift;
|
|
149 |
my $volume = shift;
|
|
150 |
my $name = "$self->{exportVolumePrefex}$volume";
|
|
151 |
Utils::TidyFileName(\$name);
|
|
152 |
return $name;
|
|
153 |
}
|
|
154 |
|
|
155 |
sub LookupIndexEntry {
|
|
156 |
my $self = shift;
|
|
157 |
my $file = lc(shift);
|
|
158 |
Utils::TidyFileName(\$file);
|
|
159 |
if (exists $self->{index}->{$file}) {
|
|
160 |
return $self->{index}->{$file};
|
|
161 |
}
|
|
162 |
return undef;
|
|
163 |
}
|
|
164 |
|
|
165 |
sub WriteIndexEntry {
|
|
166 |
# Index entries keep track of which volume of a set a particular release may be found in.
|
|
167 |
my $self = shift;
|
|
168 |
my $file = lc(shift);
|
|
169 |
Utils::TidyFileName(\$file);
|
|
170 |
$self->WriteLogEntry($file);
|
|
171 |
$self->{index}->{$file} = $self->{currentExportVolume};
|
|
172 |
}
|
|
173 |
|
|
174 |
sub WriteLogEntry {
|
|
175 |
# Log entries keep track of what has been sent. KLogDirName should not be deleted between exports.
|
|
176 |
my $self = shift;
|
|
177 |
my $file = shift;
|
|
178 |
$file = Utils::ConcatenateDirNames($self->LogDir(), $file);
|
|
179 |
Utils::MakeDir(dirname($file));
|
|
180 |
$self->WriteLogReadMe();
|
|
181 |
open (LOG, ">$file") or die "Error: Unable to write log entry \"$file\": $!\n";
|
|
182 |
close (LOG);
|
|
183 |
}
|
|
184 |
|
|
185 |
sub WriteLogReadMe {
|
|
186 |
my $self = shift;
|
|
187 |
my $readMe = Utils::ConcatenateDirNames($self->LogDir(), 'readme.txt');
|
|
188 |
unless (-e $readMe) {
|
|
189 |
open (README, ">$readMe") or die "Error: Couldn't open \"$readMe\" for writing: $!\n";
|
|
190 |
print README "This directory contains a log automatically written by the LPD Release Tools as a result of one
|
|
191 |
or more exports being performed to a remote site of type 'multi-volume'. It's purpose is to keep track of which
|
|
192 |
component releases have already been exported, so they don't get sent again. If you delete this directory, on next
|
|
193 |
export, all component releases will need to be sent.";
|
|
194 |
close (README);
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
sub ExternaliseIndex {
|
|
199 |
# The index will later be interalised by MultiVolumeExport.
|
|
200 |
my $self = shift;
|
|
201 |
for (my $i = 0; $i <= $self->{currentExportVolume}; ++$i) {
|
|
202 |
my $dir = Utils::ConcatenateDirNames($self->Host(), $self->ExportVolumeName($i));
|
|
203 |
Utils::MakeDir($dir);
|
|
204 |
open (INDEX, ">$dir/index") or die "Error: Couldn't open \"$dir/index\" for writing: $!\n";
|
|
205 |
foreach my $file (sort keys %{$self->{index}}) {
|
|
206 |
print INDEX "$file\t$self->{index}->{$file}\n";
|
|
207 |
}
|
|
208 |
close (INDEX);
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
sub InitNextExportVolume {
|
|
213 |
my $self = shift;
|
|
214 |
$self->{currentExportVolumeSize} = 0;
|
|
215 |
if (exists $self->{currentExportVolume}) {
|
|
216 |
++$self->{currentExportVolume};
|
|
217 |
}
|
|
218 |
else {
|
|
219 |
$self->{currentExportVolume} = 0;
|
|
220 |
$self->SetExportVolumePrefix();
|
|
221 |
}
|
|
222 |
my $exportVol = Utils::ConcatenateDirNames($self->Host(), $self->CurrentExportVolumeName());
|
|
223 |
Utils::MakeDir($exportVol);
|
|
224 |
}
|
|
225 |
|
|
226 |
sub LogDir {
|
|
227 |
my $self = shift;
|
|
228 |
return Utils::ConcatenateDirNames($self->Host(), KLogDirName);
|
|
229 |
}
|
|
230 |
|
|
231 |
sub DESTROY {
|
|
232 |
my $self = shift;
|
|
233 |
if ($self->{currentExportVolume} == 0 and not exists $self->{index}) {
|
|
234 |
# Nothing was exported, so cleanup.
|
|
235 |
my $dir = Utils::ConcatenateDirNames($self->Host(), $self->CurrentExportVolumeName());
|
|
236 |
rmdir ($dir) or die "Error: Couldn't remove directory \"$dir\": $!\n";
|
|
237 |
}
|
|
238 |
else {
|
|
239 |
$self->ExternaliseIndex();
|
|
240 |
}
|
|
241 |
}
|
|
242 |
|
|
243 |
1;
|
|
244 |
|
|
245 |
=head1 NAME
|
|
246 |
|
|
247 |
RemoteSite::NetDrive::MultiVolumeExport.pm - Export encyrpted releases to multiple fixed size volumes
|
|
248 |
|
|
249 |
=head1 DESCRIPTION
|
|
250 |
|
|
251 |
The purpose of this remote site module is to allow releases to be exported to directories to be stored on removable media such as writable CD ROMs. It is derived from C<RemoteSite::NetDrive> since a lot of the basic file manipulation is identical.
|
|
252 |
|
|
253 |
The maximum size of each export volume can be specified using the C<IniData> keyword C<max_export_volume_size>. This is used to determine when to start a new volume. At the end of the export process a set of uniquely named directories (the export volumes) will have been created in C<host> directory (specified using the C<IniData> keyword C<remote_host>). There will also be a directory called F<sent_log>, which should be retain between exports so the tools can work out which release have already been exported. Once the export volumes have been archived, they may be deleted.
|
|
254 |
|
|
255 |
=head1 INTERFACE
|
|
256 |
|
|
257 |
=head2 New
|
|
258 |
|
|
259 |
Passed an argument list in the form of hash key value pairs. The supported arguments are...
|
|
260 |
|
|
261 |
host => $host_address_string
|
|
262 |
max_export_volume_size => $max_export_volume_size_integer
|
|
263 |
verbose => $verbosity_integer
|
|
264 |
|
|
265 |
Returns a reference to a C<RemoteSite::NetDrive::MultiVolumeExport> object.
|
|
266 |
|
|
267 |
=head2 SendFile
|
|
268 |
|
|
269 |
Passed a local and a remote file name. Checks the file will fit in the current volume, if not creates a new volume. Logs the file and then differs to C<RemoteSite::NetDrive> to perform the copy.
|
|
270 |
|
|
271 |
=head2 GetFile
|
|
272 |
|
|
273 |
Not suppored, since this module may only be used for exporting.
|
|
274 |
|
|
275 |
=head2 FileExists
|
|
276 |
|
|
277 |
Passed a filename (with full path). Checks the F<sent_log> to see is this has already been exported. Returns true if it has, false otherwise.
|
|
278 |
|
|
279 |
=head1 KNOWN BUGS
|
|
280 |
|
|
281 |
None
|
|
282 |
|
|
283 |
=head1 COPYRIGHT
|
|
284 |
|
|
285 |
Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
286 |
All rights reserved.
|
|
287 |
This component and the accompanying materials are made available
|
|
288 |
under the terms of the License "Eclipse Public License v1.0"
|
|
289 |
which accompanies this distribution, and is available
|
|
290 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
291 |
|
|
292 |
Initial Contributors:
|
|
293 |
Nokia Corporation - initial contribution.
|
|
294 |
|
|
295 |
Contributors:
|
|
296 |
|
|
297 |
Description:
|
|
298 |
|
|
299 |
|
|
300 |
=cut
|