This is an automated email from the ASF dual-hosted git repository.

bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new b024eb1ddf Fix#9316  Allow a VFS File Explorer rename that only 
changes letter case (#9326)
b024eb1ddf is described below

commit b024eb1ddfa9da5a57e28b5113aed093d3bf15ed
Author: Lance <[email protected]>
AuthorDate: Sat Nov 7 03:17:56 2026 +0800

    Fix#9316  Allow a VFS File Explorer rename that only changes letter case 
(#9326)
    
    * Allow a VFS File Explorer rename that only changes letter case
    
    Signed-off-by: leehaut <[email protected]>
    
    * Allow a VFS File Explorer rename that only changes letter case
    
    Signed-off-by: leehaut <[email protected]>
    
    ---------
    
    Signed-off-by: leehaut <[email protected]>
---
 .../vfs/explorer/VfsFileExplorerLocation.java      |  2 +-
 .../ui/hopgui/vfs/explorer/VfsFileTransfer.java    | 31 ++++++++
 .../hopgui/vfs/explorer/VfsFileTransferTest.java   | 83 ++++++++++++++++++++++
 3 files changed, 115 insertions(+), 1 deletion(-)

diff --git 
a/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileExplorerLocation.java
 
b/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileExplorerLocation.java
index 2bb258ccae..52aa14c087 100644
--- 
a/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileExplorerLocation.java
+++ 
b/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileExplorerLocation.java
@@ -2193,7 +2193,7 @@ public class VfsFileExplorerLocation extends Composite {
               PKG, "VfsFileExplorer.Rename.NoParent", 
file.getName().getBaseName()));
     }
     FileObject destination = parent.resolveFile(newName);
-    if (destination.exists() && !VfsFileTransfer.same(file, destination)) {
+    if (destination.exists() && !VfsFileTransfer.sameFile(file, destination)) {
       throw new IllegalStateException(
           BaseMessages.getString(PKG, "VfsFileExplorer.Transfer.Exists", 
newName));
     }
diff --git 
a/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransfer.java 
b/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransfer.java
index ded80e272c..2fcdc5ed69 100644
--- 
a/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransfer.java
+++ 
b/ui/src/main/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransfer.java
@@ -20,6 +20,8 @@ package org.apache.hop.ui.hopgui.vfs.explorer;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -460,6 +462,35 @@ public final class VfsFileTransfer {
     }
   }
 
+  /**
+   * True when both objects name one file. {@link #same} compares the path as 
written, so on a
+   * case-insensitive disk {@code data.csv} and {@code Data.csv} are not the 
same to it. A local
+   * pair counts only when the names differ by letter case, neither path is a 
symbolic link, and the
+   * disk reports one file. A link and the file it points to stay different, 
so renaming the link
+   * does not replace that file.
+   */
+  static boolean sameFile(FileObject left, FileObject right) {
+    if (same(left, right)) {
+      return true;
+    }
+    try {
+      String leftName = HopVfs.getFilename(left);
+      String rightName = HopVfs.getFilename(right);
+      if (!leftName.equalsIgnoreCase(rightName)
+          || !HopVfs.isLocalFileSystem(leftName)
+          || !HopVfs.isLocalFileSystem(rightName)) {
+        return false;
+      }
+      Path leftPath = Path.of(leftName);
+      Path rightPath = Path.of(rightName);
+      return !Files.isSymbolicLink(leftPath)
+          && !Files.isSymbolicLink(rightPath)
+          && Files.isSameFile(leftPath, rightPath);
+    } catch (Exception ignored) {
+      return false;
+    }
+  }
+
   /** True when {@code candidate} is {@code folder} or a folder inside it. */
   public static boolean isInside(FileObject folder, FileObject candidate)
       throws FileSystemException {
diff --git 
a/ui/src/test/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransferTest.java
 
b/ui/src/test/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransferTest.java
index ad41c409c2..a7c9b9d684 100644
--- 
a/ui/src/test/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransferTest.java
+++ 
b/ui/src/test/java/org/apache/hop/ui/hopgui/vfs/explorer/VfsFileTransferTest.java
@@ -22,13 +22,19 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.abort;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.CancellationException;
+import java.util.stream.Stream;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.hop.core.vfs.HopVfs;
@@ -311,6 +317,63 @@ class VfsFileTransferTest {
         
result.getRemaining().stream().map(VfsFileTransfer.Entry::getName).toList());
   }
 
