[
https://issues.apache.org/jira/browse/HADOOP-10579?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18086854#comment-18086854
]
ASF GitHub Bot commented on HADOOP-10579:
-----------------------------------------
aajisaka commented on code in PR #8259:
URL: https://github.com/apache/hadoop/pull/8259#discussion_r3371027367
##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/find/Perm.java:
##########
@@ -0,0 +1,217 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.fs.shell.find;
+
+import java.io.IOException;
+import java.util.Deque;
+
+import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.hadoop.fs.shell.PathData;
+
+/**
+ * Implements the -perm expression for the {@link
org.apache.hadoop.fs.shell.find.Find} command.
+ */
+final class Perm extends BaseExpression {
+ /**
+ * Registers this expression with the specified factory.
+ */
+ public static void registerExpression(ExpressionFactory factory) throws
IOException {
+ factory.addClass(Perm.class, "-perm");
+ }
+
+ private static final String[] USAGE = {"-perm [-]mode", "-perm [-]onum"};
+ private static final String[] HELP = {"Evaluates as true if the file
permissions match that",
+ "specified. If the hyphen is specified then the expression",
+ "shall evaluate as true if at least the bits specified",
+ "match, otherwise an exact match is required.",
+ "The mode may be specified using either symbolic notation,",
+ "eg 'u=rwx,g+x+w' or as an octal number."};
+
+ private int permission = 0;
+ private boolean mask = false;
+
+ Perm() {
+ super();
+ setUsage(USAGE);
+ setHelp(HELP);
+ }
+
+ @Override
+ public void prepare() throws IOException {
+ parseArgument(getArgument(1));
+ }
+
+ /**
+ * Parse an argument string to build the permission mask.
+ *
+ * @param argument String to be parsed
+ * @throws IllegalArgumentException if the argument is invalid
+ */
+ private void parseArgument(String argument) throws IllegalArgumentException {
+ String arg = argument;
+ if (arg == null) {
+ throw new IllegalArgumentException("Invalid null argument");
+ }
+ if (arg.isEmpty()) {
+ throw new IllegalArgumentException("Invalid empty argument");
+ }
+ if (arg.startsWith("-")) {
+ mask = true;
+ arg = arg.substring(1);
+ }
+ if (Character.isDigit(arg.charAt(0))) {
+ // the argument is a numeric mode
+ permission = new FsPermission(arg).toShort();
+ } else {
+ // the argument is a symbolic mode
+ int shift;
+ Operator operator = null;
+ int value = 0;
Review Comment:
Would you initialize the operator and value in the for-loop below? Otherwise
`u=rwx,g` would be equivalent to `u=rwx,g=rwx`.
##########
hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml:
##########
@@ -17617,6 +17617,475 @@ $</expected-output>
<expected-output>^/findtest/item1/item1a
/findtest/item1/item1a/item1aa
/findtest/item4/item4a
+$</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+ <test> <!
> Find command - add match expressions to find command
> ----------------------------------------------------
>
> Key: HADOOP-10579
> URL: https://issues.apache.org/jira/browse/HADOOP-10579
> Project: Hadoop Common
> Issue Type: Sub-task
> Reporter: Jonathan Allen
> Assignee: Hiroki Egawa
> Priority: Minor
> Labels: pull-request-available
> Attachments: HADOOP-10579.patch
>
>
> Add match expressions to the find command created under HADOOP-8989, e.g.:
> - atime
> - empty
> - group
> - mtime
> - newer
> - nogroup
> - nouser
> - perm
> - regex
> - size
> - user
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]