hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r540359 - in /lucene/hadoop/trunk: ./ src/contrib/hbase/src/java/org/apache/hadoop/hbase/ src/java/org/apache/hadoop/fs/ src/test/org/apache/hadoop/fs/
Date Mon, 21 May 2007 23:30:41 GMT
Author: cutting
Date: Mon May 21 16:30:40 2007
New Revision: 540359

URL: http://svn.apache.org/viewvc?view=rev&rev=540359
Log:
HADOOP-1386.  Fix Path to not permit the empty string as a path, as this has lead to accidental
file deletion.  Instead force applications to use '.' to name the default directory.  Contributed
by Hairong.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HStoreFile.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/InMemoryFileSystem.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java
    lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestPath.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=540359&r1=540358&r2=540359
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Mon May 21 16:30:40 2007
@@ -457,6 +457,11 @@
 123. HADOOP-1385.  Fix MD5Hash#hashCode() to generally hash to more
      than 256 values.  (omalley via cutting)
 
+124. HADOOP-1386.  Fix Path to not permit the empty string as a
+     path, as this has lead to accidental file deletion.  Instead
+     force applications to use "." to name the default directory.
+     (Hairong Kuang via cutting)
+
 
 Release 0.12.3 - 2007-04-06
 

Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HStoreFile.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HStoreFile.java?view=diff&rev=540359&r1=540358&r2=540359
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HStoreFile.java
(original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/HStoreFile.java
Mon May 21 16:30:40 2007
@@ -54,7 +54,7 @@
    */
   public HStoreFile(Configuration conf) {
     this.conf = conf;
-    this.dir = new Path("");
+    this.dir = new Path(Path.CUR_DIR);
     this.regionName = new Text();
     this.colFamily = new Text();
     this.fileId = 0;

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java?view=diff&rev=540359&r1=540358&r2=540359
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java Mon May 21 16:30:40 2007
@@ -1015,13 +1015,13 @@
         if (i < argv.length) {
           exitCode = doall(cmd, argv, conf, i);
         } else {
-          ls("", false);
+          ls(Path.CUR_DIR, false);
         } 
       } else if ("-lsr".equals(cmd)) {
         if (i < argv.length) {
           exitCode = doall(cmd, argv, conf, i);
         } else {
-          ls("", true);
+          ls(Path.CUR_DIR, true);
         } 
       } else if ("-mv".equals(cmd)) {
         exitCode = rename(argv, conf);

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/InMemoryFileSystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/InMemoryFileSystem.java?view=diff&rev=540359&r1=540358&r2=540359
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/InMemoryFileSystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/InMemoryFileSystem.java Mon May 21 16:30:40
2007
@@ -68,7 +68,11 @@
       int size = Integer.parseInt(conf.get("fs.inmemory.size.mb", "100"));
       this.fsSize = size * 1024 * 1024;
       this.uri = URI.create(uri.getScheme() + "://" + uri.getAuthority());
-      this.staticWorkingDir = new Path(this.uri.getPath());
+      String path = this.uri.getPath();
+      if (path.length() == 0) {
+        path = Path.CUR_DIR;
+      }
+      this.staticWorkingDir = new Path(path);
       LOG.info("Initialized InMemoryFileSystem: " + uri.toString() + 
                " of size (in bytes): " + fsSize);
     }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java?view=diff&rev=540359&r1=540358&r2=540359
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Path.java Mon May 21 16:30:40 2007
@@ -18,7 +18,6 @@
 
 package org.apache.hadoop.fs;
 
-import java.util.*;
 import java.net.*;
 import java.io.*;
 
@@ -34,6 +33,8 @@
   public static final String SEPARATOR = "/";
   public static final char SEPARATOR_CHAR = '/';
   
+  public static final String CUR_DIR = ".";
+  
   static final boolean WINDOWS
     = System.getProperty("os.name").startsWith("Windows");
 
@@ -71,9 +72,23 @@
                normalizePath(resolved.getPath()));
   }
 
