diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-12-19 15:24:05 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-12-19 15:24:05 +0100 |
commit | c6552709ae6df3271b5a69fba488a8da3b7f7304 (patch) | |
tree | 081d45f1cf81a9dcb4dbdb48e014d8552c73c323 /src/de | |
parent | c67f5d3509612d6bb080381a4c49e56c86203023 (diff) | |
parent | 256cfd2001ce30529bf3b5762ed1390630de96a3 (diff) | |
download | AntennaPod-c6552709ae6df3271b5a69fba488a8da3b7f7304.zip |
Merge branch 'issue-48' into develop
Diffstat (limited to 'src/de')
-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)) { |