From 8ebb09b9d8f67795fb226ee60c5b2f06f87ccb9b Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 10 May 2010 11:46:39 +0200 Subject: [PATCH] Rewrite Samba file list parsing. --- framework/VFS/lib/VFS/smb.php | 26 ++++++-------------------- framework/VFS/test/VFS/SmbTest.php | 4 ++-- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/framework/VFS/lib/VFS/smb.php b/framework/VFS/lib/VFS/smb.php index e90a00371..22c97f8d5 100644 --- a/framework/VFS/lib/VFS/smb.php +++ b/framework/VFS/lib/VFS/smb.php @@ -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' => '', diff --git a/framework/VFS/test/VFS/SmbTest.php b/framework/VFS/test/VFS/SmbTest.php index efb5e1a4a..e15de0fb9 100644 --- a/framework/VFS/test/VFS/SmbTest.php +++ b/framework/VFS/test/VFS/SmbTest.php @@ -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', -- 2.11.0