diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-02-22 19:10:05 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-02-22 19:10:05 +0100 |
commit | bd92dd3fb317fd3d38a505b8cc0d27cc6f3f4dd8 (patch) | |
tree | 23c1e8373c421d4c51943f0ea28591398683f1c4 | |
parent | 26471f6e10f9fbbfa44ee02a455fc17a147d5907 (diff) | |
download | AntennaPod-bd92dd3fb317fd3d38a505b8cc0d27cc6f3f4dd8.zip |
Delete file if download fails or is cancelled
-rw-r--r-- | src/de/danoeh/antennapod/service/download/HttpDownloader.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/service/download/HttpDownloader.java b/src/de/danoeh/antennapod/service/download/HttpDownloader.java index 4a4d9e58b..7cb487c1a 100644 --- a/src/de/danoeh/antennapod/service/download/HttpDownloader.java +++ b/src/de/danoeh/antennapod/service/download/HttpDownloader.java @@ -163,6 +163,7 @@ public class HttpDownloader extends Downloader { status.setReasonDetailed(reasonDetailed); status.setDone(true); status.setSuccessful(false); + cleanup(); } private void onCancelled() { @@ -172,6 +173,20 @@ public class HttpDownloader extends Downloader { status.setDone(true); status.setSuccessful(false); status.setCancelled(true); + cleanup(); + } + + /** Deletes unfinished downloads. */ + private void cleanup() { + if (status != null && status.getFeedFile() != null && status.getFeedFile().getFile_url() != null) { + File dest = new File(status.getFeedFile().getFile_url()); + if (dest.exists()) { + boolean rc = dest.delete(); + if (AppConfig.DEBUG) Log.d(TAG, "Deleted file " + dest.getName() + "; Result: " + rc); + } else { + if (AppConfig.DEBUG) Log.d(TAG, "cleanup() didn't delete file: does not exist."); + } + } } } |