Class HardLink

java.lang.Object
org.apache.hadoop.fs.HardLink
Direct Known Subclasses:
FileUtil.HardLink

public class HardLink extends Object
Class for creating hardlinks. Supports Unix/Linux, Windows via winutils , and Mac OS X. The HardLink class was formerly a static inner class of FSUtil, and the methods provided were blatantly non-thread-safe. To enable volume-parallel Update snapshots, we now provide static threadsafe methods that allocate new buffer string arrays upon each call. We also provide an API to hardlink all files in a directory with a single command, which is up to 128 times more efficient - and minimizes the impact of the extra buffer creations.
  • Field Details

  • Constructor Details

    • HardLink

      public HardLink()
  • Method Details

    • createHardLink

      public static void createHardLink(File file, File linkName) throws IOException
      Creates a hardlink.
      Parameters:
      file - - existing source file
      linkName - - desired target link file
      Throws:
      IOException - raised on errors performing I/O.
    • createHardLinkMult

      public static void createHardLinkMult(File parentDir, String[] fileBaseNames, File linkDir) throws IOException
      Creates hardlinks from multiple existing files within one parent directory, into one target directory.
      Parameters:
      parentDir - - directory containing source files
      fileBaseNames - - list of path-less file names, as returned by parentDir.list()
      linkDir - - where the hardlinks should be put. It must already exist.
      Throws:
      IOException - raised on errors performing I/O.
    • supportsHardLink

      public static boolean supportsHardLink(File f)
      Determines whether the system supports hardlinks.
      Parameters:
      f - - file to examine
      Returns:
      true if hardlinks are supported, false otherwise
    • getLinkCount

      public static int getLinkCount(File fileName) throws IOException
      Retrieves the number of links to the specified file.
      Parameters:
      fileName - file name.
      Returns:
      link count.
      Throws:
      IOException - raised on errors performing I/O.