hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1151594 - in /hadoop/common/trunk/common: CHANGES.txt src/docs/src/documentation/content/xdocs/file_system_shell.xml src/java/org/apache/hadoop/fs/shell/Ls.java src/test/core/org/apache/hadoop/cli/testConf.xml
Date Wed, 27 Jul 2011 19:09:58 GMT
Author: suresh
Date: Wed Jul 27 19:09:55 2011
New Revision: 1151594

URL: http://svn.apache.org/viewvc?rev=1151594&view=rev
Log:
HADOOP-7378. Add -d option to ls to not expand directories. Contributed by Daryn Sharp.

Modified:
    hadoop/common/trunk/common/CHANGES.txt
    hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml
    hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java
    hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml

Modified: hadoop/common/trunk/common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/CHANGES.txt?rev=1151594&r1=1151593&r2=1151594&view=diff
==============================================================================
--- hadoop/common/trunk/common/CHANGES.txt (original)
+++ hadoop/common/trunk/common/CHANGES.txt Wed Jul 27 19:09:55 2011
@@ -289,6 +289,9 @@ Trunk (unreleased changes)
     HADOOP-7485. Add -h option to ls to list file sizes in human readable
     format. (XieXianshan via suresh)
 
+    HADOOP-7378. Add -d option to ls to not expand directories.
+    (Daryn Sharp via suresh)
+
   OPTIMIZATIONS
   
     HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole

Modified: hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml?rev=1151594&r1=1151593&r2=1151594&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml
(original)
+++ hadoop/common/trunk/common/src/docs/src/documentation/content/xdocs/file_system_shell.xml
Wed Jul 27 19:09:55 2011
@@ -273,7 +273,7 @@
        <section>
            <title>ls</title>
            <p>
-               <code>Usage: hdfs dfs -ls [-R] [-h] &lt;args&gt;</code>
+               <code>Usage: hdfs dfs -ls [-d] [-h] [-R] &lt;args&gt;</code>
            </p>
            <p>For a file returns stat on the file with the following format:</p>
            <p>
@@ -284,10 +284,11 @@
                <code>permissions userid groupid modification_date modification_time
dirname</code>
            </p>
            <p>Options:</p>
-           <ul>
-             <li>The <code>-R</code> option will list subdirectories recursively.</li>
-             <li>The <code>-h</code> option will format file sizes in a
&quot;human-readable&quot; fashion (e.g 64.0m instead of 67108864)</li>
-           </ul>
+             <ul>
+               <li><code>-d</code>  Directories are listed as plain files</li>
+               <li><code>-h</code>  Format file sizes in a &quot;human-readable&quot;
fashion (e.g 64.0m instead of 67108864)</li>
+               <li><code>-R</code>  Recursively list subdirectories encountered</li>
+             </ul>
            <p>Example:</p>
            <p>
                <code>hdfs dfs -ls /user/hadoop/file1 </code>

Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java?rev=1151594&r1=1151593&r2=1151594&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java (original)
+++ hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Ls.java Wed Jul 27 19:09:55
2011
@@ -42,7 +42,7 @@ class Ls extends FsCommand {
   }
   
   public static final String NAME = "ls";
-  public static final String USAGE = "[-R] [-h] [<path> ...]";
+  public static final String USAGE = "[-d] [-h] [-R] [<path> ...]";
   public static final String DESCRIPTION =
     "List the contents that match the specified file pattern. If\n" + 
     "path is not specified, the contents of /user/<currentUser>\n" +
@@ -52,15 +52,17 @@ class Ls extends FsCommand {
     "\tfileName(full path) <r n> size \n" +
     "where n is the number of replicas specified for the file \n" + 
     "and size is the size of the file, in bytes.\n" +
-    "  -R  Recursively list the contents of directories.\n" +
+    "  -d  Directories are listed as plain files.\n" +
     "  -h  Formats the sizes of files in a human-readable fashion\n" +
-    "      rather than of bytes.\n\n";
+    "      rather than a number of bytes.\n" +
+    "  -R  Recursively list the contents of directories.";
 
   protected static final SimpleDateFormat dateFormat = 
     new SimpleDateFormat("yyyy-MM-dd HH:mm");
 
   protected int maxRepl = 3, maxLen = 10, maxOwner = 0, maxGroup = 0;
   protected String lineFormat;
+  protected boolean dirRecurse;
 
   protected boolean humanReadable = false;
   protected String formatSize(long size) {
@@ -72,22 +74,27 @@ class Ls extends FsCommand {
   @Override
   protected void processOptions(LinkedList<String> args)
   throws IOException {
-    CommandFormat cf = new CommandFormat(0, Integer.MAX_VALUE, "R", "h");
+    CommandFormat cf = new CommandFormat(0, Integer.MAX_VALUE, "d", "h", "R");
     cf.parse(args);
-    setRecursive(cf.getOpt("R"));
+    dirRecurse = !cf.getOpt("d");
+    setRecursive(cf.getOpt("R") && dirRecurse);
     humanReadable = cf.getOpt("h");
     if (args.isEmpty()) args.add(Path.CUR_DIR);
   }
 
   @Override
-  protected void processPaths(PathData parent, PathData ... items)
-  throws IOException {
+  protected void processPathArgument(PathData item) throws IOException {
     // implicitly recurse once for cmdline directories
-    if (parent == null && items[0].stat.isDirectory()) {
-      recursePath(items[0]);
-      return;
+    if (dirRecurse && item.stat.isDirectory()) {
+      recursePath(item);
+    } else {
+      super.processPathArgument(item);
     }
+  }
 
+  @Override
+  protected void processPaths(PathData parent, PathData ... items)
+  throws IOException {
     if (!isRecursive() && items.length != 0) {
       out.println("Found " + items.length + " items");
     }

Modified: hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml?rev=1151594&r1=1151593&r2=1151594&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml (original)
+++ hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml Wed Jul 27
19:09:55 2011
@@ -54,7 +54,7 @@
       <comparators>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^-ls \[-R\] \[-h\] \[&lt;path&gt; \.\.\.\]:( |\t)*List
the contents that match the specified file pattern. If( )*</expected-output>
+          <expected-output>^-ls \[-d\] \[-h\] \[-R\] \[&lt;path&gt; \.\.\.\]:(
|\t)*List the contents that match the specified file pattern. If( )*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
@@ -90,15 +90,19 @@
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^( |\t)*-R  Recursively list the contents of directories.(
)*</expected-output>
+          <expected-output>^( |\t)*-d\s+Directories are listed as plain files\.</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^( |\t)*-h  Formats the sizes of files in a human-readable
fashion( )*</expected-output>
+          <expected-output>^( |\t)*-h\s+Formats the sizes of files in a human-readable
fashion( )*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^( |\t)*rather than a number of bytes.( )*</expected-output>
+          <expected-output>^( |\t)*rather than a number of bytes\.( )*</expected-output>
+        </comparator>
+        <comparator>
+          <type>RegexpComparator</type>
+          <expected-output>^( |\t)*-R\s+Recursively list the contents of directories\.</expected-output>
         </comparator>
       </comparators>
     </test>



Mime
View raw message