Attached is a patch against LWP 5.79 to allow File::Listing to
interpret the output of GNU ls's --full-time option.  This allows you
to get timestamps accurate to the second, instead of the minute-based
ones you get with a normal "ls -l".

I believe it also handles BSD ls's -T option, but I don't have a BSD
system to test.  I'm just working off the OpenBSD manpage.

The new time formats are recognized automatically; you just call
parse_dir like you normally would.

Please CC me on responses; I'm not subscribed to the list.

-- 
Chris Madsen                                            [EMAIL PROTECTED]
  ------------------  http://www.pobox.com/~cjm  ------------------
--- lib/File/Listing.pm Sun Oct 26 08:24:22 2003
+++ lib/File/Listing.pm Fri May 28 10:58:02 2004
@@ -144,7 +144,8 @@
         .*                                       # Graps
         \D(\d+)                                  # File size
         \s+                                      # Some space
-        (\w{3}\s+\d+\s+(?:\d{1,2}:\d{2}|\d{4}))  # Date
+        (\w{3}\s+\d+\s+(?:\d{1,2}:\d{2}|\d{4}) | # Date
+         \w{3}\s+(?:\w{3}\s+)?\d+\s+\d{1,2}:\d{2}(?::\d{2})?\s+\d{4}) # or Full date
         \s+                                      # Some more space
         (.*)$                                    # File name
        /x )
@@ -371,11 +372,13 @@
 =head1 DESCRIPTION
 
 This module exports a single function called parse_dir(), which can be
-used to parse directory listings. Currently it only understand Unix
-C<'ls -l'> and C<'ls -lR'> format.  It should eventually be able to
-most things you might get back from a ftp server file listing (LIST
-command), i.e. VMS listings, NT listings, DOS listings,...
+used to parse directory listings. Currently it only understands Unix
+C<'ls -l'> and C<'ls -lR'> format.  It also understands the
+C<--full-time> option of GNU B<ls> and the C<-T> option of BSD B<ls>.  It
+should eventually be able to parse most things you might get back from
+a ftp server file listing (LIST command), i.e. VMS listings, NT
+listings, DOS listings,...
 
 The first parameter to parse_dir() is the directory listing to parse.
 It can be a scalar, a reference to an array of directory lines or a
--- t/base/listing.t    Thu Nov 14 07:07:44 1996
+++ t/base/listing.t    Fri May 28 10:52:38 2004
@@ -1,4 +1,4 @@
-print "1..6\n";
+print "1..16\n";
 
 
 use File::Listing;
@@ -84,3 +84,85 @@
 
 $mode == 0100644 || print "not ";
 print "ok 6\n";
+
+
+# Test GNU ls -l --full-time format:
+$full_time_dir = <<'EOL';
+total 68
+drwxr-xr-x    4 aas      users        1024 Tue Mar 16 15:47:02 2004 .
+drwxr-xr-x   11 aas      users        1024 Mon Mar 15 19:22:31 2004 ..
+drwxr-xr-x    2 aas      users        1024 Tue Mar 16 15:47:40 2004 CVS
+-rw-r--r--    1 aas      users        2384 Thu Feb 26 21:14:22 2004 Debug.pm
+-rw-r--r--    1 aas      users        2145 Thu Feb 26 20:09:12 2004 IO.pm
+-rw-r--r--    1 aas      users        3960 Mon Mar 15 18:05:50 2004 MediaTypes.pm
+-rw-r--r--    1 aas      users         792 Thu Feb 26 20:12:44 2004 MemberMixin.pm
+drwxr-xr-x    3 aas      users        1024 Mon Mar 15 18:05:33 2004 Protocol
+-rw-r--r--    1 aas      users        5613 Thu Feb 26 20:16:22 2004 Protocol.pm
+-rw-r--r--    1 aas      users        5963 Wed Feb 26 21:27:11 2003 RobotUA.pm
+-rw-r--r--    1 aas      users        5071 Tue Mar 16 12:25:58 2004 Simple.pm
+-rw-r--r--    1 aas      users        8817 Sat Mar 15 18:05:59 2003 Socket.pm
+-rw-r--r--    1 aas      users        2121 Tue Feb  5 14:22:00 2002 TkIO.pm
+-rw-r--r--    1 aas      users       19628 Mon Mar 15 18:05:20 2004 UserAgent.pm
+-rw-r--r--    1 aas      users        2841 Thu Feb  5 19:06:30 2004 media.types
+EOL
+
[EMAIL PROTECTED] = parse_dir($full_time_dir, undef, 'unix');
+
+# Pick out the Socket.pm line as the sample we check carefully
+($name, $type, $size, $mtime, $mode) = @{$dir[9]};
+
+$name eq "Socket.pm" || print "not ";
+print "ok 7\n";
+
+$type eq "f" || print "not ";
+print "ok 8\n";
+
+$size == 8817 || print "not ";
+print "ok 9\n";
+
+scalar(localtime($mtime)) eq 'Sat Mar 15 18:05:59 2003' or print "not ";
+print "ok 10\n";
+
+$mode == 0100644 || print "not ";
+print "ok 11\n";
+
+
+# Test BSD ls -l -T format:
+$bsd_time_dir = <<'EOL';
+total 68
+drwxr-xr-x    4 aas      users        1024 Mar 16 15:47:02 2004 .
+drwxr-xr-x   11 aas      users        1024 Mar 15 19:22:31 2004 ..
+drwxr-xr-x    2 aas      users        1024 Mar 16 15:47:40 2004 CVS
+-rw-r--r--    1 aas      users        2384 Feb 26 21:14:22 2004 Debug.pm
+-rw-r--r--    1 aas      users        2145 Feb 26 20:09:12 2004 IO.pm
+-rw-r--r--    1 aas      users        3960 Mar 15 18:05:50 2004 MediaTypes.pm
+-rw-r--r--    1 aas      users         792 Feb 26 20:12:44 2004 MemberMixin.pm
+drwxr-xr-x    3 aas      users        1024 Mar 15 18:05:33 2004 Protocol
+-rw-r--r--    1 aas      users        5613 Feb 26 20:16:22 2004 Protocol.pm
+-rw-r--r--    1 aas      users        5963 Feb 26 21:27:11 2003 RobotUA.pm
+-rw-r--r--    1 aas      users        5071 Mar 16 12:25:58 2004 Simple.pm
+-rw-r--r--    1 aas      users        8817 Mar 15 18:05:59 2003 Socket.pm
+-rw-r--r--    1 aas      users        2121 Feb  5 14:22:00 2002 TkIO.pm
+-rw-r--r--    1 aas      users       19628 Mar 15 18:05:20 2004 UserAgent.pm
+-rw-r--r--    1 aas      users        2841 Feb  5 19:06:30 2004 media.types
+EOL
+
[EMAIL PROTECTED] = parse_dir($bsd_time_dir, undef, 'unix');
+
+# Pick out the Socket.pm line as the sample we check carefully
+($name, $type, $size, $mtime, $mode) = @{$dir[9]};
+
+$name eq "Socket.pm" || print "not ";
+print "ok 12\n";
+
+$type eq "f" || print "not ";
+print "ok 13\n";
+
+$size == 8817 || print "not ";
+print "ok 14\n";
+
+scalar(localtime($mtime)) eq 'Sat Mar 15 18:05:59 2003' or print "not ";
+print "ok 15\n";
+
+$mode == 0100644 || print "not ";
+print "ok 16\n";

Reply via email to