Forráskód Böngészése

More fixes to get working directory to work on Windows. Long-term we should stop using java.io.File for our abstract file paths. On Windows, 'new File(/foo/bar).isAbsolute()' returns false, which caused lots of problems. So I have added a FileSystem.isAbsolute() method that we use internally. I also added a few more .getAbsoluteFile() calls to convert paths into absolute paths so that LocalFileSystem works correctly. Finally I took advantage of file status information cached in DFSFile, eliminating some namenode RPCs.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@390734 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 éve
szülő
commit
0caa6bc1b1

+ 2 - 2
src/java/org/apache/hadoop/conf/Configuration.java

@@ -273,10 +273,10 @@ public class Configuration {
     int hashCode = path.hashCode();
     for (int i = 0; i < dirs.length; i++) {  // try each local dir
       int index = (hashCode+i & Integer.MAX_VALUE) % dirs.length;
-      File file = new File(dirs[index], path);
+      File file = new File(dirs[index], path).getAbsoluteFile();
       File dir = file.getParentFile();
       if (dir.exists() || dir.mkdirs()) {
-        return file.getAbsoluteFile();
+        return file;
       }
     }
     throw new IOException("No valid local directories in property: "+dirsProp);

+ 3 - 0
src/java/org/apache/hadoop/dfs/DFSFile.java

@@ -57,6 +57,9 @@ class DFSFile extends File {
     public boolean isHidden() {
         return false;
     }
+    public boolean isAbsolute() {
+        return true;
+    }
 
     /**
      * We need to reimplement some of them

+ 15 - 2
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -54,7 +54,7 @@ public class DistributedFileSystem extends FileSystem {
     }
     
     private File makeAbsolute(File f) {
-      if (f.isAbsolute()) {
+      if (isAbsolute(f)) {
         return f;
       } else {
         return new File(workingDir, f.getPath());
@@ -102,10 +102,23 @@ public class DistributedFileSystem extends FileSystem {
     }
 
     public boolean isDirectory(File f) throws IOException {
+        if (f instanceof DFSFile) {
+          return ((DFSFile)f).isDirectory();
+        }
         return dfs.isDirectory(getPath(f));
     }
 
+    public boolean isAbsolute(File f) {
+      return f.isAbsolute() ||
+        f.getPath().startsWith("/") ||
+        f.getPath().startsWith("\\");
+    }
+
     public long getLength(File f) throws IOException {
+        if (f instanceof DFSFile) {
+          return ((DFSFile)f).length();
+        }
+
         DFSFileInfo info[] = dfs.listFiles(getPath(f));
         return info[0].getLen();
     }
@@ -282,7 +295,7 @@ public class DistributedFileSystem extends FileSystem {
         path.append(DFSFile.DFS_FILE_SEPARATOR);
         path.append(l.get(i));
       }
-      if (f.isAbsolute() && path.length() == 0) {
+      if (isAbsolute(f) && path.length() == 0) {
         path.append(DFSFile.DFS_FILE_SEPARATOR);
       }
       return path.toString();

+ 3 - 0
src/java/org/apache/hadoop/fs/FileSystem.java

@@ -265,6 +265,9 @@ public abstract class FileSystem extends Configured {
         }
     }
     
+    /** True iff the named path is absolute. */
+    public abstract boolean isAbsolute(File f);
+
     /** The number of bytes in a file. */
     public abstract long getLength(File f) throws IOException;
 

+ 5 - 1
src/java/org/apache/hadoop/fs/LocalFileSystem.java

@@ -153,7 +153,7 @@ public class LocalFileSystem extends FileSystem {
     }
 
     private File makeAbsolute(File f) {
-      if (f.isAbsolute()) {
+      if (isAbsolute(f)) {
         return f;
       } else {
         return new File(workingDir, f.toString());
@@ -199,6 +199,10 @@ public class LocalFileSystem extends FileSystem {
         return f.isDirectory();
     }
 
+    public boolean isAbsolute(File f) {
+      return f.isAbsolute();
+    }
+
     public long getLength(File f) throws IOException {
         f = makeAbsolute(f);
         return f.length();

+ 1 - 1
src/java/org/apache/hadoop/mapred/InputFormatBase.java

@@ -65,7 +65,7 @@ public abstract class InputFormatBase implements InputFormat {
     for (int i = 0; i < dirs.length; i++) {
       // if it is relative, make it absolute using the directory from the 
       // JobConf
-      if (workDir != null && !dirs[i].isAbsolute()) {
+      if (workDir != null && !fs.isAbsolute(dirs[i])) {
         dirs[i] = new File(workDir, dirs[i].toString());
       }
       File[] dir = fs.listFiles(dirs[i]);

+ 2 - 2
src/java/org/apache/hadoop/mapred/JobConf.java

@@ -99,8 +99,8 @@ public class JobConf extends Configuration {
   public void setJar(String jar) { set("mapred.jar", jar); }
 
   public File getSystemDir() {
-    return new File(get("mapred.system.dir",
-                                        "/tmp/hadoop/mapred/system"));
+    return new File(get("mapred.system.dir", "/tmp/hadoop/mapred/system"))
+      .getAbsoluteFile();
   }
 
   public String[] getLocalDirs() throws IOException {