fix dir for non existing folders

This commit is contained in:
Robin Appelman 2013-06-16 22:26:17 +02:00
commit c91c970a8a
2 changed files with 12 additions and 2 deletions

View file

@ -66,7 +66,9 @@ class Share {
*/ */
public function dir($path) { public function dir($path) {
$path = $this->escapePath($path); $path = $this->escapePath($path);
$this->execute('cd ' . $path); $output = $this->execute('cd ' . $path);
//check output for errors
$this->parseOutput($output);
$output = $this->execute('dir'); $output = $this->execute('dir');
$this->execute('cd /'); $this->execute('cd /');
@ -199,7 +201,8 @@ class Share {
if (strpos($lines[0], 'does not exist')) { if (strpos($lines[0], 'does not exist')) {
throw new NotFoundException(); throw new NotFoundException();
} }
list($error,) = explode(' ', $lines[0]); $parts = explode(' ', $lines[0]);
$error = array_pop($parts);
switch ($error) { switch ($error) {
case ErrorCodes::PathNotFound: case ErrorCodes::PathNotFound:
case ErrorCodes::ObjectNotFound: case ErrorCodes::ObjectNotFound:

View file

@ -255,4 +255,11 @@ class Share extends \PHPUnit_Framework_TestCase {
$this->share->rmdir($this->root . '/foobar'); $this->share->rmdir($this->root . '/foobar');
$this->share->del($this->root . '/foobar'); $this->share->del($this->root . '/foobar');
} }
/**
* @expectedException \SMB\NotFoundException
*/
public function testDirNonExisting() {
$this->share->dir('/foobar/asd');
}
} }