This is an automated email from the ASF dual-hosted git repository.

abstractdog pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/tez.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new 8e3a23b85 TEZ-4412 ensure mkDirForAM create directory with special 
permissions (#209) (Zhang Dongsheng reviewed by Laszlo Bodor)
8e3a23b85 is described below

commit 8e3a23b852b5afaffabfb1cb4af287f5456c124d
Author: skysiders <[email protected]>
AuthorDate: Tue May 10 13:30:59 2022 +0800

    TEZ-4412 ensure mkDirForAM create directory with special permissions (#209) 
(Zhang Dongsheng reviewed by Laszlo Bodor)
---
 .../main/java/org/apache/tez/common/TezCommonUtils.java    |  9 ++++++++-
 .../java/org/apache/tez/common/TestTezCommonUtils.java     | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/tez-api/src/main/java/org/apache/tez/common/TezCommonUtils.java 
b/tez-api/src/main/java/org/apache/tez/common/TezCommonUtils.java
index 2896297c6..80446ce07 100644
--- a/tez-api/src/main/java/org/apache/tez/common/TezCommonUtils.java
+++ b/tez-api/src/main/java/org/apache/tez/common/TezCommonUtils.java
@@ -291,7 +291,14 @@ public class TezCommonUtils {
    * @throws IOException
    */
   public static void mkDirForAM(FileSystem fs, Path dir) throws IOException {
-    fs.mkdirs(dir, new FsPermission(TEZ_AM_DIR_PERMISSION));
+    FsPermission perm = new FsPermission(TEZ_AM_DIR_PERMISSION);
+    fs.mkdirs(dir, perm);
+    if (!fs.getFileStatus(dir).getPermission().equals(perm)) {
+      LOG.warn("Directory " + dir.toString() + " created with unexpected 
permissions : "
+            + fs.getFileStatus(dir).getPermission() + ". Fixing permissions to 
correct value : "
+            + perm.toString());
+      fs.setPermission(dir, perm);
+    }
   }
 
   /**
diff --git 
a/tez-api/src/test/java/org/apache/tez/common/TestTezCommonUtils.java 
b/tez-api/src/test/java/org/apache/tez/common/TestTezCommonUtils.java
index d7bd39738..d5dc6fd6b 100644
--- a/tez-api/src/test/java/org/apache/tez/common/TestTezCommonUtils.java
+++ b/tez-api/src/test/java/org/apache/tez/common/TestTezCommonUtils.java
@@ -26,6 +26,7 @@ import com.google.common.collect.Maps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
@@ -413,4 +414,17 @@ public class TestTezCommonUtils {
   }
 
 
+  @Test
+  public void testMkDirForAM() throws IOException {
+    Configuration remoteConf = new Configuration();
+    remoteConf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, TEST_ROOT_DIR);
+    remoteConf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "777");
+    MiniDFSCluster miniDFS = new 
MiniDFSCluster.Builder(remoteConf).numDataNodes(3).format(true).racks(null)
+        .build();
+    FileSystem remoteFileSystem = miniDFS.getFileSystem();
+    Path path = new Path(TEST_ROOT_DIR + "/testMkDirForAM");
+    TezCommonUtils.mkDirForAM(remoteFileSystem, path);
+    Assert.assertEquals(TezCommonUtils.TEZ_AM_DIR_PERMISSION, 
remoteFileSystem.getFileStatus(path).getPermission());
+    miniDFS.shutdown();
+  }
 }

Reply via email to