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 9001e3578 replace File#getCanonicalPath with FileUtils#getResolvedPath
9001e3578 is described below

commit 9001e35782b67d2f0ba250ea7f340da8be935fa2
Author: Stefan Bodewig <[email protected]>
AuthorDate: Fri Feb 6 21:59:12 2026 +0100

    replace File#getCanonicalPath with FileUtils#getResolvedPath
---
 src/main/org/apache/tools/ant/taskdefs/Expand.java      |  4 ++--
 .../apache/tools/ant/taskdefs/ManifestClassPath.java    |  2 +-
 src/main/org/apache/tools/ant/taskdefs/Move.java        |  4 +++-
 .../optional/extension/resolvers/AntResolver.java       |  5 ++++-
 .../org/apache/tools/ant/taskdefs/optional/net/FTP.java |  2 +-
 .../ant/taskdefs/optional/net/FTPTaskMirrorImpl.java    |  2 +-
 .../tools/ant/taskdefs/optional/unix/Symlink.java       | 12 ++++++++----
 src/main/org/apache/tools/ant/util/FileUtils.java       | 17 +++++++++--------
 8 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java 
b/src/main/org/apache/tools/ant/taskdefs/Expand.java
index e607a6a4a..0c1cb7c6e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Expand.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java
@@ -331,8 +331,8 @@ public class Expand extends Task {
         }
         File f = fileUtils.resolveFile(dir, mappedNames[0]);
         if (!allowedOutsideOfDest && !fileUtils.isLeadingPath(dir, f, true)) {
-            log("skipping " + entryName + " as its target " + 
f.getCanonicalPath()
-                + " is outside of " + dir.getCanonicalPath() + ".", 
Project.MSG_VERBOSE);
+            log("skipping " + entryName + " as its target " + 
FILE_UTILS.getResolvedPath(f)
+                + " is outside of " + FILE_UTILS.getResolvedPath(dir) + ".", 
Project.MSG_VERBOSE);
                 return;
         }
 
diff --git a/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java 
b/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java
index a1710bf9e..f06efa60b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java
+++ b/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java
@@ -92,7 +92,7 @@ public class ManifestClassPath extends Task {
                     relPath = FileUtils.getRelativePath(dir, pathEntry);
                 }
 
