summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/Helpers.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/providers/downloads/Helpers.java')
-rw-r--r--src/com/android/providers/downloads/Helpers.java38
1 files changed, 12 insertions, 26 deletions
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index a20a7592..59cc97cf 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -16,7 +16,6 @@
package com.android.providers.downloads;
-import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
@@ -99,25 +98,22 @@ public class Helpers {
boolean isPublicApi) throws GenerateSaveFileError {
checkCanHandleDownload(context, mimeType, destination, isPublicApi);
if (destination == Downloads.Impl.DESTINATION_FILE_URI) {
- return getPathForFileUri(hint, contentLength);
+ String path = verifyFileUri(hint, contentLength);
+ String c = getFullPath(path, mimeType, destination, null);
+ return c;
} else {
return chooseFullPath(context, url, hint, contentDisposition, contentLocation, mimeType,
destination, contentLength);
}
}
- private static String getPathForFileUri(String hint, long contentLength)
+ private static String verifyFileUri(String hint, long contentLength)
throws GenerateSaveFileError {
if (!isExternalMediaMounted()) {
throw new GenerateSaveFileError(Downloads.Impl.STATUS_DEVICE_NOT_FOUND_ERROR,
"external media not mounted");
}
String path = Uri.parse(hint).getPath();
- if (new File(path).exists()) {
- Log.d(Constants.TAG, "File already exists: " + path);
- throw new GenerateSaveFileError(Downloads.Impl.STATUS_FILE_ALREADY_EXISTS_ERROR,
- "requested destination file already exists");
- }
if (getAvailableBytes(getFilesystemRoot(path)) < contentLength) {
throw new GenerateSaveFileError(Downloads.Impl.STATUS_INSUFFICIENT_SPACE_ERROR,
"insufficient space on external storage");
@@ -148,11 +144,15 @@ public class Helpers {
File base = locateDestinationDirectory(context, mimeType, destination, contentLength);
String filename = chooseFilename(url, hint, contentDisposition, contentLocation,
destination);
+ return getFullPath(filename, mimeType, destination, base);
+ }
+ private static String getFullPath(String filename, String mimeType, int destination,
+ File base) throws GenerateSaveFileError {
// Split filename between base and extension
// Add an extension if filename does not have one
String extension = null;
- int dotIndex = filename.indexOf('.');
+ int dotIndex = filename.lastIndexOf('.');
if (dotIndex < 0) {
extension = chooseExtensionFromMimeType(mimeType, true);
} else {
@@ -162,12 +162,13 @@ public class Helpers {
boolean recoveryDir = Constants.RECOVERY_DIRECTORY.equalsIgnoreCase(filename + extension);
- filename = base.getPath() + File.separator + filename;
+ if (base != null) {
+ filename = base.getPath() + File.separator + filename;
+ }
if (Constants.LOGVV) {
Log.v(Constants.TAG, "target file: " + filename + extension);
}
-
return chooseUniqueFilename(destination, filename, extension, recoveryDir);
}
@@ -850,19 +851,4 @@ public class Helpers {
}
return sb.toString();
}
-
- /*
- * Delete the given file from device
- * and delete its row from the downloads database.
- */
- /* package */ static void deleteFile(ContentResolver resolver, long id, String path, String mimeType) {
- try {
- File file = new File(path);
- file.delete();
- } catch (Exception e) {
- Log.w(Constants.TAG, "file: '" + path + "' couldn't be deleted", e);
- }
- resolver.delete(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, Downloads.Impl._ID + " = ? ",
- new String[]{String.valueOf(id)});
- }
}