This repository has been archived by the owner on Apr 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DidbsExtractor.pm
150 lines (123 loc) · 3.81 KB
/
DidbsExtractor.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package DidbsExtractor;
use DidbsUtils;
use DidbsPackageState;
use File::Path qw/rmtree/;
# Contents set up from values from the dbibsPackage
#
# downloadSuccessFilePath
#
sub new
{
my $self = bless {}, shift;
my $scriptLocation = shift;
my $packageId = shift;
my $packageDir = shift;
my $buildDir = shift;
my $didbsPackage = shift;
my $packageState = shift;
$self->{scriptLocation} = $scriptLocation;
$self->{packageId} = $packageId;
$self->{packageDir} = $packageDir;
$self->{buildDir} = $buildDir;
$self->{didbsPackage} = $didbsPackage;
$self->{packageState} = $packageState;
return $self;
}
sub getState
{
my $self = shift;
return $self->{packageState}->getState();
}
sub setState
{
my $self = shift;
my $newState = shift;
$self->{packageState}->setState($newState);
}
sub extractionSuccess
{
my $self = shift;
return $self->getState() eq EXTRACTED;
}
sub extractit
{
my $self = shift;
my $destdir = $self->{packageDir}."/srcballs";
mkdirp($destdir);
my $destfile = $self->{didbsPackage}->{packageFile};
my $fulldestfile = $destdir."/".$destfile;
if( $self->getState() ne FETCHED )
{
mkdirp($destdir);
my $destfile = $self->{didbsPackage}->{packageFile};
my $fulldestfile = $destdir."/".$destfile;
my $sourceurl = $self->{didbsPackage}->{packageSource};
my $checksum = $self->{didbsPackage}->{packageChecksum};
didbsprint "Checking for already downloaded archive from $sourceurl\n";
my $fetchcmd = $self->{scriptLocation}."/scripts/wgethelper.sh ".$self->{scriptLocation}." $destdir \"$sourceurl\"";
# If the file exists check the signature
my $fileexistsgood = 0;
if( -e $fulldestfile )
{
if(!verifyChecksum($self,$fulldestfile,$checksum))
{
didbsprint "Stale download at $fulldestfile.\n";
didbsprint "Removing is commented out.\n";
exit -1;
unlink $fulldestfile;
}
else
{
didbsprint "File exists ($fulldestfile)\n";
$fileexistsgood = 1;
}
}
if(!$fileexistsgood)
{
didbsprint "Fetching...\n";
didbsprint "\n\n";
system($fetchcmd) == 0 || die $!;
$self->setState( FETCHED );
if(!verifyChecksum($self,$fulldestfile,$checksum))
{
didbsprint "Second download attempt failed.\n";
exit -1;
}
}
# File is good
didbsprint "Checksum match.\n";
$self->setState(SIGCHECKED);
}
if( $self->getState() == SIGCHECKED )
{
my $extractdir = $self->{buildDir}."/".$self->{packageId};
didbsprint "Removing any existing content at $extractdir\n";
rmtree $extractdir || die $!;
mkdirp( $extractdir );
my $extractor = $self->{didbsPackage}->{packageExtraction};
my $fullpathext = $self->{scriptLocation}."/scripts/".$extractor;
didbsprint "Extracting to $extractdir using $fullpathext\n";
my $cmd = "$fullpathext $extractdir $fulldestfile";
didbsprint "Command is $cmd\n";
system($cmd) == 0 || die $!;
$self->setState(EXTRACTED);
}
return $self->getState() == EXTRACTED;
}
sub verifyChecksum
{
my $self=shift;
my $filename=shift;
my $checksum=shift;
# didbsprint "Verifying checksum of $filename\n";
my $calcchecksum = sumfile($self->{scriptLocation}, $filename);
didbsprint "Expected($checksum) - received($calcchecksum)\n";
return $calcchecksum eq $checksum;
}
sub debug
{
my $self = shift;
didbsprint "DibsExtractor constructed for $self->{packageId}\n";
didbsprint "Status is " . $self->getState() ."\n";
}
1;