-                canonicalPath = pathEntry.getCanonicalPath();
+                canonicalPath = fileUtils.getResolvedPath(pathEntry);
                 // getRelativePath always uses '/' as separator, adapt
                 if (File.separatorChar != '/') {
                     canonicalPath =
diff --git a/src/main/org/apache/tools/ant/taskdefs/Move.java 
b/src/main/org/apache/tools/ant/taskdefs/Move.java
index 7dadc1bbf..2555beab5 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Move.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Move.java
@@ -362,7 +362,9 @@ public class Move extends Copy {
         if (parent != null && !parent.exists()) {
             parent.mkdirs();
         } else if (destFile.isFile()) {
-            sourceFile = 
getFileUtils().normalize(sourceFile.getAbsolutePath()).getCanonicalFile();
+            sourceFile = new File(getFileUtils()
+                                  .getResolvedPath(getFileUtils()
+                                                   
.normalize(sourceFile.getAbsolutePath())));
             destFile = getFileUtils().normalize(destFile.getAbsolutePath());
             if 
(destFile.getAbsolutePath().equals(sourceFile.getAbsolutePath())) {
                 //no point in renaming a file to its own canonical version...
diff --git 
a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java
 
b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java
index b02e41427..6501332c6 100644
--- 
a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java
+++ 
b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java
@@ -25,12 +25,15 @@ import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Ant;
 import org.apache.tools.ant.taskdefs.optional.extension.Extension;
 import org.apache.tools.ant.taskdefs.optional.extension.ExtensionResolver;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Resolver that just returns s specified location.
  *
  */
 public class AntResolver implements ExtensionResolver {
+    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
     private File antfile;
     private File destfile;
     private String target;
@@ -78,7 +81,7 @@ public class AntResolver implements ExtensionResolver {
 
         try {
             final File dir =
-                antfile.getParentFile().getCanonicalFile();
+                new File(FILE_UTILS.getResolvedPath(antfile.getParentFile()));
             ant.setDir(dir);
         } catch (final IOException ioe) {
             throw new BuildException(ioe.getMessage(), ioe);
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java 
b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
index 33b4c1287..3addb1808 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
@@ -2069,7 +2069,7 @@ public class FTP extends Task implements FTPTaskConfig {
             // because of race conditions occurring on Windows
             Delete mydelete = new Delete();
             mydelete.bindToOwner(this);
-            mydelete.setFile(tempFile.getCanonicalFile());
+            mydelete.setFile(new File(FILE_UTILS.getResolvedPath(tempFile)));
             mydelete.execute();
         } catch (Exception e) {
             throw new BuildException(e, getLocation());
diff --git 
a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java 
b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java
index 636f54783..77816de24 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java
@@ -1359,7 +1359,7 @@ public class FTPTaskMirrorImpl implements FTPTaskMirror {
             // because of race conditions occurring on Windows
             Delete mydelete = new Delete();
             mydelete.bindToOwner(task);
-            mydelete.setFile(tempFile.getCanonicalFile());
+            mydelete.setFile(new File(FILE_UTILS.getResolvedPath(tempFile)));
             mydelete.execute();
         } catch (Exception e) {
             throw new BuildException(e, task.getLocation());
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java 
b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
index 7cc0c022b..528b02e81 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
@@ -56,6 +56,7 @@ import org.apache.tools.ant.dispatch.DispatchTask;
 import org.apache.tools.ant.dispatch.DispatchUtils;
 import org.apache.tools.ant.taskdefs.LogOutputStream;
 import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Creates, Deletes, Records and Restores Symlinks.
@@ -108,6 +109,8 @@ import org.apache.tools.ant.types.FileSet;
  */
 public class Symlink extends DispatchTask {
 
+    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
     private String resource;
     private String link;
     private List<FileSet> fileSets = new ArrayList<>();
@@ -210,7 +213,7 @@ public class Symlink extends DispatchTask {
                 final String resource = links.getProperty(link);
                 try {
                     if (Files.isSymbolicLink(Paths.get(link)) &&
-                            new File(link).getCanonicalPath().equals(new 
File(resource).getCanonicalPath())) {
+                        FILE_UTILS.getResolvedPath(new 
File(link)).equals(FILE_UTILS.getResolvedPath(new File(resource)))) {
                         // it's already a symlink and the symlink target is 
the same
                         // as the target noted in the properties file. So 
there's no
                         // need to recreate it
@@ -265,7 +268,7 @@ public class Symlink extends DispatchTask {
                 // fill up a Properties object with link and resource names:
                 for (File link : linksInDir) {
                     try {
-                        linksToStore.put(link.getName(), 
link.getCanonicalPath());
+                        linksToStore.put(link.getName(), 
FILE_UTILS.getResolvedPath(link));
                     } catch (IOException ioe) {
                         handleError("Couldn't get canonical name of parent 
link");
                     }
@@ -511,7 +514,8 @@ public class Symlink extends DispatchTask {
                             final String name = f.getName();
                             // we use the canonical path of the parent dir in 
which the (potential)
                             // link resides
-                            final File parentDirCanonicalizedFile = new 
File(pf.getCanonicalPath(), name);
+                            final File parentDirCanonicalizedFile =
+                                new File(FILE_UTILS.getResolvedPath(pf), name);
                             if 
(Files.isSymbolicLink(parentDirCanonicalizedFile.toPath())) {
                                 result.add(parentDirCanonicalizedFile);
                             }
@@ -552,7 +556,7 @@ public class Symlink extends DispatchTask {
                 try (InputStream is = new BufferedInputStream(
                     Files.newInputStream(inc.toPath()))) {
                     links.load(is);
-                    pf = pf.getCanonicalFile();
+                    pf = new File(FILE_UTILS.getResolvedPath(pf));
                 } catch (FileNotFoundException fnfe) {
                     handleError("Unable to find " + name + "; skipping it.");
                     continue;
diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java 
b/src/main/org/apache/tools/ant/util/FileUtils.java
index e6b49b75f..7739432b1 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -1321,15 +1321,15 @@ public class FileUtils {
      * @return true if path starts with leading; false otherwise.
      * @since Ant 1.10.5
      * @throws IOException if resolveSymlinks is true and invoking
-     * getCanonicaPath on either argument throws an exception
+     * getCanonicaPath/toRealPath on either argument throws an exception
      */
     public boolean isLeadingPath(File leading, File path, boolean 
resolveSymlinks)
         throws IOException {
         if (!resolveSymlinks) {
             return isLeadingPath(leading, path);
         }
-        final File l = leading.getCanonicalFile();
-        File p = path.getCanonicalFile();
+        final File l = new File(getResolvedPath(leading));
+        File p = new File(getResolvedPath(path));
         do {
             if (l.equals(p)) {
                 return true;
@@ -1436,8 +1436,7 @@ public class FileUtils {
         }
         File f1Normalized = normalize(f1.getAbsolutePath());
         File f2Normalized = normalize(f2.getAbsolutePath());
-        return f1Normalized.getCanonicalFile().equals(f2Normalized
-                                                      .getCanonicalFile());
+        return 
getResolvedPath(f1Normalized).equals(getResolvedPath(f2Normalized));
     }
 
     /**
@@ -1478,7 +1477,7 @@ public class FileUtils {
     public void rename(File from, File to, boolean keepTargetFilePermissions) 
throws IOException {
         Set<PosixFilePermission> existingFilePermissions = null;
         // identical logic lives in Move.renameFile():
-        from = normalize(from.getAbsolutePath()).getCanonicalFile();
+        from = new File(getResolvedPath(normalize(from.getAbsolutePath())));
         to = normalize(to.getAbsolutePath());
         if (!from.exists()) {
             System.err.println("Cannot rename nonexistent file " + from);
@@ -1788,12 +1787,14 @@ public class FileUtils {
      * @return the relative path between the files
      * @throws Exception for undocumented reasons
      * @see File#getCanonicalPath()
+     * @see #getResolvedPath
+     * @see Path#toRealPath
      *
      * @since Ant 1.7
      */
     public static String getRelativePath(File fromFile, File toFile) throws 
Exception { //NOSONAR
-        String fromPath = fromFile.getCanonicalPath();
-        String toPath = toFile.getCanonicalPath();
+        String fromPath = PRIMARY_INSTANCE.getResolvedPath(fromFile);
+        String toPath = PRIMARY_INSTANCE.getResolvedPath(toFile);
 
         // build the path stack info to compare
         String[] fromPathStack = getPathStack(fromPath);

Reply via email to