Skip to content

Commit 03a0395

Browse files
Ansuelaiamadeus
authored andcommitted
scripts/download.pl: fix support for aria2c download tool on macos
Currently we use /dev/shm to place aria2c tmp file. This is not present on macos. Use the openwrt tmp directory instead of the linux-only /dev/shm to save compatibility with more os. Fixes: d391236 ("download.pl: add aria2c support") Signed-off-by: Christian Marangi <[email protected]>
1 parent 5ae6c9b commit 03a0395

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

scripts/download.pl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ sub download_cmd {
8080
my $additional_mirrors = join(" ", map "$_/$filename", @_);
8181

8282
my @chArray = ('a'..'z', 'A'..'Z', 0..9);
83-
my $rfn = join '', map{ $chArray[int rand @chArray] } 0..9;
83+
my $rfn = join '', "${filename}_", map{ $chArray[int rand @chArray] } 0..9;
8484
if (open CURL, '-|', 'curl', '--version') {
8585
if (defined(my $line = readline CURL)) {
8686
$have_curl = 1 if $line =~ /^curl /;
@@ -96,13 +96,15 @@ sub download_cmd {
9696

9797
if ($have_aria2c) {
9898
@mirrors=();
99-
return join(" ", "touch /dev/shm/${rfn}_spp;",
99+
return join(" ", "[ -d $ENV{'TMPDIR'}/aria2c ] || mkdir $ENV{'TMPDIR'}/aria2c;",
100+
"touch $ENV{'TMPDIR'}/aria2c/${rfn}_spp;",
100101
qw(aria2c --stderr -c -x2 -s10 -j10 -k1M), $url, $additional_mirrors,
101102
$check_certificate ? () : '--check-certificate=false',
102-
"--server-stat-of=/dev/shm/${rfn}_spp",
103-
"--server-stat-if=/dev/shm/${rfn}_spp",
104-
"-d /dev/shm -o $rfn;",
105-
"cat /dev/shm/$rfn;", "rm /dev/shm/$rfn /dev/shm/${rfn}_spp");
103+
"--server-stat-of=$ENV{'TMPDIR'}/aria2c/${rfn}_spp",
104+
"--server-stat-if=$ENV{'TMPDIR'}/aria2c/${rfn}_spp",
105+
"-d $ENV{'TMPDIR'}/aria2c -o $rfn;",
106+
"cat $ENV{'TMPDIR'}/aria2c/$rfn;",
107+
"rm $ENV{'TMPDIR'}/aria2c/$rfn $ENV{'TMPDIR'}/aria2c/${rfn}_spp");
106108
} elsif ($have_curl) {
107109
return (qw(curl -f --connect-timeout 20 --retry 5 --location),
108110
$check_certificate ? () : '--insecure',

0 commit comments

Comments
 (0)