org.apache.tools.ant.util

## Class SymbolicLinkUtils

- java.lang.Object
- - org.apache.tools.ant.util.SymbolicLinkUtils

-     public class SymbolicLinkUtils
      extends java.lang.Object

  Contains methods related to symbolic links - or what Ant thinks is a symbolic link based on the absent support for them in Java.
  Since:
    Ant 1.8.0

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `SymbolicLinkUtils()` Empty constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `deleteSymbolicLink(java.io.File link, Task task)` Delete a symlink (without deleting the associated resource).
    `static SymbolicLinkUtils` | `getSymbolicLinkUtils()` Method to retrieve The SymbolicLinkUtils, which is shared by all users of this method.
    `boolean` | `isDanglingSymbolicLink(java.io.File file)` Checks whether a given file is a broken symbolic link.
    `boolean` | `isDanglingSymbolicLink(java.io.File parent, java.lang.String name)` Checks whether a given file is a broken symbolic link.
    `boolean` | `isDanglingSymbolicLink(java.lang.String name)` Checks whether a given file is a broken symbolic link.
    `boolean` | `isSymbolicLink(java.io.File file)` Checks whether a given file is a symbolic link.
    `boolean` | `isSymbolicLink(java.io.File parent, java.lang.String name)` Checks whether a given file is a symbolic link.
    `boolean` | `isSymbolicLink(java.lang.String name)` Checks whether a given file is a symbolic link.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SymbolicLinkUtils

          protected SymbolicLinkUtils()

      Empty constructor.

  - ### Method Detail

    - #### getSymbolicLinkUtils

          public static SymbolicLinkUtils getSymbolicLinkUtils()

      Method to retrieve The SymbolicLinkUtils, which is shared by all users of this method.
      Returns:
        an instance of SymbolicLinkUtils.

    - #### isSymbolicLink

          public boolean isSymbolicLink(java.io.File file)
                                 throws java.io.IOException

      Checks whether a given file is a symbolic link.

      It doesn't really test for symbolic links but whether the canonical and absolute paths of the file are identical--this may lead to false positives on some platforms.

      Parameters:
        `file` - the file to test. Must not be null.
      Returns:
        true if the file is a symbolic link.
      Throws:
        `java.io.IOException` - on error.

    - #### isSymbolicLink

          public boolean isSymbolicLink(java.lang.String name)
                                 throws java.io.IOException

      Checks whether a given file is a symbolic link.

      It doesn't really test for symbolic links but whether the canonical and absolute paths of the file are identical--this may lead to false positives on some platforms.

      Parameters:
        `name` - the name of the file to test.
      Returns:
        true if the file is a symbolic link.
      Throws:
        `java.io.IOException` - on error.

    - #### isSymbolicLink

          public boolean isSymbolicLink(java.io.File parent,
                                        java.lang.String name)
                                 throws java.io.IOException

      Checks whether a given file is a symbolic link.

      It doesn't really test for symbolic links but whether the canonical and absolute paths of the file are identical--this may lead to false positives on some platforms.

      Parameters:
        `parent` - the parent directory of the file to test
        `name` - the name of the file to test.
      Returns:
        true if the file is a symbolic link.
      Throws:
        `java.io.IOException` - on error.

    - #### isDanglingSymbolicLink

          public boolean isDanglingSymbolicLink(java.lang.String name)
                                         throws java.io.IOException

      Checks whether a given file is a broken symbolic link.

      It doesn't really test for symbolic links but whether Java reports that the File doesn't exist but its parent's child list contains it--this may lead to false positives on some platforms.

      Note that #isSymbolicLink returns false if this method returns true since Java won't produce a canonical name different from the absolute one if the link is broken.

      Parameters:
        `name` - the name of the file to test.
      Returns:
        true if the file is a broken symbolic link.
      Throws:
        `java.io.IOException` - on error.

    - #### isDanglingSymbolicLink

          public boolean isDanglingSymbolicLink(java.io.File file)
                                         throws java.io.IOException

      Checks whether a given file is a broken symbolic link.

      It doesn't really test for symbolic links but whether Java reports that the File doesn't exist but its parent's child list contains it--this may lead to false positives on some platforms.

      Note that #isSymbolicLink returns false if this method returns true since Java won't produce a canonical name different from the absolute one if the link is broken.

      Parameters:
        `file` - the file to test.
      Returns:
        true if the file is a broken symbolic link.
      Throws:
        `java.io.IOException` - on error.

    - #### isDanglingSymbolicLink

          public boolean isDanglingSymbolicLink(java.io.File parent,
                                                java.lang.String name)
                                         throws java.io.IOException

      Checks whether a given file is a broken symbolic link.

      It doesn't really test for symbolic links but whether Java reports that the File doesn't exist but its parent's child list contains it--this may lead to false positives on some platforms.

      Note that #isSymbolicLink returns false if this method returns true since Java won't produce a canonical name different from the absolute one if the link is broken.

      Parameters:
        `parent` - the parent directory of the file to test
        `name` - the name of the file to test.
      Returns:
        true if the file is a broken symbolic link.
      Throws:
        `java.io.IOException` - on error.

    - #### deleteSymbolicLink

          public void deleteSymbolicLink(java.io.File link,
                                         Task task)
                                  throws java.io.IOException

      Delete a symlink (without deleting the associated resource).

      This is a utility method that removes a unix symlink without removing the resource that the symlink points to. If it is accidentally invoked on a real file, the real file will not be harmed, but silently ignored.

      Normally this method works by getting the canonical path of the link, using the canonical path to rename the resource (breaking the link) and then deleting the link. The resource is then returned to its original name inside a finally block to ensure that the resource is unharmed even in the event of an exception.

      There may be cases where the algorithm described above doesn't work, in that case the method tries to use the native "rm" command on the symlink instead.

      Parameters:
        `link` - A `File` object of the symlink to delete.
        `task` - An Ant Task required if "rm" needs to be invoked.
      Throws:
        `java.io.IOException` - If calls to `File.rename`, `File.delete` or `File.getCanonicalPath` fail.
        `BuildException` - if the execution of "rm" failed.