svn merge -c 1406198 FIXES: HDFS-1331. dfs -test should work like /bin/test (Andy Isaacson via daryn)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1406203 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ff3fb08cd7
commit
f963c2eb96
|
@ -37,16 +37,21 @@ class Test extends FsCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String NAME = "test";
|
public static final String NAME = "test";
|
||||||
public static final String USAGE = "-[ezd] <path>";
|
public static final String USAGE = "-[defsz] <path>";
|
||||||
public static final String DESCRIPTION =
|
public static final String DESCRIPTION =
|
||||||
"If file exists, has zero length, is a directory\n" +
|
"Answer various questions about <path>, with result via exit status.\n" +
|
||||||
"then return 0, else return 1.";
|
" -d return 0 if <path> is a directory.\n" +
|
||||||
|
" -e return 0 if <path> exists.\n" +
|
||||||
|
" -f return 0 if <path> is a file.\n" +
|
||||||
|
" -s return 0 if file <path> is greater than zero bytes in size.\n" +
|
||||||
|
" -z return 0 if file <path> is zero bytes in size.\n" +
|
||||||
|
"else, return 1.";
|
||||||
|
|
||||||
private char flag;
|
private char flag;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processOptions(LinkedList<String> args) {
|
protected void processOptions(LinkedList<String> args) {
|
||||||
CommandFormat cf = new CommandFormat(1, 1, "e", "d", "z");
|
CommandFormat cf = new CommandFormat(1, 1, "e", "d", "f", "s", "z");
|
||||||
cf.parse(args);
|
cf.parse(args);
|
||||||
|
|
||||||
String[] opts = cf.getOpts().toArray(new String[0]);
|
String[] opts = cf.getOpts().toArray(new String[0]);
|
||||||
|
@ -71,6 +76,12 @@ class Test extends FsCommand {
|
||||||
case 'd':
|
case 'd':
|
||||||
test = item.stat.isDirectory();
|
test = item.stat.isDirectory();
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
test = item.stat.isFile();
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
test = (item.stat.getLen() > 0);
|
||||||
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
test = (item.stat.getLen() == 0);
|
test = (item.stat.getLen() == 0);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -591,11 +591,11 @@
|
||||||
<comparators>
|
<comparators>
|
||||||
<comparator>
|
<comparator>
|
||||||
<type>RegexpComparator</type>
|
<type>RegexpComparator</type>
|
||||||
<expected-output>^-test -\[ezd\] <path>:\s+If file exists, has zero length, is a directory( )*</expected-output>
|
<expected-output>^-test -\[defsz\] <path>:\sAnswer various questions about <path>, with result via exit status.</expected-output>
|
||||||
</comparator>
|
</comparator>
|
||||||
<comparator>
|
<comparator>
|
||||||
<type>RegexpComparator</type>
|
<type>RegexpComparator</type>
|
||||||
<expected-output>^( |\t)*then return 0, else return 1.( )*</expected-output>
|
<expected-output>^( |\t)*else, return 1.( )*</expected-output>
|
||||||
</comparator>
|
</comparator>
|
||||||
</comparators>
|
</comparators>
|
||||||
</test>
|
</test>
|
||||||
|
|
|
@ -199,6 +199,8 @@ Release 2.0.3-alpha - Unreleased
|
||||||
HDFS-4132. When libwebhdfs is not enabled, nativeMiniDfsClient frees
|
HDFS-4132. When libwebhdfs is not enabled, nativeMiniDfsClient frees
|
||||||
uninitialized memory (Colin Patrick McCabe via todd)
|
uninitialized memory (Colin Patrick McCabe via todd)
|
||||||
|
|
||||||
|
HDFS-1331. dfs -test should work like /bin/test (Andy Isaacson via daryn)
|
||||||
|
|
||||||
Release 2.0.2-alpha - 2012-09-07
|
Release 2.0.2-alpha - 2012-09-07
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -1244,6 +1244,105 @@ public class TestDFSShell {
|
||||||
assertEquals(0, val);
|
assertEquals(0, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify -test -f negative case (missing file)
|
||||||
|
{
|
||||||
|
String[] args = new String[3];
|
||||||
|
args[0] = "-test";
|
||||||
|
args[1] = "-f";
|
||||||
|
args[2] = "/test/mkdirs/noFileHere";
|
||||||
|
int val = -1;
|
||||||
|
try {
|
||||||
|
val = shell.run(args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Exception raised from DFSShell.run " +
|
||||||
|
e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
assertEquals(1, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify -test -f negative case (directory rather than file)
|
||||||
|
{
|
||||||
|
String[] args = new String[3];
|
||||||
|
args[0] = "-test";
|
||||||
|
args[1] = "-f";
|
||||||
|
args[2] = "/test/mkdirs";
|
||||||
|
int val = -1;
|
||||||
|
try {
|
||||||
|
val = shell.run(args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Exception raised from DFSShell.run " +
|
||||||
|
e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
assertEquals(1, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify -test -f positive case
|
||||||
|
{
|
||||||
|
writeFile(fileSys, myFile);
|
||||||
|
assertTrue(fileSys.exists(myFile));
|
||||||
|
|
||||||
|
String[] args = new String[3];
|
||||||
|
args[0] = "-test";
|
||||||
|
args[1] = "-f";
|
||||||
|
args[2] = myFile.toString();
|
||||||
|
int val = -1;
|
||||||
|
try {
|
||||||
|
val = shell.run(args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Exception raised from DFSShell.run " +
|
||||||
|
e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
assertEquals(0, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify -test -s negative case (missing file)
|
||||||
|
{
|
||||||
|
String[] args = new String[3];
|
||||||
|
args[0] = "-test";
|
||||||
|
args[1] = "-s";
|
||||||
|
args[2] = "/test/mkdirs/noFileHere";
|
||||||
|
int val = -1;
|
||||||
|
try {
|
||||||
|
val = shell.run(args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Exception raised from DFSShell.run " +
|
||||||
|
e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
assertEquals(1, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify -test -s negative case (zero length file)
|
||||||
|
{
|
||||||
|
String[] args = new String[3];
|
||||||
|
args[0] = "-test";
|
||||||
|
args[1] = "-s";
|
||||||
|
args[2] = "/test/mkdirs/isFileHere";
|
||||||
|
int val = -1;
|
||||||
|
try {
|
||||||
|
val = shell.run(args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Exception raised from DFSShell.run " +
|
||||||
|
e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
assertEquals(1, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify -test -s positive case (nonzero length file)
|
||||||
|
{
|
||||||
|
String[] args = new String[3];
|
||||||
|
args[0] = "-test";
|
||||||
|
args[1] = "-s";
|
||||||
|
args[2] = myFile.toString();
|
||||||
|
int val = -1;
|
||||||
|
try {
|
||||||
|
val = shell.run(args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Exception raised from DFSShell.run " +
|
||||||
|
e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
assertEquals(0, val);
|
||||||
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
fileSys.close();
|
fileSys.close();
|
||||||
|
|
Loading…
Reference in New Issue