Skip to content

Commit

Permalink
Fixes #73: Throw a RuntimeException when rawlist fails, this should b…
Browse files Browse the repository at this point in the history
…e prevented in userland code.
  • Loading branch information
frankdejonge committed Feb 10, 2014
1 parent f0cd94b commit 095f87d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/Adapter/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ protected function listDirectoryContents($directory, $recursive = true)
{
$listing = ftp_rawlist($this->getConnection(), $directory, $recursive);

if ($listing === false) {

This comment has been minimized.

Copy link
@staabm

staabm Feb 10, 2014

it is not documented that ftp_rawlist might return false, see http://php.net/ftp_rawlist ?

This comment has been minimized.

Copy link
@frankdejonge

frankdejonge Feb 10, 2014

Author Member

Correct, but the entire PHP implementation of FTP wobbles, so while it is not documented, it is something that happens when you try to list the contents of a non-existing directory.

This comment has been minimized.

Copy link
@staabm

staabm Feb 10, 2014

thanks for the explanation. opened a php-bug for the doc related issue..
https://bugs.php.net/bug.php?id=66686

throw new RuntimeException('Could not perform a rawlist on directory: '.$directory);
}

return $this->normalizeListing($listing, $directory);
}
}
44 changes: 28 additions & 16 deletions tests/FtpTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ function ftp_raw($connection, $command)
return array( 0 => '211-Status of somewhere/folder/dummy.txt:', 1 => ' -rw-r--r-- 1 ftp ftp 0 Nov 24 13:59 somewhere/folder/dummy.txt', 2 => '211 End of status' );
}

function ftp_rawlist($connection)
function ftp_rawlist($connection, $directory)
{
if (strpos($directory, 'fail.rawlist') !== false) {
return false;
}

return array(
'drwxr-xr-x 4 ftp ftp 4096 Nov 24 13:58 .',
'drwxr-xr-x 16 ftp ftp 4096 Sep 2 13:01 ..',
Expand Down Expand Up @@ -147,23 +151,22 @@ function ftp_chmod($connection, $mode, $path)

class FtpTests extends \PHPUnit_Framework_TestCase
{
protected $options = array(
'host' => 'example.org',
'port' => 40,
'ssl' => true,
'timeout' => 35,
'root' => '/somewhere',
'permPublic' => 0777,
'permPrivate' => 0000,
'passive' => false,
'username' => 'user',
'password' => 'password',
);

public function testInstantiable()
{
// 'host', 'port', 'username', 'password', 'ssl', 'timeout', 'root', 'permPrivate', 'permPublic'
$options = array(
'host' => 'example.org',
'port' => 40,
'ssl' => true,
'timeout' => 35,
'root' => '/somewhere',
'permPublic' => 0777,
'permPrivate' => 0000,
'passive' => false,
'username' => 'user',
'password' => 'password',
);

$adapter = new Ftp($options);
$adapter = new Ftp($this->options);
$this->assertEquals('example.org', $adapter->getHost());
$this->assertEquals(40, $adapter->getPort());
$this->assertEquals(true, $adapter->getSsl());
Expand Down Expand Up @@ -207,6 +210,15 @@ public function testConnectFail()
$adapter->connect();
}

/**
* @expectedException RuntimeException
*/
public function testRawlistFail()
{
$adapter = new Ftp($this->options);
$adapter->listContents('fail.rawlist');
}

/**
* @expectedException RuntimeException
*/
Expand Down

0 comments on commit 095f87d

Please sign in to comment.