summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/storage/DownloadRequester.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-12-16 22:55:03 +0100
committerdaniel oeh <daniel.oeh@gmail.com>2012-12-16 22:55:03 +0100
commit256cfd2001ce30529bf3b5762ed1390630de96a3 (patch)
tree5d7cd9246c71e9e90a0b4d64359c648825b677b4 /src/de/danoeh/antennapod/storage/DownloadRequester.java
parent3692119bedec66358d72a649d9408ece77a7b30c (diff)
downloadAntennaPod-256cfd2001ce30529bf3b5762ed1390630de96a3.zip
Fixed issue #48
Diffstat (limited to 'src/de/danoeh/antennapod/storage/DownloadRequester.java')
-rw-r--r--src/de/danoeh/antennapod/storage/DownloadRequester.java26
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)) {