This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push:
new 4da6c49 BZ 65499 avoid getCanonicalFile in many cases
4da6c49 is described below
commit 4da6c49b048691282c79a731b69517be088d938e
Author: Stefan Bodewig <[email protected]>
AuthorDate: Thu Aug 19 14:09:03 2021 +0200
BZ 65499 avoid getCanonicalFile in many cases
---
WHATSNEW | 2 ++
src/main/org/apache/tools/ant/util/FileUtils.java | 15 +++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index 92f1c50..68b2ccf 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -19,6 +19,8 @@ Other changes:
* AntClassLoader now implements the ClassLoader#findResource(String) method.
Github Pull Request #150
+ * Ant tries to avoid file name canonicalization whne possible.
+ Bugzilla Report 65499
Changes from Ant 1.10.10 TO Ant 1.10.11
=======================================
diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java
b/src/main/org/apache/tools/ant/util/FileUtils.java
index d835438..52c6625 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -1421,10 +1421,21 @@ public class FileUtils {
if (f1 == null || f2 == null) {
return false;
}
+ return fileNameEquals(f1, f2) || isSameFile(f1, f2);
+ }
+
+ private boolean isSameFile(File f1, File f2) throws IOException {
+ if (f1.exists()) {
+ try {
+ return f2.exists() && Files.isSameFile(f1.toPath(),
f2.toPath());
+ } catch (NoSuchFileException e) {
+ // file has been removed between exists check and isSameFile?
+ return false;
+ }
+ }
File f1Normalized = normalize(f1.getAbsolutePath());
File f2Normalized = normalize(f2.getAbsolutePath());
- return f1Normalized.equals(f2Normalized)
- || f1Normalized.getCanonicalFile().equals(f2Normalized
+ return f1Normalized.getCanonicalFile().equals(f2Normalized
.getCanonicalFile());
}