From bd92dd3fb317fd3d38a505b8cc0d27cc6f3f4dd8 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 22 Feb 2013 19:10:05 +0100 Subject: Delete file if download fails or is cancelled --- .../antennapod/service/download/HttpDownloader.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/de/danoeh/antennapod/service/download') 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."); + } + } } } -- cgit v1.2.3