Procházet zdrojové kódy

HADOOP-3138. DFS mkdirs() should not throw an exception if the directory already exists. (rangadi)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@644818 13f79535-47bb-0310-9956-ffa450edef68
Raghu Angadi před 17 roky
rodič
revize
7994499115

+ 3 - 0
CHANGES.txt

@@ -485,6 +485,9 @@ Trunk (unreleased changes)
     HADOOP-3165. -put/-copyFromLocal did not treat input file "-" as stdin.
     HADOOP-3165. -put/-copyFromLocal did not treat input file "-" as stdin.
     (Lohit Vijayarenu via rangadi)
     (Lohit Vijayarenu via rangadi)
 
 
+    HADOOP-3138. DFS mkdirs() should not throw an exception if the directory
+    already exists. (rangadi)
+
 Release 0.16.2 - 2008-04-02
 Release 0.16.2 - 2008-04-02
 
 
   BUG FIXES
   BUG FIXES

+ 8 - 0
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -1605,6 +1605,14 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
   private synchronized boolean mkdirsInternal(String src,
   private synchronized boolean mkdirsInternal(String src,
       PermissionStatus permissions) throws IOException {
       PermissionStatus permissions) throws IOException {
     NameNode.stateChangeLog.debug("DIR* NameSystem.mkdirs: " + src);
     NameNode.stateChangeLog.debug("DIR* NameSystem.mkdirs: " + src);
+    if (isPermissionEnabled) {
+      checkTraverse(src);
+    }
+    if (dir.isDir(src)) {
+      // all the users of mkdirs() are used to expect 'true' even if
+      // a new directory is not created.
+      return true;
+    }
     if (isInSafeMode())
     if (isInSafeMode())
       throw new SafeModeException("Cannot create directory " + src, safeMode);
       throw new SafeModeException("Cannot create directory " + src, safeMode);
     if (!isValidName(src)) {
     if (!isValidName(src)) {

+ 4 - 0
src/test/org/apache/hadoop/security/TestPermission.java

@@ -161,6 +161,10 @@ public class TestPermission extends TestCase {
           userGroupInfo.toString());
           userGroupInfo.toString());
       fs = FileSystem.get(conf);
       fs = FileSystem.get(conf);
 
 
+      // make sure mkdir of a existing directory that is not owned by 
+      // this user does not throw an exception.
+      fs.mkdirs(CHILD_DIR1);
+      
       // illegal mkdir
       // illegal mkdir
       assertTrue(!canMkdirs(fs, CHILD_DIR2));
       assertTrue(!canMkdirs(fs, CHILD_DIR2));