aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremancebo <emancebo@cyngn.com>2015-10-23 18:15:54 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-10-26 10:27:54 -0700
commit7a947f91bcdf09b16df7247eca33dd3601d8e3db (patch)
tree7d0e17f6b2491a6d629791a42966254ec497a80d
parent1c860be4a48cdf373506070abc79fd4d8d739e18 (diff)
downloadandroid_packages_apps_CMFileManager-caf/cm-12.1.tar.gz
android_packages_apps_CMFileManager-caf/cm-12.1.tar.bz2
android_packages_apps_CMFileManager-caf/cm-12.1.zip
Fix rename of files ending with . on sdcardcaf/cm-12.1
If sdcard is formatted as vfat then file names named as "foo." will be silently saved as "foo". This causes us to report the wrong target file to media scanner, which can cause an extra file to be shown in mtp mode on windows. The workaround is to rescan the parent dir to discover the correct filename to report to media scanner. Change-Id: Ia58a341ef6190efe3dca8b13bbc081b6e2d4e9c1 issue-id: QRDL-983
-rw-r--r--src/com/cyanogenmod/filemanager/util/CommandHelper.java40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/com/cyanogenmod/filemanager/util/CommandHelper.java b/src/com/cyanogenmod/filemanager/util/CommandHelper.java
index 625499e7..6a575a77 100644
--- a/src/com/cyanogenmod/filemanager/util/CommandHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/CommandHelper.java
@@ -792,6 +792,22 @@ public final class CommandHelper {
return result;
}
+ private static void recursiveScan(@NonNull final Context context,
+ @Nullable String srcPath,
+ @NonNull String destPath) {
+ recursiveScan(context, srcPath, destPath, -1);
+ }
+
+ private static class FileSystemObjectWithDepth {
+ public FileSystemObject fso;
+ public int depth;
+
+ public FileSystemObjectWithDepth(FileSystemObject fso, int depth) {
+ this.fso = fso;
+ this.depth = depth;
+ }
+ }
+
/**
*
* @param context
@@ -800,17 +816,19 @@ public final class CommandHelper {
*/
private static void recursiveScan(@NonNull final Context context,
@Nullable String srcPath,
- @NonNull String destPath) {
+ @NonNull String destPath,
+ int maxDepth) {
ArrayList<String> paths = new ArrayList<>();
- Stack<FileSystemObject> pathsToScan = new Stack<>();
+ Stack<FileSystemObjectWithDepth> pathsToScan = new Stack<>();
try {
FileSystemObject fso = getFileInfo(context, destPath, null);
if (fso == null) {
return;
}
- pathsToScan.push(fso);
+ pathsToScan.push(new FileSystemObjectWithDepth(fso, 0));
while (!pathsToScan.isEmpty()) {
- fso = pathsToScan.pop();
+ FileSystemObjectWithDepth fsowd = pathsToScan.pop();
+ fso = fsowd.fso;
if (srcPath != null) {
String src = fso.getFullPath().replace(destPath, srcPath);
// Add the path to be deleted
@@ -818,7 +836,7 @@ public final class CommandHelper {
}
// Add the path to be added
paths.add(MediaHelper.normalizeMediaPath(fso.getFullPath()));
- if (fso instanceof Directory) {
+ if (fso instanceof Directory && (maxDepth == -1 || fsowd.depth < maxDepth)) {
try {
List<FileSystemObject> files =
CommandHelper.listFiles(context, fso.getFullPath(), null);
@@ -830,7 +848,7 @@ public final class CommandHelper {
if (file instanceof ParentDirectory) {
continue;
}
- pathsToScan.push(file);
+ pathsToScan.push(new FileSystemObjectWithDepth(file, fsowd.depth + 1));
}
} catch (IOException
| ConsoleAllocException
@@ -939,7 +957,15 @@ public final class CommandHelper {
File parent = new File(dst).getParentFile();
if ((parent != null && !VirtualMountPointConsole.isVirtualStorageResource(parent
.getAbsolutePath()))) {
- recursiveScan(context, src, dst);
+ // scan source
+ MediaScannerConnection.scanFile(context, new String[]{
+ MediaHelper.normalizeMediaPath(src)}, null, null);
+
+ // Recursive scan of the parent dir of the dest. this mitigates a vfat
+ // issue where a file named "foo." will silently be renamed as "foo".
+ // This ensures that we report the correct filename to media scanner by
+ // re-reading the filename from the file system.
+ recursiveScan(context, null, parent.getAbsolutePath(), 1);
}
}