602
+ − 1
#!perl
+ − 2
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
+ − 3
# All rights reserved.
+ − 4
# This component and the accompanying materials are made available
+ − 5
# under the terms of the License "Eclipse Public License v1.0"
+ − 6
# which accompanies this distribution, and is available
+ − 7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ − 8
#
+ − 9
# Initial Contributors:
+ − 10
# Nokia Corporation - initial contribution.
+ − 11
#
+ − 12
# Contributors:
+ − 13
#
+ − 14
# Description:
+ − 15
# PushPullRel - abstracts out common parts of PushEnv, PullEnv, PushRel, PullRel
+ − 16
#
+ − 17
+ − 18
package PushPullRel;
+ − 19
+ − 20
use strict;
+ − 21
use File::Copy;
+ − 22
use IniData;
+ − 23
use RelData;
+ − 24
use PathData;
+ − 25
use CommandController;
+ − 26
+ − 27
sub new {
+ − 28
my $class = shift;
+ − 29
my $localinidata = shift;
+ − 30
my $foreigninifile = shift; # can be an ini file location or an IniData object
+ − 31
my $pushing = shift; # flag, whether we're pushing a release or pulling it
+ − 32
my $verbose = shift;
+ − 33
my $force = shift;
+ − 34
+ − 35
my $self = bless {}, (ref $class || $class);
+ − 36
+ − 37
$self->{localinidata} = $localinidata;
+ − 38
if (ref $foreigninifile) {
+ − 39
$self->{foreigninidata} = $foreigninifile;
+ − 40
} else{
+ − 41
$self->{foreigninidata} = IniData->New($foreigninifile);
+ − 42
}
+ − 43
+ − 44
$self->{pushing} = $pushing || 0;
+ − 45
if ($self->{pushing}) {
+ − 46
$self->{frominidata} = $self->{localinidata};
+ − 47
$self->{toinidata} = $self->{foreigninidata};
+ − 48
} else {
+ − 49
$self->{toinidata} = $self->{localinidata};
+ − 50
$self->{frominidata} = $self->{foreigninidata};
+ − 51
}
+ − 52
$self->{errors} = [];
+ − 53
$self->{verbose} = $verbose;
+ − 54
$self->{force} = $force;
+ − 55
+ − 56
return $self;
+ − 57
}
+ − 58
+ − 59
sub TransferRel {
+ − 60
my $self = shift;
+ − 61
my $thisComp = shift;
+ − 62
my $thisVer = shift;
+ − 63
eval {
+ − 64
my $toRelDir = $self->{toinidata}->PathData->LocalArchivePathForExistingOrNewComponent($thisComp, $thisVer);
+ − 65
my $fromRelDir = $self->{frominidata}->PathData->LocalArchivePathForExistingComponent($thisComp, $thisVer);
+ − 66
die "Error: Couldn't find component \"$thisComp\" \"$thisVer\"\n" unless defined $fromRelDir;
+ − 67
$self->PerformCopying($thisComp, $thisVer, $toRelDir, $fromRelDir);
+ − 68
};
+ − 69
+ − 70
if ($@) {
+ − 71
print "$@";
+ − 72
$self->_AddError($@);
+ − 73
}
+ − 74
}
+ − 75
+ − 76
sub PerformCopying {
+ − 77
my $self = shift;
+ − 78
my $thisComp = shift;
+ − 79
my $thisVer = shift;
+ − 80
my $toRelDir = shift;
+ − 81
my $fromRelDir = shift;
+ − 82
+ − 83
if (-e $toRelDir and Utils::CrossCheckDirs($toRelDir, $fromRelDir)) {
+ − 84
print "$thisComp $thisVer already present\n";
+ − 85
}
+ − 86
elsif (-e $toRelDir) {
+ − 87
if ($self->{force}) {
+ − 88
print "Overwriting \"$toRelDir\" with \"$fromRelDir\"...\n";
+ − 89
$self->_DoCopying($fromRelDir, $toRelDir);
+ − 90
}
+ − 91
else {
+ − 92
die "\"$toRelDir\" present, but doesn't match \"$fromRelDir\". Use -f to force copy.\n";
+ − 93
}
+ − 94
}
+ − 95
else {
+ − 96
# Directory not present, so create an copy release files.
+ − 97
print "Copying $thisComp $thisVer to \"$toRelDir\"...\n";
+ − 98
$self->_DoCopying($fromRelDir, $toRelDir);
+ − 99
}
+ − 100
}
+ − 101
+ − 102
sub TransferEnv {
+ − 103
my $self = shift;
+ − 104
my $comp = shift;
+ − 105
my $ver = shift;
+ − 106
+ − 107
my $relData = RelData->Open($self->{frominidata}, $comp, $ver, $self->{verbose});
+ − 108
my $env = $relData->Environment();
+ − 109
+ − 110
my @errors;
+ − 111
foreach my $thisComp (sort keys %{$env}) {
+ − 112
my $thisVer = $env->{$thisComp};
+ − 113
$self->TransferRel($thisComp, $thisVer);
+ − 114
}
+ − 115
}
+ − 116
+ − 117
sub Errors {
+ − 118
my $self = shift;
+ − 119
return @{$self->{errors}} if wantarray;
+ − 120
return $self->{errors};
+ − 121
}
+ − 122
+ − 123
sub SummariseErrors {
+ − 124
my $self = shift;
+ − 125
my $copyRel = shift || 0;
+ − 126
+ − 127
my $errors = $self->Errors;
+ − 128
if ($#$errors >= 0) {
+ − 129
print "\nSummary of errors:\n\n";
+ − 130
foreach my $thisError (@$errors) {
+ − 131
print $thisError;
+ − 132
}
+ − 133
+ − 134
if($copyRel){
+ − 135
print "\nError: Unable to copy release successfully\n";
+ − 136
}
+ − 137
else{
+ − 138
print "\nError: Unable to push/pull release successfully\n";
+ − 139
}
+ − 140
}
+ − 141
}
+ − 142
+ − 143
sub _DoCopying {
+ − 144
my $self = shift;
+ − 145
my $localRelDir = shift;
+ − 146
my $externalRelDir = shift;
+ − 147
die "Local release directory not provided" unless $localRelDir;
+ − 148
die "External release dir was undefined" unless defined $externalRelDir;
+ − 149
opendir(DIR, $localRelDir) or die "Error: Couldn't open directory \"$localRelDir\": $!\n";
+ − 150
Utils::MakeDir($externalRelDir);
+ − 151
+ − 152
while (defined(my $file = readdir(DIR))) {
+ − 153
next if ($file eq '.' or $file eq '..');
+ − 154
my $localFile = "$localRelDir\\$file";
+ − 155
my $externalFile = "$externalRelDir\\$file";
+ − 156
if (-f $localFile) {
+ − 157
if (-e "$externalRelDir\\$file" and $self->{force}) {
+ − 158
if ($self->{verbose}) { print "\tMaking \"$externalRelDir\\$file\" writable...\n"; }
+ − 159
Utils::SetFileWritable("$externalRelDir\\$file");
+ − 160
}
+ − 161
elsif (-e "$externalRelDir\\$file") {
+ − 162
die;
+ − 163
}
+ − 164
if ($self->{verbose}) { print "\tCopying \"$localFile\" to \"$externalRelDir\"...\n"; }
+ − 165
+ − 166
unless (copy ($localFile, $externalFile)){
+ − 167
my $errormessage = $!;
+ − 168
+ − 169
if($errormessage =~ /No such file or directory/i) {
+ − 170
$errormessage = "Unknown Error - Check disk space or missing file/directory";
+ − 171
}
+ − 172
+ − 173
die "Error: Couldn't copy \"$localFile\" to \"$externalFile\": $errormessage";
+ − 174
}
+ − 175
}
+ − 176
else {
+ − 177
die "Error: \"$file\" is not a file\n";
+ − 178
}
+ − 179
}
+ − 180
}
+ − 181
+ − 182
sub _AddError {
+ − 183
my $self = shift;
+ − 184
my $error = shift;
+ − 185
push @{$self->{errors}}, $error;
+ − 186
}
+ − 187
+ − 188
1;
+ − 189
+ − 190
__END__
+ − 191
+ − 192
=head1 NAME
+ − 193
+ − 194
PushPullRel.pm - class for moving releases between two local archives
+ − 195
+ − 196
=head1 DESCRIPTION
+ − 197
+ − 198
Provides an API to transfer releases between two local archives. (That is, non-encrypted archives,
+ − 199
accessible as standard disk drives from the PC). Used by C<pushenv>, C<pullenv>, C<pushrel>,
+ − 200
C<pullrel>.
+ − 201
+ − 202
=head1 INTERFACE
+ − 203
+ − 204
=head2 new
+ − 205
+ − 206
Creates a new object of this class. Takes five parameters. 1) An IniData object corresponding
+ − 207
to your local repository. 2) A foreign IniData object (or just a filename) describing the
+ − 208
remote repository. 3) A boolean, saying whether you're pushing to the remote site. If false,
+ − 209
assumes you're pulling from the remote site. 4) Verbose. 5) Force (overwrites).
+ − 210
+ − 211
=head2 TransferRel
+ − 212
+ − 213
Takes a component name and version. Transfers that component.
+ − 214
+ − 215
=head2 TransferEnv
+ − 216
+ − 217
Takes a component name and version. Transfers the environment of that component.
+ − 218
+ − 219
=head2 PerformCopying
+ − 220
+ − 221
Takes a component name, version, to release and from release directory. Performs initial checks on the release directories passed and then calls _DoCopying.
+ − 222
+ − 223
=head2 Errors
+ − 224
+ − 225
Returns an arrayref of all the errors encountered during TransferEnv.
+ − 226
+ − 227
=head2 SummariseErrors
+ − 228
+ − 229
Optional input copyRel flag which indicates whether to this summary is for a copyrel or not. Prints all the errors encountered.
+ − 230
+ − 231
=head1 KNOWN BUGS
+ − 232
+ − 233
None.
+ − 234
+ − 235
=head1 COPYRIGHT
+ − 236
+ − 237
Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
+ − 238
All rights reserved.
+ − 239
This component and the accompanying materials are made available
+ − 240
under the terms of the License "Eclipse Public License v1.0"
+ − 241
which accompanies this distribution, and is available
+ − 242
at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ − 243
+ − 244
Initial Contributors:
+ − 245
Nokia Corporation - initial contribution.
+ − 246
+ − 247
Contributors:
+ − 248
+ − 249
Description:
+ − 250
+ − 251
+ − 252
=cut
+ − 253