Browse Source

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

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.16@652198 13f79535-47bb-0310-9956-ffa450edef68
Mukund Madhugiri 17 năm trước cách đây
mục cha
commit
cf61abf566

+ 7 - 0
CHANGES.txt

@@ -1,5 +1,12 @@
 Hadoop Change Log
 
+Release 0.16.4 - 2008-05-05
+
+  BUG FIXES
+
+    HADOOP-3138. DFS mkdirs() should not throw an exception if the directory
+    already exists. (rangadi via mukund)
+
 Release 0.16.3 - 2008-04-16
 
   BUG FIXES

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

@@ -1567,6 +1567,14 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
   private synchronized boolean mkdirsInternal(String src,
       PermissionStatus permissions) throws IOException {
     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())
       throw new SafeModeException("Cannot create directory " + src, safeMode);
     if (!isValidName(src)) {

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

@@ -161,6 +161,10 @@ public class TestPermission extends TestCase {
           userGroupInfo.toString());
       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
       assertTrue(!canMkdirs(fs, CHILD_DIR2));