hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r437821 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/FSDirectory.java src/test/org/apache/hadoop/dfs/TestDFSMkdirs.java
Date Mon, 28 Aug 2006 20:41:13 GMT
Author: cutting
Date: Mon Aug 28 13:41:12 2006
New Revision: 437821

URL: http://svn.apache.org/viewvc?rev=437821&view=rev
Log:
HADOOP-281.  Prohibit DFS files that are also directories.  Contributed by Wendy.

Added:
    lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSMkdirs.java
Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=437821&r1=437820&r2=437821&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Mon Aug 28 13:41:12 2006
@@ -80,6 +80,9 @@
     SequenceFile.Writer's constructor is now deprecated and replaced
     with a factory method.  (Arun C Murthy via cutting)
 
+20. HADOOP-281.  Prohibit DFS files that are also directories.
+    (Wendy Chien via cutting)
+
 
 Release 0.5.0 - 2006-08-04
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java?rev=437821&r1=437820&r2=437821&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java Mon Aug 28 13:41:12
2006
@@ -184,6 +184,10 @@
               throw new FileNotFoundException(
                       "Parent path does not exist: "+path);
           }
+          if (!parentNode.isDir()) {
+        	  throw new FileNotFoundException(
+        			  "Parent path is not a directory: "+path);
+          }
            // check whether the parent already has a node with that name
           String name = newNode.name = target.getName();
           if( parentNode.getChild( name ) != null )

Added: lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSMkdirs.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSMkdirs.java?rev=437821&view=auto
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSMkdirs.java (added)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSMkdirs.java Mon Aug 28 13:41:12
2006
@@ -0,0 +1,53 @@
+package org.apache.hadoop.dfs;
+
+import junit.framework.TestCase;
+import java.io.*;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+
+/**
+ * This class tests that the DFS command mkdirs cannot create subdirectories
+ * from a file when passed an illegal path.  HADOOP-281.
+ * @author Wendy Chien
+ */
+public class TestDFSMkdirs extends TestCase {
+
+  private void writeFile(FileSystem fileSys, Path name) throws IOException {
+    DataOutputStream stm = fileSys.create(name);
+    stm.writeBytes("wchien");
+    stm.close();
+  }
+  
+  /**
+   * Tests mkdirs can create a directory that does not exist and will
+   * not create a subdirectory off a file.
+   */
+  public void testDFSMkdirs() throws IOException {
+    Configuration conf = new Configuration();
+    MiniDFSCluster cluster = new MiniDFSCluster(65312, conf, false);
+    FileSystem fileSys = cluster.getFileSystem();
+    try {
+    	// First create a new directory with mkdirs
+    	Path myPath = new Path("/test/mkdirs");
+    	assertTrue(fileSys.mkdirs(myPath));
+    	assertTrue(fileSys.exists(myPath));
+    	
+    	// Second, create a file in that directory.
+    	Path myFile = new Path("/test/mkdirs/myFile");
+    	writeFile(fileSys, myFile);
+   
+    	// Third, use mkdir to create a subdirectory off of that file,
+    	// and check that it fails.
+    	Path myIllegalPath = new Path("/test/mkdirs/myFile/subdir");
+    	assertFalse(fileSys.mkdirs(myIllegalPath));
+    	assertFalse(fileSys.exists(myIllegalPath));
+    	fileSys.delete(myFile);
+    	
+    } finally {
+      fileSys.close();
+      cluster.shutdown();
+    }
+  }
+}



Mime
View raw message