hget: do a HEAD request to check if the file is already complete (thanks miscief)
when we continue a download, make sure the file isnt already complete, as otherwise the server might respond with a 416 as the range request will out of range.
This commit is contained in:
parent
e73ce8475e
commit
a13ba7741f
1 changed files with 13 additions and 2 deletions
15
rc/bin/hget
15
rc/bin/hget
|
@ -47,13 +47,24 @@ if(! ~ $#o 0){
|
||||||
if(test -s $o)
|
if(test -s $o)
|
||||||
s=`{ls -l $o | awk '{print $6}'}
|
s=`{ls -l $o | awk '{print $6}'}
|
||||||
}
|
}
|
||||||
if(! ~ $s 0)
|
|
||||||
r=($r 'Range: bytes='^$s^'-')
|
|
||||||
<[3=0] <>/mnt/web/clone {
|
<[3=0] <>/mnt/web/clone {
|
||||||
d=/mnt/web/^`{sed 1q}
|
d=/mnt/web/^`{sed 1q}
|
||||||
if(~ $#b 1)
|
if(~ $#b 1)
|
||||||
echo -n baseurl $b >[1=0]
|
echo -n baseurl $b >[1=0]
|
||||||
echo -n url $1 >[1=0]
|
echo -n url $1 >[1=0]
|
||||||
|
if(! ~ $s 0 && ~ $#p 0 && ~ $#P 0 && ~ $#m 0){
|
||||||
|
for(i in $r)
|
||||||
|
echo -n headers $i >[1=0]
|
||||||
|
echo -n request HEAD >[1=0]
|
||||||
|
<$d/body {
|
||||||
|
if(~ $s `{cat $d/contentlength >[2]/dev/null})
|
||||||
|
exit ''
|
||||||
|
}
|
||||||
|
if(~ $#b 1)
|
||||||
|
echo -n baseurl $b >[1=0]
|
||||||
|
echo -n url $1 >[1=0]
|
||||||
|
r=($r 'Range: bytes='^$s^'-')
|
||||||
|
}
|
||||||
for(i in $r)
|
for(i in $r)
|
||||||
echo -n headers $i >[1=0]
|
echo -n headers $i >[1=0]
|
||||||
if(~ $#m 1)
|
if(~ $#m 1)
|
||||||
|
|
Loading…
Reference in a new issue