From 031768159728a9a6de33122ac7340e0562b1620c Mon Sep 17 00:00:00 2001 From: Dean Gardiner Date: Mon, 11 Nov 2013 03:07:07 +1300 Subject: [PATCH] Added directory removal to the rtorrent downloader --- couchpotato/core/downloaders/rtorrent/main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/couchpotato/core/downloaders/rtorrent/main.py b/couchpotato/core/downloaders/rtorrent/main.py index ed08114e..ecef57c7 100755 --- a/couchpotato/core/downloaders/rtorrent/main.py +++ b/couchpotato/core/downloaders/rtorrent/main.py @@ -214,6 +214,14 @@ class rTorrent(Downloader): for file_item in torrent.get_files(): # will only delete files, not dir/sub-dir os.unlink(os.path.join(torrent.directory, file_item.path)) + if torrent.is_multi_file() and torrent.directory.endswith(torrent.name): + # Remove empty directories bottom up + try: + for path, _, _ in os.walk(torrent.directory, topdown=False): + os.rmdir(path) + except OSError: + log.info('Directory "%s" contains extra files, unable to remove', torrent.directory) + torrent.erase() # just removes the torrent, doesn't delete data return True