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
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.
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.
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.
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.