Browse Source

bz-62890 fix the newly added test in SyncTest. Also, in the implementation of FileUtils#isCaseSensitiveFileSystem, take into account Files.isSame can throw NoSuchFileException in the absence of either of the paths being checked

master
Jaikiran Pai 6 years ago
parent
commit
8ae8894fc2
2 changed files with 22 additions and 3 deletions
  1. +10
    -2
      src/main/org/apache/tools/ant/util/FileUtils.java
  2. +12
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java

+ 10
- 2
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -33,6 +33,7 @@ import java.net.URLConnection;
import java.nio.channels.Channel;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
@@ -1805,7 +1806,7 @@ public class FileUtils {
}
final String mixedCaseFileNamePrefix = "aNt";
Path mixedCaseTmpFile = null;
final boolean caseSensitive;
boolean caseSensitive;
try {
synchronized (fileSystemCaseSensitivity) {
if (fileSystemCaseSensitivity.containsKey(fileSystem)) {
@@ -1823,7 +1824,14 @@ public class FileUtils {
return Optional.empty();
}
final Path lowerCasePath = Paths.get(mixedCaseTmpFile.toString().toLowerCase(Locale.US));
caseSensitive = !Files.isSameFile(mixedCaseTmpFile, lowerCasePath);
try {
caseSensitive = !Files.isSameFile(mixedCaseTmpFile, lowerCasePath);
} catch (NoSuchFileException nsfe) {
// a NSFE implies that the "lowerCasePath" file wasn't considered to be present
// even if the different cased file exists. That effectively means this is a
// case sensitive filesystem
caseSensitive = true;
}
fileSystemCaseSensitivity.put(fileSystem, caseSensitive);
}
} catch (IOException ioe) {


+ 12
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java View File

@@ -19,10 +19,14 @@
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.util.FileUtils;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.util.Optional;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertFalse;
@@ -147,7 +151,14 @@ public class SyncTest {
buildRule.executeTarget("casesensitivity-test");
final String destDir = buildRule.getProject().getProperty("dest") + "/casecheck";
assertFileIsPresent(destDir + "/a.txt");
assertFileIsPresent(destDir + "/A.txt");
final boolean caseSensitive = FileUtils.isCaseSensitiveFileSystem(
buildRule.getProject().resolveFile(destDir).toPath())
.orElse(true); // directory scanner defaults to case sensitive = true
if (caseSensitive) {
assertFileIsNotPresent(destDir + "/A.txt");
} else {
assertFileIsPresent(destDir + "/A.txt");
}
assertFileIsPresent(destDir + "/foo.txt");

assertFileIsNotPresent(destDir + "/bar.txt");


Loading…
Cancel
Save