+  @Test
+  void aCaseOnlyLocalNameIsTheSameFile() throws Exception {
+    Path dir = Files.createTempDirectory("hop-vfs-case");
+    try {
+      Path file = Files.writeString(dir.resolve("data.csv"), "hello");
+      Path other = Files.writeString(dir.resolve("other.csv"), "x");
+      FileObject source = HopVfs.getFileObject(file.toString());
+      FileObject otherCase = source.getParent().resolveFile("Data.csv");
+      FileObject different = HopVfs.getFileObject(other.toString());
+
+      assertTrue(VfsFileTransfer.sameFile(source, source));
+      assertFalse(VfsFileTransfer.sameFile(source, different));
+      if (otherCase.exists()) {
+        assertFalse(VfsFileTransfer.same(source, otherCase));
+        assertTrue(VfsFileTransfer.sameFile(source, otherCase));
+      } else {
+        assertFalse(VfsFileTransfer.sameFile(source, otherCase));
+      }
+    } finally {
+      deleteTree(dir);
+    }
+  }
+
+  @Test
+  void aSymbolicLinkIsNotTheSameFileAsItsTarget() throws Exception {
+    Path dir = Files.createTempDirectory("hop-vfs-link");
+    try {
+      Path target = Files.writeString(dir.resolve("a.csv"), "precious");
+      Path link = symbolicLink(dir.resolve("link.csv"), target.getFileName());
+      assertFalse(
+          VfsFileTransfer.sameFile(
+              HopVfs.getFileObject(link.toString()), 
HopVfs.getFileObject(target.toString())));
+    } finally {
+      deleteTree(dir);
+    }
+  }
+
+  @Test
+  void aCaseOnlySymbolicLinkIsNotTheSameFile() throws Exception {
+    Path dir = Files.createTempDirectory("hop-vfs-case-link");
+    try {
+      Path stored = Files.writeString(dir.resolve("data.csv"), "hello");
+      Path link;
+      try {
+        link = Files.createSymbolicLink(dir.resolve("Data.csv"), 
stored.getFileName());
+      } catch (UnsupportedOperationException | IOException e) {
+        abort("a distinct case-only symbolic link is not available: " + 
e.getMessage());
+        return;
+      }
+      assertFalse(
+          VfsFileTransfer.sameFile(
+              HopVfs.getFileObject(link.toString()), 
HopVfs.getFileObject(stored.toString())));
+    } finally {
+      deleteTree(dir);
+    }
+  }
+
   @Test
   void aDroppedPathInsideAnotherIsLeftOut() {
     assertEquals(
@@ -367,6 +430,26 @@ class VfsFileTransferTest {
     }
   }
 
+  private static Path symbolicLink(Path link, Path relativeTarget) {
+    try {
+      return Files.createSymbolicLink(link, relativeTarget);
+    } catch (UnsupportedOperationException | IOException e) {
+      abort("symbolic links are not available: " + e.getMessage());
+      return null;
+    }
+  }
+
+  private static void deleteTree(Path dir) throws Exception {
+    if (dir == null || !Files.exists(dir)) {
+      return;
+    }
+    try (Stream<Path> paths = Files.walk(dir)) {
+      for (Path path : paths.sorted(Comparator.reverseOrder()).toList()) {
+        Files.deleteIfExists(path);
+      }
+    }
+  }
+
   private static List<String> names(FileObject folder) throws Exception {
     folder.refresh();
     List<String> names = new ArrayList<>();

Reply via email to