Rewrite Samba file list parsing.
authorJan Schneider <jan@horde.org>
Mon, 10 May 2010 09:46:39 +0000 (11:46 +0200)
committerJan Schneider <jan@horde.org>
Mon, 10 May 2010 12:04:31 +0000 (14:04 +0200)
framework/VFS/lib/VFS/smb.php
framework/VFS/test/VFS/SmbTest.php

index e90a003..22c97f8 100644 (file)
@@ -353,46 +353,32 @@ class VFS_smb extends VFS
         $files = array();
         for ($r = 0; $r < $num_lines; $r++) {
             // Match file listing.
-            if (!preg_match('/^(\s\s.+\s{6,})/', $res[$r])) {
+            if (!preg_match('/^  (.+?) +([A-Z]*) +(\d+)  (\w\w\w \w\w\w [ \d]\d \d\d:\d\d:\d\d \d\d\d\d)$/', $res[$r], $match)) {
                 continue;
             }
 
-            // Split into columns at every six spaces
-            $split1 = preg_split('/\s{6,}/', trim($res[$r]));
             // If the file name isn't . or ..
-            if ($split1[0] == '.' || $split1[0] == '..') {
+            if ($match[1] == '.' || $match[1] == '..') {
                 continue;
             }
 
-            if (isset($split1[2])) {
-                // If there is a small file size, inf could be split
-                // into 3 cols.
-                $split1[1] .= ' ' . $split1[2];
-            }
-            // Split file inf at every one or more spaces.
-            $split2 = preg_split('/\s+/', $split1[1]);
-            if (is_numeric($split2[0])) {
-                // If there is no file attr, shift cols over.
-                array_unshift($split2, '');
-            }
-            $my_name = $split1[0];
+            $my_name = $match[1];
 
             // Filter out dotfiles if they aren't wanted.
             if (!$dotfiles && substr($my_name, 0, 1) == '.') {
                 continue;
             }
 
-            $my_size = $split2[1];
+            $my_size = $match[3];
             $ext_name = explode('.', $my_name);
 
-            if ((strpos($split2[0], 'D') !== false)) {
+            if ((strpos($match[2], 'D') !== false)) {
                 $my_type = '**dir';
                 $my_size = -1;
             } else {
                 $my_type = self::strtolower($ext_name[count($ext_name) - 1]);
             }
-            $my_date = strtotime($split2[4] . ' ' . $split2[3] . ' ' .
-                                 $split2[6] . ' ' . $split2[5]);
+            $my_date = strtotime($match[4]);
             $filedata = array('owner' => '',
                               'group' => '',
                               'perms' => '',
index efb5e1a..e15de0f 100644 (file)
@@ -65,12 +65,12 @@ class VFS_SmbTest extends PHPUnit_Framework_TestCase
                     'date' => 1243426505,
                     'size' => -1,
                     ),
-                'Datei mit SOnderzeichen ¿ Ã§ µ ° juhuuu.txt' =>
+                'Datei mit SOnderzeichen ¿ € § µ ° juhuuu.txt' =>
                 array (
                     'owner' => '',
                     'group' => '',
                     'perms' => '',
-                    'name' => 'Datei mit SOnderzeichen ¿ Ã§ µ ° juhuuu.txt',
+                    'name' => 'Datei mit SOnderzeichen ¿ € § µ ° juhuuu.txt',
                     'type' => 'txt',
                     'date' => 1243426538,
                     'size' => '0',