diff options
-rw-r--r-- | src/de/danoeh/antennapod/storage/DownloadRequester.java | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java index 0201cc542..26bc91555 100644 --- a/src/de/danoeh/antennapod/storage/DownloadRequester.java +++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java @@ -49,10 +49,10 @@ public class DownloadRequester { private void download(Context context, FeedFile item, File dest, boolean overwriteIfExists) { if (!isDownloadingFile(item)) { - if (dest.exists()) { + if (!isFilenameAvailable(dest.toString()) || dest.exists()) { if (AppConfig.DEBUG) - Log.d(TAG, "File already exists."); - if (overwriteIfExists) { + Log.d(TAG, "Filename already used."); + if (isFilenameAvailable(dest.toString()) && overwriteIfExists) { boolean result = dest.delete(); if (AppConfig.DEBUG) Log.d(TAG, "Deleting file. Result: " + result); @@ -69,7 +69,7 @@ public class DownloadRequester { if (AppConfig.DEBUG) Log.d(TAG, "Testing filename " + newName); newDest = new File(dest.getParent(), newName); - if (!newDest.exists()) { + if (!newDest.exists() && isFilenameAvailable(newDest.toString())) { if (AppConfig.DEBUG) Log.d(TAG, "File doesn't exist yet. Using " + newName); @@ -108,6 +108,24 @@ public class DownloadRequester { } } + /** + * Returns true if a filename is available and false if it has already been + * taken by another requested download. + */ + private boolean isFilenameAvailable(String path) { + for (String key : downloads.keySet()) { + FeedFile f = downloads.get(key); + if (f.getFile_url().equals(path)) { + if (AppConfig.DEBUG) + Log.d(TAG, path + + " is already used by another requested download"); + return false; + } + } + if (AppConfig.DEBUG) Log.d(TAG, path + " is available as a download destination"); + return true; + } + public void downloadFeed(Context context, Feed feed) throws DownloadRequestException { if (feedFileValid(feed)) { |