hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r812127 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FileAlreadyExistsException.java src/java/org/apache/hadoop/fs/RawLocalFileSystem.java src/test/core/org/apache/hadoop/fs/TestLocalFileSystem.java
Date Mon, 07 Sep 2009 13:25:49 GMT
Author: tomwhite
Date: Mon Sep  7 13:25:48 2009
New Revision: 812127

URL: http://svn.apache.org/viewvc?rev=812127&view=rev
Log:
HADOOP-6229. Attempt to make a directory under an existing file on LocalFileSystem should
throw an Exception. Contributed by Boris Shkolnik.

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

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=812127&r1=812126&r2=812127&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Mon Sep  7 13:25:48 2009
@@ -972,6 +972,9 @@
     HADOOP-6199. Move io.map.skip.index property to core-default from mapred.
     (Amareshwari Sriramadasu via cdouglas)
 
+    HADOOP-6229. Attempt to make a directory under an existing file on
+    LocalFileSystem should throw an Exception. (Boris Shkolnik via tomwhite)
+
 Release 0.20.1 - Unreleased
 
   INCOMPATIBLE CHANGES

Added: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileAlreadyExistsException.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileAlreadyExistsException.java?rev=812127&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileAlreadyExistsException.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileAlreadyExistsException.java Mon
Sep  7 13:25:48 2009
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs;
+
+
+import java.io.IOException;
+
+/**
+ * Used when target file already exists for any operation and 
+ * is not configured to be overwritten.  
+ */
+public class FileAlreadyExistsException
+    extends IOException {
+
+  public FileAlreadyExistsException() {
+    super();
+  }
+
+  public FileAlreadyExistsException(String msg) {
+    super(msg);
+  }
+}

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=812127&r1=812126&r2=812127&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java Mon Sep  7 13:25:48
2009
@@ -308,8 +308,18 @@
    * treat existence as an error.
    */
   public boolean mkdirs(Path f) throws IOException {
+    if(f == null) {
+      throw new IllegalArgumentException("mkdirs path arg is null");
+    }
     Path parent = f.getParent();
     File p2f = pathToFile(f);
+    if(parent != null) {
+      File parent2f = pathToFile(parent);
+      if(parent2f != null && parent2f.exists() && !parent2f.isDirectory())
{
+        throw new FileAlreadyExistsException("Parent path is not a directory: " 
+            + parent);
+      }
+    }
     return (parent == null || mkdirs(parent)) &&
       (p2f.mkdir() || p2f.isDirectory());
   }
@@ -318,7 +328,8 @@
   @Override
   public boolean mkdirs(Path f, FsPermission permission) throws IOException {
     boolean b = mkdirs(f);
-    setPermission(f, permission);
+    if(b)
+      setPermission(f, permission);
     return b;
   }
   

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestLocalFileSystem.java?rev=812127&r1=812126&r2=812127&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestLocalFileSystem.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestLocalFileSystem.java Mon Sep
 7 13:25:48 2009
@@ -154,4 +154,26 @@
     assertEquals(path.makeQualified(fs), status.getPath());
     cleanupFile(fs, path);
   }
+  
+  public void testMkdirs() throws IOException {
+    Configuration conf = new Configuration();
+    LocalFileSystem fs = FileSystem.getLocal(conf);
+    Path test_dir = new Path(TEST_ROOT_DIR, "test_dir");
+    Path test_file = new Path(TEST_ROOT_DIR, "file1");
+    assertTrue(fs.mkdirs(test_dir));
+   
+    writeFile(fs, test_file);
+    // creating dir over a file
+    Path bad_dir = new Path(test_file, "another_dir");
+    
+    try {
+      fs.mkdirs(bad_dir);
+      fail("Failed to detect existing file in path");
+    } catch (FileAlreadyExistsException e) { }
+    
+    try {
+      fs.mkdirs(null);
+      fail("Failed to detect null in mkdir arg");
+    } catch (IllegalArgumentException e) { }
+  }
 }



Mime
View raw message