Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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 org.apache.hadoop.fs.shell.PathData;

/**
* Implements the -atime expression for the {@link org.apache.hadoop.fs.shell.find.Find} command.
*/
final class Atime extends NumberExpression {
/**
* Registers this expression with the specified factory.
*/
public static void registerExpression(ExpressionFactory factory) throws IOException {
factory.addClass(Atime.class, "-atime");
factory.addClass(Amin.class, "-amin");
}

private static final String[] USAGE = {"-atime n", "-amin n"};
private static final String[] HELP = {"Evaluates as true if the file access time subtracted from",
"the start time is n days (or minutes if -amin is used)."};

/**
* Constructs an Atime expression with a parameter size of 1 day.
*/
Atime() {
this(DAY_IN_MILLISECONDS);
}

/**
* Constructs an Atime expression using the specified units for the parameter.
*
* @param units expression parameter size in milliseconds
*/
private Atime(long units) {
super(units);
setUsage(USAGE);
setHelp(HELP);
}

@Override
public Result apply(PathData item, int depth) throws IOException {
return applyNumber(getOptions().getStartTime() - getFileStatus(item, depth).getAccessTime());
}

/**
* Implement -amin expression (similar to -atime but in minutes rather than days).
*/
final static class Amin extends FilterExpression {
Amin() {
super(new Atime(MINUTE_IN_MILLISECONDS));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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 org.apache.hadoop.fs.shell.PathData;

/**
* Implements the -blocksize expression for the
* {@link org.apache.hadoop.fs.shell.find.Find} command.
*/
final class Blocksize extends NumberExpression {
/**
* Registers this expression with the specified factory.
*/
public static void registerExpression(ExpressionFactory factory) throws IOException {
factory.addClass(Blocksize.class, "-blocksize");
}

private static final String[] USAGE = {"-blocksize n"};
private static final String[] HELP = {"Evaluates to true if the block size of the file is n."};

Blocksize() {
super();
setUsage(USAGE);
setHelp(HELP);
}

@Override
public Result apply(PathData item, int depth) throws IOException {
return applyNumber(getFileStatus(item, depth).getBlockSize());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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 org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.shell.PathData;

/**
* Implements the -empty expression for the {@link org.apache.hadoop.fs.shell.find.Find} command.
*/
final class Empty extends BaseExpression {
/**
* Registers this expression with the specified factory.
*/
public static void registerExpression(ExpressionFactory factory) throws IOException {
factory.addClass(Empty.class, "-empty");
}

private static final String[] USAGE = {"-empty"};
private static final String[] HELP =
{"Evaluates as true if the file is empty or directory has no", "contents."};

Empty() {
super();
setUsage(USAGE);
setHelp(HELP);
}

@Override
public Result apply(PathData item, int depth) throws IOException {
FileStatus fileStatus = getFileStatus(item, depth);
if (fileStatus.isDirectory()) {
if (getFileSystem(item).listStatus(getPath(item)).length == 0) {
return Result.PASS;
}
return Result.FAIL;
}
if (fileStatus.getLen() == 0L) {
return Result.PASS;
}
return Result.FAIL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,21 @@ private static void addExpression(Class<?> clazz) {

// Navigation Expressions
// Matcher Expressions
addExpression(Atime.class);
addExpression(Blocksize.class);
addExpression(Empty.class);
addExpression(Group.class);
addExpression(Mtime.class);
addExpression(Name.class);
addExpression(Newer.class);
addExpression(Nogroup.class);
addExpression(Nouser.class);
addExpression(Perm.class);
addExpression(Regex.class);
addExpression(Replicas.class);
addExpression(Size.class);
addExpression(Type.class);
addExpression(User.class);

DESCRIPTION = buildDescription(ExpressionFactory.getExpressionFactory());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* 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.shell.PathData;

/**
* Implements the -group expression for the {@link org.apache.hadoop.fs.shell.find.Find} command.
*/
final class Group extends BaseExpression {
/**
* Registers this expression with the specified factory.
*/
public static void registerExpression(ExpressionFactory factory) throws IOException {
factory.addClass(Group.class, "-group");
}

private static final String[] USAGE = {"-group groupname"};
private static final String[] HELP =
{"Evaluates as true if the file belongs to the specified", "group."};
private String requiredGroup;

Group() {
super();
setUsage(USAGE);
setHelp(HELP);
}

@Override
public void addArguments(Deque<String> args) {
addArguments(args, 1);
}

@Override
public void prepare() throws IOException {
requiredGroup = getArgument(1);
}

@Override
public Result apply(PathData item, int depth) throws IOException {
String group = getFileStatus(item, depth).getGroup();
if (requiredGroup.equals(group)) {
return Result.PASS;
}
return Result.FAIL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* 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 org.apache.hadoop.fs.shell.PathData;

/**
* Implements the -mtime expression for the {@link org.apache.hadoop.fs.shell.find.Find} command.
*/
final class Mtime extends NumberExpression {
/**
* Registers this expression with the specified factory.
*/
public static void registerExpression(ExpressionFactory factory) throws IOException {
factory.addClass(Mtime.class, "-mtime");
factory.addClass(Mmin.class, "-mmin");
}

private static final String[] USAGE = {"-mtime n", "-mmin n"};
private static final String[] HELP =
{"Evaluates as true if the file modification time subtracted",
"from the start time is n days (or minutes if -mmin is used)"};

/**
* Constructs a Mtime expression with a parameter size of 1 day.
*/
Mtime() {
this(DAY_IN_MILLISECONDS);
}

/**
* Constructs a Mtime expression using the specified units for the parameter.
*
* @param units expression parameter size in milliseconds
*/
private Mtime(long units) {
super(units);
setUsage(USAGE);
setHelp(HELP);
}

@Override
public Result apply(PathData item, int depth) throws IOException {
return applyNumber(
getOptions().getStartTime() - getFileStatus(item, depth).getModificationTime());
}

/**
* Implement -mmin expression (similar to -mtime but in minutes rather than
* days).
*/
final static class Mmin extends FilterExpression {
Mmin() {
super(new Mtime(MINUTE_IN_MILLISECONDS));
}
}
}
Loading
Loading