Attached is a patch against LWP 5.800 (or 5.79, the files didn't change)
to allow File::Listing to interpret the output of GNU ls's --full-time
option (tested with GNU ls 4.1 and 4.5, which unfortunately have
completely different formats).  This allows you to get timestamps
accurate to the second, instead of the minute-based ones you get with a
normal "ls -l".

It also handles BSD ls's -T option (which is similar to GNU ls 4.1's
--full-time option).  (Thanks to Ville Skyttä, who sent an example of
a BSD listing, confirming that it does look like the manpage said.)

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

This time I made sure to test the patch file; it should apply cleanly.

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

-- 
Chris Madsen                                            [EMAIL PROTECTED]
  ------------------  http://www.pobox.com/~cjm  ------------------
--- c:/tmp/lib/File/Listing.pm  Sun Oct 26 08:24:22 2003
+++ lib/File/Listing.pm Tue Jun 15 15:33:10 2004
@@ -144,7 +144,9 @@
         .*                                       # 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
+         \d{4}-\d\d-\d\d\s+\d{1,2}:\d\d(?::\d\d(?:\.\d+)?)?(?:\s+[-+]\d{4})?) # or 
ISO date
         \s+                                      # Some more space
         (.*)$                                    # File name
        /x )
@@ -371,10 +373,12 @@
 =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

--- c:/tmp/t/base/listing.t     Thu Nov 14 07:07:44 1996
+++ t/base/listing.t    Thu Jun 17 10:55:10 2004
@@ -1,4 +1,4 @@
-print "1..6\n";
+print "1..26\n";


 use File::Listing;
@@ -84,3 +84,167 @@

 $mode == 0100644 || print "not ";
 print "ok 6\n";
+
+
+# Test GNU ls version 4.1 -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 GNU ls version 4.5 -l --full-time format (aka --time-style=full-iso):
+$iso_time_dir = <<'EOL';
+total 68
+drwxr-xr-x    4 aas      users        1024 2004-03-16 15:47:02.000000000 -0600 .
+drwxr-xr-x   11 aas      users        1024 2004-03-15 19:22:31.000000000 -0600 ..
+drwxr-xr-x    2 aas      users        1024 2004-03-16 15:47:40.000000000 -0600 CVS
+-rw-r--r--    1 aas      users        2384 2004-02-26 21:14:22.000000000 -0600 
Debug.pm
+-rw-r--r--    1 aas      users        2145 2004-02-26 20:09:12.000000000 -0600 IO.pm
+-rw-r--r--    1 aas      users        3960 2004-03-15 18:05:50.000000000 -0600 
MediaTypes.pm
+-rw-r--r--    1 aas      users         792 2004-02-26 20:12:44.000000000 -0600 
MemberMixin.pm
+drwxr-xr-x    3 aas      users        1024 2004-03-15 18:05:33.000000000 -0600 
Protocol
+-rw-r--r--    1 aas      users        5613 2004-02-26 20:16:22.000000000 -0600 
Protocol.pm
+-rw-r--r--    1 aas      users        5963 2003-02-26 21:27:11.000000000 -0600 
RobotUA.pm
+-rw-r--r--    1 aas      users        5071 2004-03-16 12:25:58.000000000 -0600 
Simple.pm
+-rw-r--r--    1 aas      users        8817 2003-03-15 18:05:59.000000000 -0600 
Socket.pm
+-rw-r--r--    1 aas      users        2121 2002-02-05 14:22:00.000000000 -0600 TkIO.pm
+-rw-r--r--    1 aas      users       19628 2004-03-15 18:05:20.000000000 -0600 
UserAgent.pm
+-rw-r--r--    1 aas      users        2841 2004-02-05 19:06:30.000000000 -0600 
media.types
+EOL
+
[EMAIL PROTECTED] = parse_dir($iso_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";
+
+$mtime == 0x3E73BFE7 or print "not ";
+print "ok 15\n";
+
+$mode == 0100644 || print "not ";
+print "ok 16\n";
+
+
+# Test GNU ls version 4.5 -l --time-style=long-iso:
+$iso_time_dir = <<'EOL';
+total 68
+drwxr-xr-x    4 aas      users        1024 2004-03-16 15:47 .
+drwxr-xr-x   11 aas      users        1024 2004-03-15 19:22 ..
+drwxr-xr-x    2 aas      users        1024 2004-03-16 15:47 CVS
+-rw-r--r--    1 aas      users        2384 2004-02-26 21:14 Debug.pm
+-rw-r--r--    1 aas      users        2145 2004-02-26 20:09 IO.pm
+-rw-r--r--    1 aas      users        3960 2004-03-15 18:05 MediaTypes.pm
+-rw-r--r--    1 aas      users         792 2004-02-26 20:12 MemberMixin.pm
+drwxr-xr-x    3 aas      users        1024 2004-03-15 18:05 Protocol
+-rw-r--r--    1 aas      users        5613 2004-02-26 20:16 Protocol.pm
+-rw-r--r--    1 aas      users        5963 2003-02-26 21:27 RobotUA.pm
+-rw-r--r--    1 aas      users        5071 2004-03-16 12:25 Simple.pm
+-rw-r--r--    1 aas      users        8817 2003-03-15 18:05 Socket.pm
+-rw-r--r--    1 aas      users        2121 2002-02-05 14:22 TkIO.pm
+-rw-r--r--    1 aas      users       19628 2004-03-15 18:05 UserAgent.pm
+-rw-r--r--    1 aas      users        2841 2004-02-05 19:06 media.types
+EOL
+
[EMAIL PROTECTED] = parse_dir($iso_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 17\n";
+
+$type eq "f" || print "not ";
+print "ok 18\n";
+
+$size == 8817 || print "not ";
+print "ok 19\n";
+
+scalar(localtime($mtime)) eq 'Sat Mar 15 18:05:00 2003' or print "not ";
+print "ok 20\n";
+
+$mode == 0100644 || print "not ";
+print "ok 21\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 22\n";
+
+$type eq "f" || print "not ";
+print "ok 23\n";
+
+$size == 8817 || print "not ";
+print "ok 24\n";
+
+scalar(localtime($mtime)) eq 'Sat Mar 15 18:05:59 2003' or print "not ";
+print "ok 25\n";
+
+$mode == 0100644 || print "not ";
+print "ok 26\n";

Reply via email to