You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2022/10/03 18:06:21 UTC

[Bug 66293] New: Ant doesn't detect windows junctions as symlinks

https://bz.apache.org/bugzilla/show_bug.cgi?id=66293

            Bug ID: 66293
           Summary: Ant doesn't detect windows junctions as symlinks
           Product: Ant
           Version: 1.10.5
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core
          Assignee: notifications@ant.apache.org
          Reporter: maarten_coene@yahoo.com
  Target Milestone: ---

When a directory is a Windows NTFS Junction, Ant does not recognize it as a
symbolic link.

I think this used to work in Ant 1.9.x (not tested though), but it is broken
since the refactoring to use the Files.isSymbolicLink method. This method
doesn't detect NTFS Junctions.

Possible solutions to detect junctions are described in this post:
https://stackoverflow.com/questions/13733275/determine-whether-a-file-is-a-junction-in-windows-or-not

For instance:
boolean isWindows =
System.getProperty("os.name").toLowerCase().contains("windows")
BasicFileAttributes attrs = Files.readAttributes(aPath,
BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
boolean isJunction = isWindows && attrs.isDirectory() && attrs.isOther();

Maarten

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 66293] Ant doesn't detect windows junctions as symlinks

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66293

Jaikiran Pai <ja...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Jaikiran Pai <ja...@apache.org> ---
Hello Maarten, I don't have access to a Windows machine, so can't easily check.
Do you have some Ant build/example where this behaviour impacts Ant? That might
give us a better idea about what kind of impact this has.

P.S: I hadn't heard of Windows junctions before, so need to check what kind of
support Java itself provides for those.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 66293] Ant doesn't detect windows junctions as symlinks

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66293

--- Comment #2 from Maarten Coene <ma...@yahoo.com> ---
Hi Jaikiran,

consider following build.xml:

<project name="bug 66293">
  <target name="clean">
    <delete includeemptydirs="true">
      <fileset dir="build" followsymlinks="false" />
    </delete>
  </target>
</project>

Say I have the following directory structure:

/build.xml
/src/test.txt
/build/src -> junction to /src

If I run the Ant script, both the '/build' directory and the '/src/test.txt'
file are deleted.

I tested it with Ant 1.9 as well, it has the same issue, so it's not a
regression due to the symlink refactoring.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 66293] Ant doesn't detect windows junctions as symlinks

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66293

--- Comment #4 from Maarten Coene <ma...@yahoo.com> ---
I don't know how often they are used either. I'm a Windows user for a very long
time and never saw them in action. But I ran into this issue when using npm on
Windows. Seems like I'm not the only one, this is exactly the issue I had:
https://github.com/npm/cli/issues/5189

Yes I also think it would be great if we could support that. The stackoverflow
link I posted earlier contains 2 possible suggestions for how to detect Windows
Junctions using Java8 API.

- Using the Path.toRealPath() method: https://stackoverflow.com/a/29699473
- Using BasicFileAttributes: https://stackoverflow.com/a/48291462

Do you have a preference? I can try to submit a patch for this.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 66293] Ant doesn't detect windows junctions as symlinks

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66293

--- Comment #3 from Stefan Bodewig <bo...@apache.org> ---
I don't believe Ant has ever properly supported junctions - and the manual or
FAQ may even says so in some place.

Adding support would be a nice enhancement, of course.

I must admit I have no idea how widely used junctions are.

-- 
You are receiving this mail because:
You are the assignee for the bug.