From 52aeb2ea3f9ed196bfb49eeb9d7427276e422011 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 4 Jul 2015 12:57:50 -0500 Subject: [PATCH 1/2] Tests/SFTP: add unit test --- tests/Functional/Net/SFTPUserStoryTest.php | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index ca84ee65..e4fdb389 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -565,5 +565,34 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase 'Failed asserting that nonexistent scratch directory could ' . 'not be deleted using rmdir().' ); + + return $sftp; + } + + /** + * @depends testRmDirScratchNonexistent + * @group github706 + */ + public function testDeleteEmptyDir($sftp) + { + $this->assertTrue( + $sftp->mkdir(self::$scratchDir), + 'Failed asserting that scratch directory could ' . + 'be created.' + ); + $this->assertInternalType( + 'array', + $sftp->stat(self::$scratchDir), + 'Failed asserting that stat on an existant empty directory returns an array' + ); + $this->assertTrue( + $sftp->delete(self::$scratchDir), + 'Failed asserting that empty scratch directory could ' . + 'be deleted using recursive delete().' + ); + $this->assertFalse( + $sftp->stat(self::$scratchDir), + 'Failed asserting that stat on a deleted directory returns false' + ); } } From c460e511a038c9acec4288ffd32862e7f4306041 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 4 Jul 2015 13:09:26 -0500 Subject: [PATCH 2/2] SFTP: update how recursive delete's update stat cache --- phpseclib/Net/SFTP.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 7b77f074..3dee8109 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -2218,6 +2218,7 @@ class Net_SFTP extends Net_SSH2 if (!$this->_send_sftp_packet(NET_SFTP_REMOVE, pack('Na*', strlen($temp), $temp))) { return false; } + $this->_remove_from_stat_cache($temp); $i++; @@ -2228,12 +2229,12 @@ class Net_SFTP extends Net_SSH2 $i = 0; } } - $this->_remove_from_stat_cache($path); } if (!$this->_send_sftp_packet(NET_SFTP_RMDIR, pack('Na*', strlen($path), $path))) { return false; } + $this->_remove_from_stat_cache($path); $i++;