From df97de0cff704f0bfbd70fffe0f3cee346dbfa15 Mon Sep 17 00:00:00 2001 From: Rohit Yengisetty Date: Thu, 5 Mar 2015 16:35:21 -0800 Subject: [PATCH] CM File Manager - Gracefully handle renaming on case-insensitive filesystems 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 | 6 ++++-- src/com/cyanogenmod/filemanager/util/FileHelper.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/com/cyanogenmod/filemanager/util/CommandHelper.java b/src/com/cyanogenmod/filemanager/util/CommandHelper.java index 6c33a2f..de71798 100644 --- a/src/com/cyanogenmod/filemanager/util/CommandHelper.java +++ b/src/com/cyanogenmod/filemanager/util/CommandHelper.java @@ -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); diff --git a/src/com/cyanogenmod/filemanager/util/FileHelper.java b/src/com/cyanogenmod/filemanager/util/FileHelper.java index 1d9aa9f..14059d6 100644 --- a/src/com/cyanogenmod/filemanager/util/FileHelper.java +++ b/src/com/cyanogenmod/filemanager/util/FileHelper.java @@ -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); + } } -- 2.11.0