Author: sebb
Date: Sat Mar 19 16:20:23 2011
New Revision: 1083209

URL: http://svn.apache.org/viewvc?rev=1083209&view=rev
Log:
Override preParse() as not needed
Fix up some parsing errors, add sizd (size of directory) handling

Modified:
    
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java

Modified: 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java?rev=1083209&r1=1083208&r2=1083209&view=diff
==============================================================================
--- 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
 (original)
+++ 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
 Sat Mar 19 16:20:23 2011
@@ -20,6 +20,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
 
@@ -84,6 +85,15 @@ public class MLSxEntryParser extends FTP
         super();
     }
 
+    /**
+     * Override preParse() phase as it is not needed.
+     */
+    // TODO can be removed if NET-381 is implemented
+    @Override
+    public List<String> preParse(List<String> orig) {
+        return orig;
+    }
+
     public FTPFile parseFTPEntry(String entry) {
         String parts[] = entry.split(" ",2); // Path may contain space
         if (parts.length != 2) {
@@ -96,11 +106,20 @@ public class MLSxEntryParser extends FTP
         boolean hasUnixMode = 
parts[0].toLowerCase(Locale.ENGLISH).contains("unix.mode=");
         for(String fact : facts) {
             String []factparts = fact.split("=");
+// Sample missing permission
+// drwx------   2 mirror   mirror       4096 Mar 13  2010 subversion
+// 
modify=20100313224553;perm=;type=dir;unique=811U282598;UNIX.group=500;UNIX.mode=0700;UNIX.owner=500;
 subversion
+            if (factparts.length != 2) {
+                continue; // nothing to do here
+            }
             String factname = factparts[0].toLowerCase(Locale.ENGLISH);
             String factvalue = factparts[1];
             if ("size".equals(factname)) {
                 file.setSize(Long.parseLong(factvalue));
             }
+            else if ("sizd".equals(factname)) { // Directory size
+                file.setSize(Long.parseLong(factvalue));
+            }
             else if ("modify".equals(factname)) {
                 // YYYYMMDDHHMMSS[.sss]
                 SimpleDateFormat sdf; // Not thread-safe
@@ -127,9 +146,10 @@ public class MLSxEntryParser extends FTP
                     file.setGroup(factvalue);
                 } else if ("owner".equals(unixfact)){
                     file.setUser(factvalue);
-                } else if ("mode".equals(unixfact)){ // e.g. 0755
+                } else if ("mode".equals(unixfact)){ // e.g. 0[1]755
+                    int off = factvalue.length()-4; // only parse last 3 digits
                     for(int i=1; i<=3; i++){
-                        int ch = factvalue.charAt(i)-'0';
+                        int ch = factvalue.charAt(off+i)-'0';
                         for(int p : UNIX_PERMS[ch]) {
                             file.setPermission(UNIX_GROUPS[i-1], p, true);
                         }


Reply via email to