Package org.apache.bookkeeper.util
Class HardLink
java.lang.Object
org.apache.bookkeeper.util.HardLink
Class for creating hardlinks.
Supports Unix/Linux, WinXP/2003/Vista via Cygwin, 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classImplementation of HardLinkCommandGetter class for Unix.(package private) static classImplementation of HardLinkCommandGetter class for Windows.static classHardLink statistics counters and methods.static enumOS Types. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateHardLink(File file, File linkName) Creates a hardlink.static voidcreateHardLinkMult(File parentDir, String[] fileBaseNames, File linkDir) Creates hardlinks from multiple existing files within one parent directory, into one target directory.protected static intcreateHardLinkMult(File parentDir, String[] fileBaseNames, File linkDir, int maxLength) (package private) static voidenableJdkLinkApi(boolean enable) static intgetLinkCount(File fileName) Retrieves the number of links to the specified file.protected static intgetLinkMultArgLength(File fileDir, String[] fileBaseNames, File linkDir) Calculate the nominal length of all contributors to the total commandstring length, including fixed overhead of the OS-dependent command.protected static intReturn this private value for use by unit tests.static StringmakeShellPath(File file) Convert a os-native filename to a path that works for the shell.
-
Field Details
-
OS_TYPE
-
linkStats
-
-
Constructor Details
-
HardLink
public HardLink()
-
-
Method Details
-
getLinkMultArgLength
protected static int getLinkMultArgLength(File fileDir, String[] fileBaseNames, File linkDir) throws IOException Calculate the nominal length of all contributors to the total commandstring length, including fixed overhead of the OS-dependent command. It's protected rather than private, to assist unit testing, but real clients are not expected to need it -- see the way createHardLinkMult() uses it internally so the user doesn't need to worry about it.- Parameters:
fileDir- - source directory, parent of fileBaseNamesfileBaseNames- - array of path-less file names, relative to the source directorylinkDir- - target directory where the hardlinks will be put- Returns:
- - total data length (must not exceed maxAllowedCmdArgLength)
- Throws:
IOException
-
getMaxAllowedCmdArgLength
protected static int getMaxAllowedCmdArgLength()Return this private value for use by unit tests. Shell commands are not allowed to have a total string length exceeding this size. -
enableJdkLinkApi
static void enableJdkLinkApi(boolean enable) -
createHardLink
Creates a hardlink.- Parameters:
file- - existing source filelinkName- - desired target link file- Throws:
IOException
-
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 filesfileBaseNames- - list of path-less file names, as returned by parentDir.list()linkDir- - where the hardlinks should be put. It must already exist. If the list of files is too long (overflows maxAllowedCmdArgLength), we will automatically split it into multiple invocations of the underlying method.- Throws:
IOException
-
createHardLinkMult
protected static int createHardLinkMult(File parentDir, String[] fileBaseNames, File linkDir, int maxLength) throws IOException - Throws:
IOException
-
getLinkCount
Retrieves the number of links to the specified file.- Throws:
IOException
-
makeShellPath
Convert a os-native filename to a path that works for the shell.- Parameters:
file- The file to convert- Returns:
- The unix pathname
- Throws:
IOException- on windows, there can be problems with the subprocess
-