Fixed deleting a file
Not sure when this became an issue, but attempting to delete a file that ends with / will result in an error on OS X
This commit is contained in:
parent
90c4c53294
commit
4167d99623
2 changed files with 11 additions and 9 deletions
|
@ -37,15 +37,15 @@ class File
|
||||||
* @return boolean status of the final rmdir();
|
* @return boolean status of the final rmdir();
|
||||||
*/
|
*/
|
||||||
public static function removeDirectory($directory)
|
public static function removeDirectory($directory)
|
||||||
|
{
|
||||||
|
// If directory is a directory, read in all the files
|
||||||
|
if (is_dir($directory))
|
||||||
{
|
{
|
||||||
if (substr($directory, -1) != '/')
|
if (substr($directory, -1) != '/')
|
||||||
{
|
{
|
||||||
$directory .= '/';
|
$directory .= '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// If directory is a directory, read in all the files
|
|
||||||
if (is_dir($directory))
|
|
||||||
{
|
|
||||||
$files = scandir($directory);
|
$files = scandir($directory);
|
||||||
|
|
||||||
// Loop through said files, check for directories, and unlink files
|
// Loop through said files, check for directories, and unlink files
|
||||||
|
|
|
@ -33,10 +33,10 @@ class FileTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testMissingTrailingSlash()
|
public function testMissingTrailingSlash()
|
||||||
{
|
{
|
||||||
$directory = '/tmp/missing';
|
$directory = '/tmp/pickles-fs/missing';
|
||||||
|
|
||||||
mkdir($directory, 0777, true);
|
mkdir($directory, 0777, true);
|
||||||
touch('/tmp/missing/slash');
|
touch('/tmp/pickles-fs/missing/slash');
|
||||||
|
|
||||||
Pickles\File::removeDirectory($directory);
|
Pickles\File::removeDirectory($directory);
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ class FileTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testRemoveFileNotDirectory()
|
public function testRemoveFileNotDirectory()
|
||||||
{
|
{
|
||||||
$directory = '/tmp/dir';
|
$directory = '/tmp/pickles-fs/dir';
|
||||||
$file = '/tmp/dir/file';
|
$file = '/tmp/pickles-fs/dir/file';
|
||||||
|
|
||||||
mkdir($directory, 0777, true);
|
mkdir($directory, 0777, true);
|
||||||
touch($file);
|
touch($file);
|
||||||
|
@ -56,6 +56,8 @@ class FileTest extends PHPUnit_Framework_TestCase
|
||||||
$this->assertFalse(file_exists($file));
|
$this->assertFalse(file_exists($file));
|
||||||
|
|
||||||
Pickles\File::removeDirectory($directory);
|
Pickles\File::removeDirectory($directory);
|
||||||
|
|
||||||
|
$this->assertFalse(file_exists($directory));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue