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::MultiVolumeImport.pm
|
|
18 |
#
|
|
19 |
|
|
20 |
package RemoteSite::NetDrive::MultiVolumeImport;
|
|
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 |
# Initialization
|
|
34 |
#
|
|
35 |
|
|
36 |
sub Initialize {
|
|
37 |
my $self = shift;
|
|
38 |
$self->SUPER::Initialize(@_);
|
|
39 |
$self->Connect();
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
#
|
|
44 |
# Public (from RemoteSite)
|
|
45 |
#
|
|
46 |
|
|
47 |
sub SendFile {
|
|
48 |
my $self = shift;
|
|
49 |
$self->HandleError("Function 'SendFile' not supported by ".ref($self)."\n");
|
|
50 |
}
|
|
51 |
|
|
52 |
sub GetFile {
|
|
53 |
my $self = shift;
|
|
54 |
my $remoteFile = shift;
|
|
55 |
my $localFile = shift;
|
|
56 |
|
|
57 |
unless (defined $localFile and defined $remoteFile) {
|
|
58 |
$self->HandleError("Incorrect args passed to ".ref($self)."::GetFile");
|
|
59 |
}
|
|
60 |
|
|
61 |
$self->InitAppropriateImportVolume($remoteFile);
|
|
62 |
$self->SUPER::GetFile($remoteFile, $localFile);
|
|
63 |
}
|
|
64 |
|
|
65 |
sub FileExists {
|
|
66 |
my $self = shift;
|
|
67 |
my $remoteFile = shift;
|
|
68 |
unless (defined $remoteFile) {
|
|
69 |
return 0;
|
|
70 |
}
|
|
71 |
$self->Connect();
|
|
72 |
return (defined $self->LookupIndexEntry($remoteFile));
|
|
73 |
}
|
|
74 |
|
|
75 |
sub DirList {
|
|
76 |
my $self = shift;
|
|
77 |
$self->HandleError("Function 'DirList' not supported by ".ref($self)."\n");
|
|
78 |
}
|
|
79 |
|
|
80 |
sub MakeDir {
|
|
81 |
my $self = shift;
|
|
82 |
$self->HandleError("Function 'MakeDir' not supported by ".ref($self)."\n");
|
|
83 |
}
|
|
84 |
|
|
85 |
sub FileSize {
|
|
86 |
my $self = shift;
|
|
87 |
$self->HandleError("Function 'FileSize' not supported by ".ref($self)."\n");
|
|
88 |
}
|
|
89 |
|
|
90 |
sub DeleteFile {
|
|
91 |
my $self = shift;
|
|
92 |
$self->HandleError("Function 'DeleteFile' not supported by ".ref($self)."\n");
|
|
93 |
}
|
|
94 |
|
|
95 |
sub MoveFile {
|
|
96 |
my $self = shift;
|
|
97 |
$self->HandleError("Function 'MoveFile' not supported by ".ref($self)."\n");
|
|
98 |
}
|
|
99 |
|
|
100 |
sub FileModifiedTime {
|
|
101 |
my $self = shift;
|
|
102 |
$self->HandleError("Function 'FileModifiedTime' not supported by ".ref($self)."\n");
|
|
103 |
}
|
|
104 |
|
|
105 |
|
|
106 |
#
|
|
107 |
# Private.
|
|
108 |
#
|
|
109 |
|
|
110 |
sub LookupIndexEntry {
|
|
111 |
my $self = shift;
|
|
112 |
my $file = lc(shift);
|
|
113 |
Utils::TidyFileName(\$file);
|
|
114 |
unless (exists $self->{index}) {
|
|
115 |
$self->InternaliseIndex();
|
|
116 |
}
|
|
117 |
if (exists $self->{index}->{$file}) {
|
|
118 |
return $self->{index}->{$file};
|
|
119 |
}
|
|
120 |
return undef;
|
|
121 |
}
|
|
122 |
|
|
123 |
sub InternaliseIndex {
|
|
124 |
# Read the index created by MultiVolumeExport.
|
|
125 |
my $self = shift;
|
|
126 |
my $index = $self->Host(). '/index';
|
|
127 |
unless (-e $index) {
|
|
128 |
$self->ChangeImportVolume(0);
|
|
129 |
}
|
|
130 |
open (INDEX, $index) or die "Error: Couldn't open \"$index\": $!\n";
|
|
131 |
while (my $line = <INDEX>) {
|
|
132 |
(my $file, my $volume) = $line =~ /(.*)\t(.*)/;
|
|
133 |
$self->{index}->{$file} = $volume;
|
|
134 |
}
|
|
135 |
close (INDEX);
|
|
136 |
}
|
|
137 |
|
|
138 |
sub InitAppropriateImportVolume {
|
|
139 |
my $self = shift;
|
|
140 |
my $file = shift;
|
|
141 |
my $requiredVolume = $self->LookupIndexEntry($file);
|
|
142 |
unless (defined $requiredVolume) {
|
|
143 |
die "Error: \"$file\" not found in any volumes\n";
|
|
144 |
}
|
|
145 |
if ($requiredVolume == $self->{currentImportVolume}) {
|
|
146 |
return;
|
|
147 |
}
|
|
148 |
else {
|
|
149 |
$file = Utils::ConcatenateDirNames($self->Host(), $file);
|
|
150 |
AGAIN:
|
|
151 |
$self->ChangeImportVolume($requiredVolume);
|
|
152 |
unless (-e $file) {
|
|
153 |
print "Error: \"$file\" not found
|
|
154 |
Try again? [y/n] ";
|
|
155 |
my $response = <STDIN>;
|
|
156 |
chomp $response;
|
|
157 |
if ($response =~ /^y$/i) {
|
|
158 |
goto AGAIN;
|
|
159 |
}
|
|
160 |
die "Aborting...\n";
|
|
161 |
}
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
sub ChangeImportVolume {
|
|
166 |
my $self = shift;
|
|
167 |
my $volume = shift;
|
|
168 |
print "Insert import volume #$volume and hit return...\n";
|
|
169 |
<STDIN>;
|
|
170 |
$self->{currentImportVolume} = $volume;
|
|
171 |
}
|
|
172 |
|
|
173 |
1;
|
|
174 |
|
|
175 |
=head1 NAME
|
|
176 |
|
|
177 |
RemoteSite::NetDrive::MultiVolumeImport.pm - Import releases that were exported using RemoteSite::NetDrive::MultiVolumeExport
|
|
178 |
|
|
179 |
=head1 DESCRIPTION
|
|
180 |
|
|
181 |
The purpose of this remote site module is to allow releases that were exported using C<RemoteSite::NetDrive::MultiVolumeExport> to be imported. The export process writes a complete index into each volume. This is read to determine which volumes contain which files. The user is prompted to change volumes are necessary. Location of the import volume is specified using the C<IniData> keyword C<remote_host>.
|
|
182 |
|
|
183 |
=head1 INTERFACE
|
|
184 |
|
|
185 |
=head2 New
|
|
186 |
|
|
187 |
Passed an argument list in the form of hash key value pairs. The supported arguments are...
|
|
188 |
|
|
189 |
host => $host_address_string
|
|
190 |
verbose => $verbosity_integer
|
|
191 |
|
|
192 |
Returns a reference to a C<RemoteSite::NetDrive::MultiVolumeImport> object
|
|
193 |
|
|
194 |
=head2 SendFile
|
|
195 |
|
|
196 |
Not suppored, since this module may only be used for importing.
|
|
197 |
|
|
198 |
=head2 GetFile
|
|
199 |
|
|
200 |
Passed a remote and local file name. Finds out which volume the file lives on, and requests that the user changes volumes if necessary. Then differs to C<RemoteSite::NetDrive> to perform the copy.
|
|
201 |
|
|
202 |
=head2 FileExists
|
|
203 |
|
|
204 |
Passed a filename (with full path). Returns true if the file exists in the volume index, false otherwise.
|
|
205 |
|
|
206 |
=head1 KNOWN BUGS
|
|
207 |
|
|
208 |
None
|
|
209 |
|
|
210 |
=head1 COPYRIGHT
|
|
211 |
|
|
212 |
Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
213 |
All rights reserved.
|
|
214 |
This component and the accompanying materials are made available
|
|
215 |
under the terms of the License "Eclipse Public License v1.0"
|
|
216 |
which accompanies this distribution, and is available
|
|
217 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
218 |
|
|
219 |
Initial Contributors:
|
|
220 |
Nokia Corporation - initial contribution.
|
|
221 |
|
|
222 |
Contributors:
|
|
223 |
|
|
224 |
Description:
|
|
225 |
|
|
226 |
|
|
227 |
=cut
|