diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index 194f1aff64..ba52441828 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -3256,7 +3256,7 @@ boolean delete(String src, boolean recursive, boolean logRetryCache) throw e; } getEditLog().logSync(); - logAuditEvent(true, operationName, src); + logAuditEvent(ret, operationName, src); if (toRemovedBlocks != null) { removeBlocks(toRemovedBlocks); // Incremental deletion of blocks } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java index 0814d4aab8..4d379b177a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java @@ -51,6 +51,7 @@ import org.junit.Test; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; import org.mockito.Mockito; @@ -1205,6 +1206,18 @@ public void testGetDatanodeStorageReport() throws Exception { } } + @Test + public void testDeleteRoot() throws Exception { + Path srcDir = new Path("/"); + fileSys = DFSTestUtil.getFileSystemAs(user1, conf); + boolean result = fileSys.delete(srcDir, true); + fileSys.close(); + assertFalse(result); + String aceDeletePattern = + ".*allowed=false.*ugi=theDoctor.*cmd=delete.*"; + verifyAuditLogs(aceDeletePattern); + } + private void verifyAuditRestoreFailedStorageACE( FSNamesystem fsNamesystem, String arg) throws IOException { String operationName = fsNamesystem.getFailedStorageCommand(arg);