HDFS-13054. Handling PathIsNotEmptyDirectoryException in DFSClient delete call. Contributed by Nanda kumar.

This commit is contained in:
Arpit Agarwal 2018-01-26 11:42:27 -08:00
parent a37e7f0ad8
commit e990904dd5
3 changed files with 23 additions and 1 deletions

View File

@ -82,6 +82,7 @@ import org.apache.hadoop.fs.Options;
import org.apache.hadoop.fs.Options.ChecksumOpt;
import org.apache.hadoop.fs.ParentNotDirectoryException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
import org.apache.hadoop.fs.QuotaUsage;
import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.fs.StorageType;
@ -1620,7 +1621,8 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory,
FileNotFoundException.class,
SafeModeException.class,
UnresolvedPathException.class,
SnapshotAccessControlException.class);
SnapshotAccessControlException.class,
PathIsNotEmptyDirectoryException.class);
}
}

View File

@ -26,6 +26,7 @@ import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.crypto.CryptoProtocolVersion;
import org.apache.hadoop.fs.BatchedRemoteIterator.BatchedEntries;
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
import org.apache.hadoop.hdfs.AddBlockFlag;
import org.apache.hadoop.fs.CacheFlag;
import org.apache.hadoop.fs.ContentSummary;
@ -625,6 +626,8 @@ public interface ClientProtocol {
* @throws org.apache.hadoop.fs.UnresolvedLinkException If <code>src</code>
* contains a symlink
* @throws SnapshotAccessControlException if path is in RO snapshot
* @throws PathIsNotEmptyDirectoryException if path is a non-empty directory
* and <code>recursive</code> is set to false
* @throws IOException If an I/O error occurred
*/
@AtMostOnce

View File

@ -67,6 +67,7 @@ import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.MD5MD5CRC32FileChecksum;
import org.apache.hadoop.fs.Options.ChecksumOpt;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.fs.StorageStatistics.LongStatistic;
import org.apache.hadoop.fs.StorageType;
@ -571,6 +572,22 @@ public class TestDistributedFileSystem {
in.close();
fs.close();
}
{
// Test PathIsNotEmptyDirectoryException while deleting non-empty dir
FileSystem fs = cluster.getFileSystem();
fs.mkdirs(new Path("/test/nonEmptyDir"));
fs.create(new Path("/tmp/nonEmptyDir/emptyFile")).close();
try {
fs.delete(new Path("/tmp/nonEmptyDir"), false);
Assert.fail("Expecting PathIsNotEmptyDirectoryException");
} catch (PathIsNotEmptyDirectoryException ex) {
// This is the proper exception to catch; move on.
}
Assert.assertTrue(fs.exists(new Path("/test/nonEmptyDir")));
fs.delete(new Path("/tmp/nonEmptyDir"), true);
}
}
finally {
if (cluster != null) {cluster.shutdown();}