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 2851F200BB4 for ; Tue, 18 Oct 2016 08:00:59 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 26F53160AF2; Tue, 18 Oct 2016 06:00:59 +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 46412160AEC for ; Tue, 18 Oct 2016 08:00:58 +0200 (CEST) Received: (qmail 97043 invoked by uid 500); 18 Oct 2016 06:00:57 -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 97033 invoked by uid 99); 18 Oct 2016 06:00:57 -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, 18 Oct 2016 06:00:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0677FE0579; Tue, 18 Oct 2016 06:00:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aajisaka@apache.org To: common-commits@hadoop.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HADOOP-13522. Add %A and %a formats for fs -stat command to print permissions. Contributed by Alex Garbarini. Date: Tue, 18 Oct 2016 06:00:57 +0000 (UTC) archived-at: Tue, 18 Oct 2016 06:00:59 -0000 Repository: hadoop Updated Branches: refs/heads/trunk 0bc6d37f3 -> bedfec0c1 HADOOP-13522. Add %A and %a formats for fs -stat command to print permissions. Contributed by Alex Garbarini. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/bedfec0c Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/bedfec0c Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/bedfec0c Branch: refs/heads/trunk Commit: bedfec0c10144087168bc79501ffd5ab4fa52606 Parents: 0bc6d37 Author: Akira Ajisaka Authored: Tue Oct 18 14:37:32 2016 +0900 Committer: Akira Ajisaka Committed: Tue Oct 18 15:00:44 2016 +0900 ---------------------------------------------------------------------- .../hadoop/fs/permission/FsPermission.java | 12 ++++++++++++ .../java/org/apache/hadoop/fs/shell/Stat.java | 11 ++++++++++- .../src/site/markdown/FileSystemShell.md | 4 ++-- .../src/test/resources/testConf.xml | 6 +++++- .../org/apache/hadoop/hdfs/TestDFSShell.java | 20 +++++++++++++++++--- 5 files changed, 46 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/bedfec0c/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/FsPermission.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/FsPermission.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/FsPermission.java index 48a5b1c..fabfc12 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/FsPermission.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/FsPermission.java @@ -183,6 +183,18 @@ public class FsPermission implements Writable { return toShort(); } + /** + * Returns the FsPermission in an octal format. + * + * @return short Unlike {@link #toShort()} which provides a binary + * representation, this method returns the standard octal style permission. + */ + public short toOctal() { + int n = this.toShort(); + int octal = (n>>>9&1)*1000 + (n>>>6&7)*100 + (n>>>3&7)*10 + (n&7); + return (short)octal; + } + @Override public boolean equals(Object obj) { if (obj instanceof FsPermission) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/bedfec0c/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java index 458d3ee..42f7843 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Stat.java @@ -31,6 +31,8 @@ import org.apache.hadoop.fs.FileStatus; /** * Print statistics about path in specified format. * Format sequences:
+ * %a: Permissions in octal
+ * %A: Permissions in symbolic style
* %b: Size of file in blocks
* %F: Type
* %g: Group name of owner
@@ -56,7 +58,8 @@ class Stat extends FsCommand { public static final String USAGE = "[format] ..."; public static final String DESCRIPTION = "Print statistics about the file/directory at " + NEWLINE + - "in the specified format. Format accepts filesize in" + NEWLINE + + "in the specified format. Format accepts permissions in" + NEWLINE + + "octal (%a) and symbolic (%A), filesize in" + NEWLINE + "blocks (%b), type (%F), group name of owner (%g)," + NEWLINE + "name (%n), block size (%o), replication (%r), user name" + NEWLINE + "of owner (%u), modification date (%y, %Y)." + NEWLINE + @@ -95,6 +98,12 @@ class Stat extends FsCommand { // this silently drops a trailing %? if (i + 1 == fmt.length) break; switch (fmt[++i]) { + case 'a': + buf.append(stat.getPermission().toOctal()); + break; + case 'A': + buf.append(stat.getPermission()); + break; case 'b': buf.append(stat.getLen()); break; http://git-wip-us.apache.org/repos/asf/hadoop/blob/bedfec0c/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md b/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md index ee7bc28..060c775 100644 --- a/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md +++ b/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md @@ -639,11 +639,11 @@ stat Usage: `hadoop fs -stat [format] ...` -Print statistics about the file/directory at \ in the specified format. Format accepts filesize in blocks (%b), type (%F), group name of owner (%g), name (%n), block size (%o), replication (%r), user name of owner(%u), and modification date (%y, %Y). %y shows UTC date as "yyyy-MM-dd HH:mm:ss" and %Y shows milliseconds since January 1, 1970 UTC. If the format is not specified, %y is used by default. +Print statistics about the file/directory at \ in the specified format. Format accepts permissions in octal (%a) and symbolic (%A), filesize in blocks (%b), type (%F), group name of owner (%g), name (%n), block size (%o), replication (%r), user name of owner(%u), and modification date (%y, %Y). %y shows UTC date as "yyyy-MM-dd HH:mm:ss" and %Y shows milliseconds since January 1, 1970 UTC. If the format is not specified, %y is used by default. Example: -* `hadoop fs -stat "%F %u:%g %b %y %n" /file` +* `hadoop fs -stat "%F %a %u:%g %b %y %n" /file` Exit Code: Returns 0 on success and -1 on error. http://git-wip-us.apache.org/repos/asf/hadoop/blob/bedfec0c/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml index a31c828..d285f33 100644 --- a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml +++ b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml @@ -859,7 +859,11 @@ RegexpComparator - ^( |\t)*in the specified format. Format accepts filesize in( )* + ^( |\t)*in the specified format. Format accepts permissions in( )* + + + RegexpComparator + ^( |\t)*octal \(%a\) and symbolic \(%A\), filesize in( )* RegexpComparator http://git-wip-us.apache.org/repos/asf/hadoop/blob/bedfec0c/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java index 5e5b8b6..cf193c9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java @@ -2021,17 +2021,31 @@ public class TestDFSShell { out.toString(), String.format("%s%n%s%n", mtime1, mtime2)); doFsStat(dfs.getConf(), "%F %u:%g %b %y %n"); - out.reset(); - doFsStat(dfs.getConf(), "%F %u:%g %b %y %n", testDir1); + + doFsStat(dfs.getConf(), "%F %a %A %u:%g %b %y %n", testDir1); assertTrue(out.toString(), out.toString().contains(mtime1)); assertTrue(out.toString(), out.toString().contains("directory")); assertTrue(out.toString(), out.toString().contains(status1.getGroup())); + assertTrue(out.toString(), + out.toString().contains(status1.getPermission().toString())); + + int n = status1.getPermission().toShort(); + int octal = (n>>>9&1)*1000 + (n>>>6&7)*100 + (n>>>3&7)*10 + (n&7); + assertTrue(out.toString(), + out.toString().contains(String.valueOf(octal))); out.reset(); - doFsStat(dfs.getConf(), "%F %u:%g %b %y %n", testDir1, testFile2); + doFsStat(dfs.getConf(), "%F %a %A %u:%g %b %y %n", testDir1, testFile2); + + n = status2.getPermission().toShort(); + octal = (n>>>9&1)*1000 + (n>>>6&7)*100 + (n>>>3&7)*10 + (n&7); assertTrue(out.toString(), out.toString().contains(mtime1)); assertTrue(out.toString(), out.toString().contains("regular file")); + assertTrue(out.toString(), + out.toString().contains(status2.getPermission().toString())); + assertTrue(out.toString(), + out.toString().contains(String.valueOf(octal))); assertTrue(out.toString(), out.toString().contains(mtime2)); } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org