Skip to content

Commit ee3bf38

Browse files
[FIX] XQuery, file:copy: preserve capitalization of the target path (improved)
1 parent 69219b7 commit ee3bf38

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

basex-core/src/main/java/org/basex/query/func/file/FileCopy.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.*;
66
import java.nio.file.*;
7+
import java.util.*;
78

89
import org.basex.core.jobs.*;
910
import org.basex.query.*;
@@ -77,14 +78,14 @@ public static void relocate(final Path src, final Path trg, final boolean copy,
7778
if(copy) {
7879
Files.copy(src, trg, StandardCopyOption.REPLACE_EXISTING);
7980
} else {
80-
// Windows: preserve capitalization of the target path
81-
if(src.getFileName().toString().equalsIgnoreCase(trg.getFileName().toString())) {
82-
Path temp = Files.createTempFile(src.getParent(), null, null);
83-
Files.move(src, temp, StandardCopyOption.REPLACE_EXISTING);
84-
Files.move(temp, trg);
85-
} else {
86-
Files.move(src, trg, StandardCopyOption.REPLACE_EXISTING);
81+
// Windows: preserve capitalization of target path
82+
Path path = src;
83+
final String s = src.getFileName().toString(), t = trg.getFileName().toString();
84+
if(!s.equals(t) && s.equalsIgnoreCase(t)) {
85+
path = src.resolveSibling(UUID.randomUUID().toString());
86+
Files.move(src, path);
8787
}
88+
Files.move(path, trg, StandardCopyOption.REPLACE_EXISTING);
8889
}
8990
}
9091
}

0 commit comments

Comments
 (0)