From d11d280b8b527d572ca0b29ef57434e9ff533ffe Mon Sep 17 00:00:00 2001 From: Mingliang Liu Date: Tue, 25 Apr 2017 18:33:41 -0700 Subject: [PATCH] HADOOP-12856. FileUtil.checkDest() and RawLocalFileSystem.mkdirs() to throw stricter IOEs; RawLocalFS contract tests to verify. Contributed by Steve Loughran --- .../java/org/apache/hadoop/fs/FileUtil.java | 5 +-- .../apache/hadoop/fs/RawLocalFileSystem.java | 2 +- .../contract/rawlocal/RawlocalFSContract.java | 2 +- .../src/test/resources/contract/rawlocal.xml | 32 +++++++++++++------ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java index bb70cbd26e..0b27a7e326 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java @@ -492,11 +492,12 @@ private static Path checkDest(String srcName, FileSystem dstFS, Path dst, if (null != sdst) { if (sdst.isDirectory()) { 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); } else if (!overwrite) { - throw new IOException("Target " + dst + " already exists"); + throw new PathExistsException(dst.toString(), + "Target " + dst + " already exists"); } } return dst; diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java index 7bf429eed4..e4e0659b13 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java @@ -552,7 +552,7 @@ private boolean mkdirsWithOptionalPermission(Path f, FsPermission permission) } } if (p2f.exists() && !p2f.isDirectory()) { - throw new FileNotFoundException("Destination exists" + + throw new FileAlreadyExistsException("Destination exists" + " and is not a directory: " + p2f.getCanonicalPath()); } return (parent == null || parent2f.exists() || mkdirs(parent)) && diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/rawlocal/RawlocalFSContract.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/rawlocal/RawlocalFSContract.java index 0cd32f350d..3c49955082 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/rawlocal/RawlocalFSContract.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/rawlocal/RawlocalFSContract.java @@ -34,7 +34,7 @@ public RawlocalFSContract(Configuration conf) { super(conf); } - public static final String RAW_CONTRACT_XML = "contract/localfs.xml"; + public static final String RAW_CONTRACT_XML = "contract/rawlocal.xml"; @Override protected String getContractXml() { diff --git a/hadoop-common-project/hadoop-common/src/test/resources/contract/rawlocal.xml b/hadoop-common-project/hadoop-common/src/test/resources/contract/rawlocal.xml index b51f3d0edb..a0d1d21a94 100644 --- a/hadoop-common-project/hadoop-common/src/test/resources/contract/rawlocal.xml +++ b/hadoop-common-project/hadoop-common/src/test/resources/contract/rawlocal.xml @@ -17,10 +17,24 @@ --> + + + + fs.contract.is-case-sensitive + true + + + + + fs.contract.supports-unix-permissions + true + + + @@ -33,11 +47,6 @@ 1000 - - fs.contract.is-case-sensitive - true - - fs.contract.supports-append true @@ -73,6 +82,11 @@ true + + fs.contract.rename-remove-dest-if-empty-dir + true + + fs.contract.supports-seek true @@ -108,4 +122,4 @@ true - \ No newline at end of file +