+  private void checkPathArg( String path ) {
+    // disallow construction of a Path from an empty string
+    if ( path == null ) {
+      throw new IllegalArgumentException(
+          "Can not create a Path from a null string");
+    }
+    if( path.length() == 0 ) {
+       throw new IllegalArgumentException(
+           "Can not create a Path from an empty string");
+    }   
+  }
+  
   /** Construct a path from a String.  Path strings are URIs, but with
    * unescaped elements and some additional normalization. */
   public Path(String pathString) {
+    checkPathArg( pathString );
+    
     // We can't use 'new URI(String)' directly, since it assumes things are
     // escaped, which we don't require of Paths. 
     
@@ -113,6 +128,7 @@
 
   /** Construct a Path from components. */
   public Path(String scheme, String authority, String path) {
+    checkPathArg( path );
     initialize(scheme, authority, path);
   }
 
@@ -183,7 +199,7 @@
     }
     String parent;
     if (lastSlash==-1) {
-      parent = "";
+      parent = CUR_DIR;
     } else {
       int end = hasWindowsDrive(path, true) ? 3 : 0;
       parent = path.substring(0, lastSlash==end?end+1:lastSlash);

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestPath.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestPath.java?view=diff&rev=540359&r1=540358&r2=540359
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestPath.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestPath.java Mon May 21 16:30:40 2007
@@ -28,7 +28,14 @@
     toStringTest("/foo/bar");
     toStringTest("foo");
     toStringTest("foo/bar");
-    toStringTest("");
+    boolean emptyException = false;
+    try {
+      toStringTest("");
+    } catch (IllegalArgumentException e) {
+      // expect to receive an IllegalArgumentException
+      emptyException = true;
+    }
+    assertTrue(emptyException);
     if (Path.WINDOWS) {
       toStringTest("c:");
       toStringTest("c:/");
@@ -60,7 +67,7 @@
     assertTrue(new Path("/foo").isAbsolute());
     assertFalse(new Path("foo").isAbsolute());
     assertFalse(new Path("foo/bar").isAbsolute());
-    assertFalse(new Path("").isAbsolute());
+    assertFalse(new Path(".").isAbsolute());
     if (Path.WINDOWS) {
       assertTrue(new Path("c:/a/b").isAbsolute());
       assertFalse(new Path("c:a/b").isAbsolute());
@@ -77,14 +84,14 @@
   }
 
   public void testChild() {
-    assertEquals(new Path(""), new Path("", ""));
-    assertEquals(new Path("/"), new Path("/", ""));
-    assertEquals(new Path("/"), new Path("", "/"));
+    assertEquals(new Path("."), new Path(".", "."));
+    assertEquals(new Path("/"), new Path("/", "."));
+    assertEquals(new Path("/"), new Path(".", "/"));
     assertEquals(new Path("/foo"), new Path("/", "foo"));
     assertEquals(new Path("/foo/bar"), new Path("/foo", "bar"));
     assertEquals(new Path("/foo/bar/baz"), new Path("/foo/bar", "baz"));
     assertEquals(new Path("/foo/bar/baz"), new Path("/foo", "bar/baz"));
-    assertEquals(new Path("foo"), new Path("", "foo"));
+    assertEquals(new Path("foo"), new Path(".", "foo"));
     assertEquals(new Path("foo/bar"), new Path("foo", "bar"));
     assertEquals(new Path("foo/bar/baz"), new Path("foo", "bar/baz"));
     assertEquals(new Path("foo/bar/baz"), new Path("foo/bar", "baz"));
@@ -122,7 +129,7 @@
     
     assertEquals(new Path("/foo/bar","../../boo/bud").toString(), "/boo/bud");
     assertEquals(new Path("foo/bar","../../boo/bud").toString(), "boo/bud");
-    assertEquals(new Path("","boo/bud").toString(), "boo/bud");
+    assertEquals(new Path(".","boo/bud").toString(), "boo/bud");
 
     assertEquals(new Path("/foo/bar/baz","../../boo/bud").toString(), "/foo/boo/bud");
     assertEquals(new Path("foo/bar/baz","../../boo/bud").toString(), "foo/boo/bud");



Mime
View raw message