From 65cd88f59c042dd585be2c741a5ab60dd986fe25 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Tue, 13 Nov 2018 09:50:13 +0530 Subject: [PATCH] bz-62890 don't cache the case sensitivity of the filesystem. Discussed at http://mail-archives.apache.org/mod_mbox/ant-dev/201811.mbox/%3c87efbq6uym.fsf@v45346.1blu.de%3e --- .../org/apache/tools/ant/util/FileUtils.java | 50 +++++++------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index d222ca9fc..2bbd2f3d1 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -81,7 +81,6 @@ public class FileUtils { private static final boolean ON_DOS = Os.isFamily("dos"); private static final boolean ON_WIN9X = Os.isFamily("win9x"); private static final boolean ON_WINDOWS = Os.isFamily("windows"); - private static final Map fileSystemCaseSensitivity = new HashMap<>(); static final int BUF_SIZE = 8192; @@ -1799,40 +1798,29 @@ public class FileUtils { if (path == null) { throw new IllegalArgumentException("Path cannot be null"); } - final FileSystem fileSystem = path.getFileSystem(); - final Boolean caseSensitivity = fileSystemCaseSensitivity.get(fileSystem); - if (caseSensitivity != null) { - return Optional.of(caseSensitivity); - } final String mixedCaseFileNamePrefix = "aNt"; Path mixedCaseTmpFile = null; boolean caseSensitive; try { - synchronized (fileSystemCaseSensitivity) { - if (fileSystemCaseSensitivity.containsKey(fileSystem)) { - return Optional.of(fileSystemCaseSensitivity.get(fileSystem)); - } - if (Files.isRegularFile(path)) { - mixedCaseTmpFile = Files.createTempFile(path.getParent(), mixedCaseFileNamePrefix, null); - } else if (Files.isDirectory(path)) { - mixedCaseTmpFile = Files.createTempFile(path, mixedCaseFileNamePrefix, null); - } else { - // we can only do our tricks to figure out whether the filesystem is - // case sensitive, only if the path is a directory or a file. - // In other cases (like the path being non-existent), we don't - // have a way to determine that detail - return Optional.empty(); - } - final Path lowerCasePath = Paths.get(mixedCaseTmpFile.toString().toLowerCase(Locale.US)); - 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); + if (Files.isRegularFile(path)) { + mixedCaseTmpFile = Files.createTempFile(path.getParent(), mixedCaseFileNamePrefix, null); + } else if (Files.isDirectory(path)) { + mixedCaseTmpFile = Files.createTempFile(path, mixedCaseFileNamePrefix, null); + } else { + // we can only do our tricks to figure out whether the filesystem is + // case sensitive, only if the path is a directory or a file. + // In other cases (like the path being non-existent), we don't + // have a way to determine that detail + return Optional.empty(); + } + final Path lowerCasePath = Paths.get(mixedCaseTmpFile.toString().toLowerCase(Locale.US)); + 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; } } catch (IOException ioe) { System.err.println("Could not determine the case sensitivity of the " +