servo: transmission: torrent-done: fix dry-run; ensure all destructive ops are actually marked as destructive
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env nix-shell
|
||||||
#!nix-shell -i bash -p acl -p bash -p coreutils -p findutils -p rsync -p util-linux
|
#!nix-shell -i bash -p acl -p bash -p coreutils -p findutils -p rsync -p util-linux
|
||||||
|
|
||||||
|
# transmission invokes this with no args, and the following env vars:
|
||||||
|
# - TR_TORRENT_DIR: full path to the folder i told transmission to download it to.
|
||||||
|
# e.g. /var/media/torrents/Videos/Film/Jason.Bourne-2016
|
||||||
|
# optionally, perform a dry run by setting TR_DRY_RUN=1
|
||||||
|
|
||||||
DOWNLOAD_DIR=/var/media/torrents
|
DOWNLOAD_DIR=/var/media/torrents
|
||||||
|
|
||||||
destructive() {
|
destructive() {
|
||||||
if [ -n "${TR_DRY_RUN-}" ]; then
|
if [ -n "${TR_DRY_RUN-}" ]; then
|
||||||
echo "$*"
|
echo "[dry-run] $*"
|
||||||
else
|
else
|
||||||
"$@"
|
"$@"
|
||||||
fi
|
fi
|
||||||
@@ -34,12 +39,12 @@ subdirs=("$MEDIA_DIR"/*)
|
|||||||
if [ ${#subdirs} -eq 1 ]; then
|
if [ ${#subdirs} -eq 1 ]; then
|
||||||
dirname="${subdirs[0]}"
|
dirname="${subdirs[0]}"
|
||||||
if [ -d "$dirname" ]; then
|
if [ -d "$dirname" ]; then
|
||||||
mv "$dirname"/* "$MEDIA_DIR/" && rmdir "$dirname"
|
destructive mv "$dirname"/* "$MEDIA_DIR/" && destructive rmdir "$dirname"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove noisy files:
|
# remove noisy files:
|
||||||
find "$MEDIA_DIR/" -type f \(\
|
destructive find "$MEDIA_DIR/" -type f \(\
|
||||||
-iname '.*downloaded.?from.*' \
|
-iname '.*downloaded.?from.*' \
|
||||||
-o -iname 'source.txt' \
|
-o -iname 'source.txt' \
|
||||||
-o 'iname 'upcoming.?releases.*' \
|
-o 'iname 'upcoming.?releases.*' \
|
||||||
|
Reference in New Issue
Block a user