|
@@ -25,9 +25,11 @@ import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
+import org.apache.hadoop.util.Shell;
|
|
|
+
|
|
|
/**
|
|
|
* Class for creating hardlinks.
|
|
|
- * Supports Unix/Linux, WinXP/2003/Vista via Cygwin, and Mac OS X.
|
|
|
+ * 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.
|
|
@@ -41,7 +43,7 @@ public class HardLink {
|
|
|
|
|
|
public enum OSType {
|
|
|
OS_TYPE_UNIX,
|
|
|
- OS_TYPE_WINXP,
|
|
|
+ OS_TYPE_WIN,
|
|
|
OS_TYPE_SOLARIS,
|
|
|
OS_TYPE_MAC
|
|
|
}
|
|
@@ -55,7 +57,7 @@ public class HardLink {
|
|
|
//methods without instantiating the HardLink object
|
|
|
static {
|
|
|
osType = getOSType();
|
|
|
- if (osType == OSType.OS_TYPE_WINXP) {
|
|
|
+ if (osType == OSType.OS_TYPE_WIN) {
|
|
|
// Windows
|
|
|
getHardLinkCommand = new HardLinkCGWin();
|
|
|
} else {
|
|
@@ -79,14 +81,8 @@ public class HardLink {
|
|
|
|
|
|
static private OSType getOSType() {
|
|
|
String osName = System.getProperty("os.name");
|
|
|
- if (osName.contains("Windows") &&
|
|
|
- (osName.contains("XP")
|
|
|
- || osName.contains("2003")
|
|
|
- || osName.contains("Vista")
|
|
|
- || osName.contains("Windows_7")
|
|
|
- || osName.contains("Windows 7")
|
|
|
- || osName.contains("Windows7"))) {
|
|
|
- return OSType.OS_TYPE_WINXP;
|
|
|
+ if (Shell.WINDOWS) {
|
|
|
+ return OSType.OS_TYPE_WIN;
|
|
|
}
|
|
|
else if (osName.contains("SunOS")
|
|
|
|| osName.contains("Solaris")) {
|
|
@@ -266,14 +262,16 @@ public class HardLink {
|
|
|
//unit testing (sort of) on non-Win servers
|
|
|
|
|
|
static String[] hardLinkCommand = {
|
|
|
- "fsutil","hardlink","create", null, null};
|
|
|
+ Shell.WINUTILS,"hardlink","create", null, null};
|
|
|
static String[] hardLinkMultPrefix = {
|
|
|
"cmd","/q","/c","for", "%f", "in", "("};
|
|
|
static String hardLinkMultDir = "\\%f";
|
|
|
static String[] hardLinkMultSuffix = {
|
|
|
- ")", "do", "fsutil", "hardlink", "create", null,
|
|
|
+ ")", "do", Shell.WINUTILS, "hardlink", "create", null,
|
|
|
"%f", "1>NUL"};
|
|
|
- static String[] getLinkCountCommand = {"stat","-c%h", null};
|
|
|
+ static String[] getLinkCountCommand = {
|
|
|
+ Shell.WINUTILS, "hardlink",
|
|
|
+ "stat", null};
|
|
|
//Windows guarantees only 8K - 1 bytes cmd length.
|
|
|
//Subtract another 64b to allow for Java 'exec' overhead
|
|
|
static final int maxAllowedCmdArgLength = 8*1024 - 65;
|
|
@@ -324,12 +322,6 @@ public class HardLink {
|
|
|
String[] buf = new String[getLinkCountCommand.length];
|
|
|
System.arraycopy(getLinkCountCommand, 0, buf, 0,
|
|
|
getLinkCountCommand.length);
|
|
|
- //The linkCount command is actually a Cygwin shell command,
|
|
|
- //not a Windows shell command, so we should use "makeShellPath()"
|
|
|
- //instead of "getCanonicalPath()". However, that causes another
|
|
|
- //shell exec to "cygpath.exe", and "stat.exe" actually can handle
|
|
|
- //DOS-style paths (it just prints a couple hundred bytes of warning
|
|
|
- //to stderr), so we use the more efficient "getCanonicalPath()".
|
|
|
buf[getLinkCountCommand.length - 1] = file.getCanonicalPath();
|
|
|
return buf;
|
|
|
}
|
|
@@ -350,7 +342,7 @@ public class HardLink {
|
|
|
//add the fixed overhead of the hardLinkMult command
|
|
|
//(prefix, suffix, and Dir suffix)
|
|
|
sum += ("cmd.exe /q /c for %f in ( ) do "
|
|
|
- + "fsutil hardlink create \\%f %f 1>NUL ").length();
|
|
|
+ + Shell.WINUTILS + " hardlink create \\%f %f 1>NUL ").length();
|
|
|
return sum;
|
|
|
}
|
|
|
|
|
@@ -577,14 +569,10 @@ public class HardLink {
|
|
|
/* Create an IOException for failing to get link count. */
|
|
|
private static IOException createIOException(File f, String message,
|
|
|
String error, int exitvalue, Exception cause) {
|
|
|
-
|
|
|
- final String winErrMsg = "; Windows errors in getLinkCount are often due "
|
|
|
- + "to Cygwin misconfiguration";
|
|
|
|
|
|
final String s = "Failed to get link count on file " + f
|
|
|
+ ": message=" + message
|
|
|
+ "; error=" + error
|
|
|
- + ((osType == OSType.OS_TYPE_WINXP) ? winErrMsg : "")
|
|
|
+ "; exit value=" + exitvalue;
|
|
|
return (cause == null) ? new IOException(s) : new IOException(s, cause);
|
|
|
}
|