diff options
author | Joey Hess <joeyh@joeyh.name> | 2014-12-11 19:48:00 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2014-12-11 19:48:00 -0400 |
commit | fe0fdf3b49840c19f0c2294fd958e5ed6448a827 (patch) | |
tree | 8456a6d30ab271a0335c364bbf549aa2955c284b /doc/special_remotes | |
parent | fa360a3d840740f9dd0d1e9fe3f4a46ff65308ab (diff) |
fix support for single-file torrents
Diffstat (limited to 'doc/special_remotes')
-rwxr-xr-x | doc/special_remotes/external/git-annex-remote-torrent | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/doc/special_remotes/external/git-annex-remote-torrent b/doc/special_remotes/external/git-annex-remote-torrent index a74885729..4f99483bc 100755 --- a/doc/special_remotes/external/git-annex-remote-torrent +++ b/doc/special_remotes/external/git-annex-remote-torrent @@ -72,16 +72,24 @@ downloadtorrent () { dest="$3" tmpdir="$(mktemp -d)" - if ! runcmd aria2c --select-file="$n" "$torrent" -d "$tmpdir"; then - false - fi # aria2c will create part of the directory structure # contained in the torrent. It may download parts of other files # in addition to the one we asked for. So, we need to find # out the filename we want, and look for it. - wantdir="$(btshowmetainfo "$torrent" | grep "^directory name: " | sed "s/^directory name: //")" - wantfile="$(btshowmetainfo "$tmp" | grep '^ ' | sed 's/^ //' | head -n "$n" | tail -n 1 | sed 's/ ([0-9]*)$//')" + wantdir="$(btshowmetainfo "$torrent" | grep "^directory name: " | sed "s/^directory name: //" || true)" + if [ -n "$wantdir" ]; then + wantfile="$(btshowmetainfo "$torrent" | grep '^ ' | sed 's/^ //' | head -n "$n" | tail -n 1 | sed 's/ ([0-9]*)$//')" + if ! runcmd aria2c --select-file="$n" "$torrent" -d "$tmpdir"; then + false + fi + else + wantfile="$(btshowmetainfo "$torrent" | egrep "^file name.*: " | sed "s/^file name.*: //")" + wantdir=. + if ! runcmd aria2c "$torrent" -d "$tmpdir"; then + false + fi + fi if [ -e "$tmpdir/$wantdir/$wantfile" ]; then mv "$tmpdir/$wantdir/$wantfile" "$dest" rm -rf "$tmpdir" @@ -130,6 +138,11 @@ while read line; do n=$(expr $n + 1) printf " $url#$n $size $file" done + if [ "$n" = 0 ]; then + file="$(btshowmetainfo "$tmp" | egrep "^file name.*: " | sed "s/^file name.*: //")" + size="$(btshowmetainfo "$tmp" | egrep "^file size.*: " | sed "s/^file size.*: \([0-9]*\).*/\1/")" + printf " $url $size $file" + fi printf "\n" IFS="$oldIFS" fi @@ -154,7 +167,7 @@ while read line; do if ! runcmd curl -o "$tmp" "$url"; then echo TRANSFER-FAILURE RETRIEVE "$key" "failed downloading torrent file from $url" else - filenum="$(echo "$url" | sed 's/.*#\(\d*\)/\1/')" + filenum="$(echo "$url" | sed 's/(.*#\(\d*\)/\1/')" if downloadtorrent "$tmp" "$filenum" "$file"; then echo TRANSFER-SUCCESS RETRIEVE "$key" else |