Browse Source

HADOOP-4410. Adds an extra arg to the API FileUtil.makeShellPath to determine whether to canonicalize file paths or not. Contributed by Amareshwari Sriramadasu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@704818 13f79535-47bb-0310-9956-ffa450edef68
Devaraj Das 16 years ago
parent
commit
7e2ed8c879
2 changed files with 24 additions and 3 deletions
  1. 4 0
      CHANGES.txt
  2. 20 3
      src/core/org/apache/hadoop/fs/FileUtil.java

+ 4 - 0
CHANGES.txt

@@ -917,6 +917,10 @@ Release 0.19.0 - Unreleased
     HADOOP-4376. Fix formatting in hadoop-default.xml for
     HADOOP-4376. Fix formatting in hadoop-default.xml for
     hadoop.http.filter.initializers. (Enis Soztutar via acmurthy) 
     hadoop.http.filter.initializers. (Enis Soztutar via acmurthy) 
 
 
+    HADOOP-4410. Adds an extra arg to the API FileUtil.makeShellPath to
+    determine whether to canonicalize file paths or not.
+    (Amareshwari Sriramadasu via ddas)
+
 Release 0.18.2 - Unreleased
 Release 0.18.2 - Unreleased
 
 
   BUG FIXES
   BUG FIXES

+ 20 - 3
src/core/org/apache/hadoop/fs/FileUtil.java

@@ -392,7 +392,24 @@ public class FileUtil {
    * @throws IOException on windows, there can be problems with the subprocess
    * @throws IOException on windows, there can be problems with the subprocess
    */
    */
   public static String makeShellPath(File file) throws IOException {
   public static String makeShellPath(File file) throws IOException {
-    return makeShellPath(file.getCanonicalPath());
+    return makeShellPath(file, false);
+  }
+
+  /**
+   * Convert a os-native filename to a path that works for the shell.
+   * @param file The filename to convert
+   * @param makeCanonicalPath 
+   *          Whether to make canonical path for the file passed
+   * @return The unix pathname
+   * @throws IOException on windows, there can be problems with the subprocess
+   */
+  public static String makeShellPath(File file, boolean makeCanonicalPath) 
+  throws IOException {
+    if (makeCanonicalPath) {
+      return makeShellPath(file.getCanonicalPath());
+    } else {
+      return makeShellPath(file.toString());
+    }
   }
   }
 
 
   /**
   /**
@@ -570,8 +587,8 @@ public class FileUtil {
        hardLinkCommand[len-1] = target.getCanonicalPath();
        hardLinkCommand[len-1] = target.getCanonicalPath();
        hardLinkCommand[len-2] = linkName.getCanonicalPath();
        hardLinkCommand[len-2] = linkName.getCanonicalPath();
       } else {
       } else {
-       hardLinkCommand[len-2] = makeShellPath(target);
-       hardLinkCommand[len-1] = makeShellPath(linkName);
+       hardLinkCommand[len-2] = makeShellPath(target, true);
+       hardLinkCommand[len-1] = makeShellPath(linkName, true);
       }
       }
       // execute shell command
       // execute shell command
       Process process = Runtime.getRuntime().exec(hardLinkCommand);
       Process process = Runtime.getRuntime().exec(hardLinkCommand);