Fixed issue #48
This commit is contained in:
parent
3692119bed
commit
256cfd2001
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue