Bug #51857 [Opn->Ver]: deleteName() for directories returns True on non-success
| From: | philip@php.net | Date: | Fri, 21 May 2010 17:41:43 +0000 |
| Subject: | Bug #51857 [Opn->Ver]: deleteName() for directories returns True on non-success | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150715@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51857&edit=1
ID: 51857
Updated by: philip@php.net
Reported by: nuabaranda at web dot de
Summary: deleteName() for directories returns True on
non-success
-Status: Open
+Status: Verified
Type: Bug
Package: Zip Related
Operating System: Linux 2.6.27
-PHP Version: 5.2.13
+PHP Version: 5.3.3-dev
New Comment:
And for good measure:
<?php
define ('FILEPATH_ZIPFILE', '/tmp/test.zip');
/* Create the Zip file */
$zip = new ZipArchive;
if ($zip->open(FILEPATH_ZIPFILE, ZIPARCHIVE::CREATE) === TRUE) {
$zip->addFromString('foo.txt', 'foo');
$zip->addFromString('bar.txt', 'bar');
$zip->addEmptyDir('EmptyDirectory');
$zip->addEmptyDir('FullDirectory');
$zip->addFromString('FullDirectory/baz.txt', 'baz');
$zip->close();
}
/* Mess with the Zip file */
$zip = new ZipArchive;
if ($zip->open(FILEPATH_ZIPFILE) === TRUE) {
/* Fails to delete */
$r1 = $zip->deleteName('EmptyDirectory');
/* Successful delete (note the appended '/' */
$r2 = $zip->deleteName('EmptyDirectory/');
/* Fails to delete */
$r3 = $zip->deleteName('FullDirectory');
/* Fails to delete, although returns true */
$r4 = $zip->deleteName('FullDirectory/');
$zip->close();
}
/* Display the Zip file contents */
$zip = new ZipArchive;
if ($zip->open(FILEPATH_ZIPFILE) === TRUE) {
echo 'File count: ', $zip->numFiles, PHP_EOL;
echo 'Status: ', $zip->status, PHP_EOL;
for ($i = 0; $i < $zip->numFiles; $i++) {
$stat = $zip->statIndex($i);
echo 'Index: ', $i, ' ', $stat['name'], PHP_EOL;
}
$zip->close();
}
var_dump(
array('r1' => $r1, 'r2' => $r2, 'r3' => $r3,
'r4' => $r4)
);
Returns:
File count: 3
Status: 0
Index: 0 foo.txt
Index: 1 bar.txt
Index: 2 FullDirectory/baz.txt
array(4) {
["r1"]=>
bool(false)
["r2"]=>
bool(true)
["r3"]=>
bool(false)
["r4"]=>
bool(true)
}
Previous Comments:
------------------------------------------------------------------------
[2010-05-19 09:43:27] nuabaranda at web dot de
Description:
------------
When trying to delete a non-empty directory in a ZIP file with
deleteName() the function will return True and not delete the directory
if it is not empty. Expectation would be to return False if the
directory can not be deleted.
Also the directory handling should be better documentated (usage of
trailing slashes, examples).
Test script:
---------------
$zip = new ZipArchive;
if( $zip->open('archive.zip', ZipArchive::CREATE) ) {
$zip->addEmptyDir('folder');
$zip->addFile('folder/file.txt');
if( ! $zip->deleteName('folder/') ) {
echo 'Should end up here if folder not deletable';
}
}
$zip->close();
Expected result:
----------------
Should echo.
Actual result:
--------------
Will not echo.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51857&edit=1