Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 557C3200B79 for ; Tue, 2 Aug 2016 17:21:03 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 53F98160A76; Tue, 2 Aug 2016 15:21:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6ECE6160AAC for ; Tue, 2 Aug 2016 17:21:02 +0200 (CEST) Received: (qmail 80475 invoked by uid 500); 2 Aug 2016 15:20:58 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 79955 invoked by uid 99); 2 Aug 2016 15:20:58 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Aug 2016 15:20:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5B820E5CE0; Tue, 2 Aug 2016 15:20:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jianhe@apache.org To: common-commits@hadoop.apache.org Date: Tue, 02 Aug 2016 15:21:09 -0000 Message-Id: <00e94637b7594629beb9ecec8b3d0135@git.apache.org> In-Reply-To: <0b8347fdc73c480b8d5c2ea4ac794f36@git.apache.org> References: <0b8347fdc73c480b8d5c2ea4ac794f36@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [12/40] hadoop git commit: HDFS-10650. DFSClient#mkdirs and DFSClient#primitiveMkdir should use default directory permission. Contributed by John Zhuge. archived-at: Tue, 02 Aug 2016 15:21:03 -0000 HDFS-10650. DFSClient#mkdirs and DFSClient#primitiveMkdir should use default directory permission. Contributed by John Zhuge. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/328c855a Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/328c855a Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/328c855a Branch: refs/heads/yarn-native-services Commit: 328c855a578b90362d33dc822075f9b828df6f1e Parents: 26de4f0 Author: Xiao Chen Authored: Thu Jul 28 13:15:02 2016 -0700 Committer: Xiao Chen Committed: Thu Jul 28 13:15:02 2016 -0700 ---------------------------------------------------------------------- .../main/java/org/apache/hadoop/hdfs/DFSClient.java | 14 ++++++++++---- .../org/apache/hadoop/security/TestPermission.java | 12 ++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/328c855a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java index aa48f7e..833b1ee 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java @@ -1163,6 +1163,13 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory, return permission.applyUMask(dfsClientConf.getUMask()); } + private FsPermission applyUMaskDir(FsPermission permission) { + if (permission == null) { + permission = FsPermission.getDirDefault(); + } + return permission.applyUMask(dfsClientConf.getUMask()); + } + /** * Same as {@link #create(String, FsPermission, EnumSet, boolean, short, long, * Progressable, int, ChecksumOpt)} with the addition of favoredNodes that is @@ -2264,7 +2271,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory, * * @param src The path of the directory being created * @param permission The permission of the directory being created. - * If permission == null, use {@link FsPermission#getDefault()}. + * If permission == null, use {@link FsPermission#getDirDefault()}. * @param createParent create missing parent directory if true * * @return True if the operation success. @@ -2273,7 +2280,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory, */ public boolean mkdirs(String src, FsPermission permission, boolean createParent) throws IOException { - final FsPermission masked = applyUMask(permission); + final FsPermission masked = applyUMaskDir(permission); return primitiveMkdir(src, masked, createParent); } @@ -2294,9 +2301,8 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory, boolean createParent) throws IOException { checkOpen(); if (absPermission == null) { - absPermission = applyUMask(null); + absPermission = applyUMaskDir(null); } - LOG.debug("{}: masked={}", src, absPermission); try (TraceScope ignored = tracer.newScope("mkdir")) { return namenode.mkdirs(src, absPermission, createParent); http://git-wip-us.apache.org/repos/asf/hadoop/blob/328c855a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java index 5a17bbc..7efa255 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java @@ -17,8 +17,10 @@ */ package org.apache.hadoop.security; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -49,6 +51,7 @@ public class TestPermission { final private static Path ROOT_PATH = new Path("/data"); final private static Path CHILD_DIR1 = new Path(ROOT_PATH, "child1"); final private static Path CHILD_DIR2 = new Path(ROOT_PATH, "child2"); + final private static Path CHILD_DIR3 = new Path(ROOT_PATH, "child3"); final private static Path CHILD_FILE1 = new Path(ROOT_PATH, "file1"); final private static Path CHILD_FILE2 = new Path(ROOT_PATH, "file2"); final private static Path CHILD_FILE3 = new Path(ROOT_PATH, "file3"); @@ -216,6 +219,9 @@ public class TestPermission { // following dir/file creations are legal nnfs.mkdirs(CHILD_DIR1); + status = nnfs.getFileStatus(CHILD_DIR1); + assertThat("Expect 755 = 777 (default dir) - 022 (default umask)", + status.getPermission().toString(), is("rwxr-xr-x")); out = nnfs.create(CHILD_FILE1); status = nnfs.getFileStatus(CHILD_FILE1); assertTrue(status.getPermission().toString().equals("rw-r--r--")); @@ -227,6 +233,12 @@ public class TestPermission { status = nnfs.getFileStatus(CHILD_FILE1); assertTrue(status.getPermission().toString().equals("rwx------")); + // mkdirs with null permission + nnfs.mkdirs(CHILD_DIR3, null); + status = nnfs.getFileStatus(CHILD_DIR3); + assertThat("Expect 755 = 777 (default dir) - 022 (default umask)", + status.getPermission().toString(), is("rwxr-xr-x")); + // following read is legal byte dataIn[] = new byte[FILE_LEN]; FSDataInputStream fin = nnfs.open(CHILD_FILE1); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org