diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index b1bca98406..d06cd1cdef 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -541,10 +541,6 @@ XAttr createEncryptionZone(INodesInPath srcIIP, CipherSuite suite, if (srcIIP.getLastINode() == null) { throw new FileNotFoundException("cannot find " + srcIIP.getPath()); } - if (dir.isNonEmptyDirectory(srcIIP)) { - throw new IOException( - "Attempt to create an encryption zone for a non-empty directory."); - } INode srcINode = srcIIP.getLastINode(); if (!srcINode.isDirectory()) { @@ -557,6 +553,10 @@ XAttr createEncryptionZone(INodesInPath srcIIP, CipherSuite suite, "Directory " + srcIIP.getPath() + " is already an encryption zone."); } + if (dir.isNonEmptyDirectory(srcIIP)) { + throw new IOException( + "Attempt to create an encryption zone for a non-empty directory."); + } final HdfsProtos.ZoneEncryptionInfoProto proto = PBHelperClient.convert(suite, version, keyName); final XAttr ezXAttr = XAttrHelper diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml index c109442dcc..f603cc90ac 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml @@ -113,6 +113,25 @@ + + Test failure of creating EZ on an existing EZ + + -fs NAMENODE -mkdir /foo + -fs NAMENODE -ls /- + -createZone -path /foo -keyName myKey + -createZone -path /foo -keyName myKey + + + -fs NAMENODE -rmdir /foo + + + + SubstringComparator + Directory /foo is already an encryption zone + + + + Test success of creating an EZ as a subdir of an existing EZ.