Merge branch 'issue-48' into develop

This commit is contained in:
daniel oeh 2012-12-19 15:24:05 +01:00
commit c6552709ae
1 changed files with 22 additions and 4 deletions

View File

@ -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)) {