Skip to content

Commit 5c36c52

Browse files
committed
generate.pl: allow setting alternate dir for downloads
This can be helpful in docker volumes or dev containers, where using the default location under the repo root can have issues due to host/container sync.
1 parent d4a266a commit 5c36c52

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

generate.pl

+8-7
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ sub die_with_sample {
122122
die_with_sample unless defined $config->{releases};
123123
die_with_sample unless ref $config->{releases} eq "ARRAY";
124124

125-
if (!-d "downloads") {
126-
mkdir "downloads" or die "Couldn't create a downloads directory";
125+
my $downloads = $ENV{DOCKER_PERL_DOWNLOADS_DIR} // "downloads";
126+
if (!-d "$downloads") {
127+
mkdir "$downloads" or die "Couldn't create a downloads directory at $downloads";
127128
}
128129

129130
for my $build (@{$config->{builds}}) {
@@ -141,21 +142,21 @@ sub die_with_sample {
141142
my $tarball = CPAN::Perl::Releases::MetaCPAN::perl_tarballs($release->{version})->{'tar.gz'};
142143
my ($file) = File::Basename::fileparse($tarball);
143144
my $url = "https://cpan.metacpan.org/authors/id/$tarball";
144-
if (-f "downloads/$file" && `sha256sum downloads/$file` =~ /^\Q$release->{sha256}\E\s+\Qdownloads\/$file\E/) {
145+
if (-f "$downloads/$file" && `sha256sum $downloads/$file` =~ /^\Q$release->{sha256}\E\s+\Q$downloads\/$file\E/) {
145146
print "Skipping download of $file, already current\n";
146147
}
147148
else {
148149
print "Downloading $url\n";
149-
getstore($url, "downloads/$file");
150+
getstore($url, "$downloads/$file");
150151
}
151152
{
152-
my $dir = "downloads/perl-$release->{version}";
153+
my $dir = "$downloads/perl-$release->{version}";
153154
qx{rm -fR $dir};
154155
mkdir $dir or die "Couldn't create $dir";
155156
qx{
156-
tar -C "downloads" -xf $dir.tar.gz &&\
157+
tar -C "$downloads" -xf $dir.tar.gz &&\
157158
cd $dir &&\
158-
find . -exec chmod u+w {} + &&\
159+
chown -R \$(id -u):\$(id -g) . &&\
159160
git init &&\
160161
git add . &&\
161162
git commit -m tmp

0 commit comments

Comments
 (0)