You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cu...@apache.org on 2008/01/25 20:35:47 UTC

svn commit: r615314 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/RawLocalFileSystem.java src/test/org/apache/hadoop/fs/TestLocalFileSystem.java

Author: cutting
Date: Fri Jan 25 11:35:46 2008
New Revision: 615314

URL: http://svn.apache.org/viewvc?rev=615314&view=rev
Log:
HADOOP-2626.  Fix paths with special characters to work correctly with the local filesystem.  Contributed by Thomas Friol.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
    hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=615314&r1=615313&r2=615314&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Jan 25 11:35:46 2008
@@ -567,6 +567,10 @@
     HADOOP-2640. Fix a bug in MultiFileSplitInputFormat that was always
     returning 1 split in some circumstances. (Enis Soztutar via nigel)
 
+    HADOOP-2626. Fix paths with special characters to work correctly
+    with the local filesystem.  (Thomas Friol via cutting)
+
+
 Release 0.15.3 - 2008-01-18
 
   BUG FIXES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=615314&r1=615313&r2=615314&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java Fri Jan 25 11:35:46 2008
@@ -232,7 +232,7 @@
     }
     if (localf.isFile()) {
       return new FileStatus[] {
-          new RawLocalFileStatus(localf, getDefaultBlockSize()) };
+          new RawLocalFileStatus(localf, getDefaultBlockSize(), this) };
     }
 
     String[] names = localf.list();
@@ -360,7 +360,7 @@
   }
   
   public FileStatus getFileStatus(Path f) {
-    return new RawLocalFileStatus(pathToFile(f), getDefaultBlockSize());
+    return new RawLocalFileStatus(pathToFile(f), getDefaultBlockSize(), this);
   }
 
   static class RawLocalFileStatus extends FileStatus {
@@ -372,9 +372,9 @@
       return !super.getOwner().equals(""); 
     }
     
-    RawLocalFileStatus(File f, long defaultBlockSize) {
+    RawLocalFileStatus(File f, long defaultBlockSize, FileSystem fs) {
       super(f.length(), f.isDirectory(), 1, defaultBlockSize,
-            f.lastModified(), new Path(f.toURI().toString()));
+            f.lastModified(), new Path(f.getPath()).makeQualified(fs));
     }
     
     @Override

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java?rev=615314&r1=615313&r2=615314&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java Fri Jan 25 11:35:46 2008
@@ -25,6 +25,9 @@
  * This class tests the local file system via the FileSystem abstraction.
  */
 public class TestLocalFileSystem extends TestCase {
+  private static String TEST_ROOT_DIR
+    = System.getProperty("test.build.data","build/test/data/work-dir/localfs");
+
 
   private void writeFile(FileSystem fs, Path name) throws IOException {
     FSDataOutputStream stm = fs.create(name);
@@ -45,7 +48,7 @@
     Configuration conf = new Configuration();
     FileSystem fileSys = FileSystem.getLocal(conf);
     Path origDir = fileSys.getWorkingDirectory();
-    Path subdir = new Path("build/test/data/work-dir/new subdir");
+    Path subdir = new Path(TEST_ROOT_DIR, "new");
     try {
       // make sure it doesn't already exist
       assertTrue(!fileSys.exists(subdir));
@@ -100,6 +103,16 @@
       .makeQualified(fileSys);
     Path fsHome = fileSys.getHomeDirectory();
     assertEquals(home, fsHome);
+  }
+
+  public void testPathEscapes() throws IOException {
+    Configuration conf = new Configuration();
+    FileSystem fs = FileSystem.getLocal(conf);
+    Path path = new Path(TEST_ROOT_DIR, "foo%bar");
+    writeFile(fs, path);
+    FileStatus status = fs.getFileStatus(path);
+    assertEquals(path.makeQualified(fs), status.getPath());
+    cleanupFile(fs, path);
   }
 
 }