浏览代码

HADOOP-12856. FileUtil.checkDest() and RawLocalFileSystem.mkdirs() to throw stricter IOEs; RawLocalFS contract tests to verify. Contributed by Steve Loughran

Mingliang Liu 8 年之前
父节点
当前提交
d11d280b8b

+ 3 - 2
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java

@@ -492,11 +492,12 @@ public class FileUtil {
     if (null != sdst) {
     if (null != sdst) {
       if (sdst.isDirectory()) {
       if (sdst.isDirectory()) {
         if (null == srcName) {
         if (null == srcName) {
-          throw new IOException("Target " + dst + " is a directory");
+          throw new PathIsDirectoryException(dst.toString());
         }
         }
         return checkDest(null, dstFS, new Path(dst, srcName), overwrite);
         return checkDest(null, dstFS, new Path(dst, srcName), overwrite);
       } else if (!overwrite) {
       } else if (!overwrite) {
-        throw new IOException("Target " + dst + " already exists");
+        throw new PathExistsException(dst.toString(),
+            "Target " + dst + " already exists");
       }
       }
     }
     }
     return dst;
     return dst;

+ 1 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java

@@ -552,7 +552,7 @@ public class RawLocalFileSystem extends FileSystem {
       }
       }
     }
     }
     if (p2f.exists() && !p2f.isDirectory()) {
     if (p2f.exists() && !p2f.isDirectory()) {
-      throw new FileNotFoundException("Destination exists" +
+      throw new FileAlreadyExistsException("Destination exists" +
               " and is not a directory: " + p2f.getCanonicalPath());
               " and is not a directory: " + p2f.getCanonicalPath());
     }
     }
     return (parent == null || parent2f.exists() || mkdirs(parent)) &&
     return (parent == null || parent2f.exists() || mkdirs(parent)) &&

+ 1 - 1
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/rawlocal/RawlocalFSContract.java

@@ -34,7 +34,7 @@ public class RawlocalFSContract extends LocalFSContract {
     super(conf);
     super(conf);
   }
   }
 
 
-  public static final String RAW_CONTRACT_XML = "contract/localfs.xml";
+  public static final String RAW_CONTRACT_XML = "contract/rawlocal.xml";
 
 
   @Override
   @Override
   protected String getContractXml() {
   protected String getContractXml() {

+ 23 - 9
hadoop-common-project/hadoop-common/src/test/resources/contract/rawlocal.xml

@@ -17,10 +17,24 @@
   -->
   -->
 
 
 <configuration>
 <configuration>
+
+  <!--
+  case sensitivity and permission options are determined at run time from OS type
+  -->
+
+  <property>
+    <name>fs.contract.is-case-sensitive</name>
+    <value>true</value>
+  </property>
+
+
+  <property>
+    <name>fs.contract.supports-unix-permissions</name>
+    <value>true</value>
+  </property>
+
   <!--
   <!--
-  Here are most of the local FS contract options.
-  some of them may be overridden at run time based on the OS,
-  others potentially generated.
+  The remaining options are static
   -->
   -->
 
 
   <property>
   <property>
@@ -33,11 +47,6 @@
     <value>1000</value>
     <value>1000</value>
   </property>
   </property>
 
 
-  <property>
-    <name>fs.contract.is-case-sensitive</name>
-    <value>true</value>
-  </property>
-
   <property>
   <property>
     <name>fs.contract.supports-append</name>
     <name>fs.contract.supports-append</name>
     <value>true</value>
     <value>true</value>
@@ -73,6 +82,11 @@
     <value>true</value>
     <value>true</value>
   </property>
   </property>
 
 
+  <property>
+    <name>fs.contract.rename-remove-dest-if-empty-dir</name>
+    <value>true</value>
+  </property>
+
   <property>
   <property>
     <name>fs.contract.supports-seek</name>
     <name>fs.contract.supports-seek</name>
     <value>true</value>
     <value>true</value>
@@ -108,4 +122,4 @@
     <value>true</value>
     <value>true</value>
   </property>
   </property>
 
 
-</configuration>
+</configuration>