OSDN Git Service

CM File Manager - Gracefully handle renaming on case-insensitive filesystems
authorRohit Yengisetty <rohit@cyngn.com>
Fri, 6 Mar 2015 00:35:21 +0000 (16:35 -0800)
committerGerrit Code Review <gerrit@cyanogenmod.org>
Sat, 21 Mar 2015 14:29:28 +0000 (14:29 +0000)
Add edge case handling to move/copy commands wherein something is being
renamed to a different-cased version of itself.

Ex : renaming 'mydocuments' to 'MyDocuments'

https://jira.cyanogenmod.org/browse/BACON-3074

Change-Id: Id90de5fd083e341371f250c0194f200388cf4941

src/com/cyanogenmod/filemanager/util/CommandHelper.java
src/com/cyanogenmod/filemanager/util/FileHelper.java

index 6c33a2f..de71798 100644 (file)
@@ -766,10 +766,11 @@ public final class CommandHelper {
             CommandNotFoundException, OperationTimeoutException,
             ExecutionException, InvalidCommandDefinitionException, ReadOnlyFilesystemException,
             CancelledOperationException {
+
         Console cSrc = ensureConsoleForFile(context, console, src);
         Console cDst = ensureConsoleForFile(context, console, dst);
         boolean ret = true;
-        if (cSrc.equals(cDst)) {
+        if (cSrc.equals(cDst) && !FileHelper.isSamePath(src, dst)) {
             // Is safe to use the same console
             MoveExecutable executable =
                     cSrc.getExecutableFactory().newCreator().createMoveExecutable(src, dst);
@@ -858,10 +859,11 @@ public final class CommandHelper {
             CommandNotFoundException, OperationTimeoutException,
             ExecutionException, InvalidCommandDefinitionException, ReadOnlyFilesystemException,
             CancelledOperationException {
+
         Console cSrc = ensureConsoleForFile(context, console, src);
         Console cDst = ensureConsoleForFile(context, console, dst);
         boolean ret = true;
-        if (cSrc.equals(cDst)) {
+        if (cSrc.equals(cDst) && !FileHelper.isSamePath(src, dst)) {
             // Is safe to use the same console
             CopyExecutable executable =
                     cSrc.getExecutableFactory().newCreator().createCopyExecutable(src, dst);
index 1d9aa9f..14059d6 100644 (file)
@@ -1501,4 +1501,19 @@ public final class FileHelper {
         }
         return src.getAbsolutePath().startsWith(dir.getAbsolutePath());
     }
+
+    /**
+     * Method that checks if both path are the same (by checking sensitive cases).
+     *
+     * @param src The source path
+     * @param dst The destination path
+     * @return boolean If both are the same path
+     */
+    public static boolean isSamePath(String src, String dst) {
+        // This is only true if both are exactly the same path or the same file in insensitive
+        // file systems
+        File o1 = new File(src);
+        File o2 = new File(dst);
+        return o1.equals(o2);
+    }
 }