summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/storage/DownloadRequester.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2014-04-27 17:02:37 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2014-04-27 17:02:37 +0200
commit6f77dea8384a90cbd6ed4ac4ce3ba4c48b7534ed (patch)
tree22fc86b748fe3fa33164496eaefbb7658f3a11a1 /src/de/danoeh/antennapod/storage/DownloadRequester.java
parent8769d29ceffe3d0157278a62aaefd6c21d46fd01 (diff)
downloadAntennaPod-6f77dea8384a90cbd6ed4ac4ce3ba4c48b7534ed.zip
Prevent media files from being deleted after a failed download
Diffstat (limited to 'src/de/danoeh/antennapod/storage/DownloadRequester.java')
-rw-r--r--src/de/danoeh/antennapod/storage/DownloadRequester.java22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java
index 34d0ebe9a..714ad952f 100644
--- a/src/de/danoeh/antennapod/storage/DownloadRequester.java
+++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java
@@ -12,6 +12,7 @@ import de.danoeh.antennapod.service.download.DownloadService;
import de.danoeh.antennapod.util.FileNameGenerator;
import de.danoeh.antennapod.util.URLChecker;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
@@ -72,9 +73,9 @@ public class DownloadRequester {
}
private void download(Context context, FeedFile item, File dest,
- boolean overwriteIfExists, String username, String password) {
+ boolean overwriteIfExists, String username, String password, boolean deleteOnFailure) {
if (!isDownloadingFile(item)) {
- if (!isFilenameAvailable(dest.toString()) || dest.exists()) {
+ if (!isFilenameAvailable(dest.toString()) || (deleteOnFailure && dest.exists())) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Filename already used.");
if (isFilenameAvailable(dest.toString()) && overwriteIfExists) {
@@ -114,7 +115,7 @@ public class DownloadRequester {
DownloadRequest request = new DownloadRequest(dest.toString(),
item.getDownload_url(), item.getHumanReadableIdentifier(),
- item.getId(), item.getTypeAsInt(), username, password);
+ item.getId(), item.getTypeAsInt(), username, password, deleteOnFailure);
download(context, request);
} else {
@@ -149,7 +150,7 @@ public class DownloadRequester {
String password = (feed.getPreferences() != null) ? feed.getPreferences().getPassword() : null;
download(context, feed, new File(getFeedfilePath(context),
- getFeedfileName(feed)), true, username, password);
+ getFeedfileName(feed)), true, username, password, true);
}
}
@@ -157,7 +158,7 @@ public class DownloadRequester {
throws DownloadRequestException {
if (feedFileValid(image)) {
download(context, image, new File(getImagefilePath(context),
- getImagefileName(image)), false, null, null);
+ getImagefileName(image)), false, null, null, false);
}
}
@@ -174,9 +175,16 @@ public class DownloadRequester {
username = null;
password = null;
}
+
+ File dest;
+ if (feedmedia.getFile_url() != null) {
+ dest = new File(feedmedia.getFile_url());
+ } else {
+ dest = new File(getMediafilePath(context, feedmedia),
+ getMediafilename(feedmedia));
+ }
download(context, feedmedia,
- new File(getMediafilePath(context, feedmedia),
- getMediafilename(feedmedia)), false, username, password
+ dest, false, username, password, false
);
}
}