php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51857 deleteName() for directories returns True on non-success
Submitted: 2010-05-19 09:43 UTC Modified: 2013-02-18 00:34 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: nuabaranda at web dot de Assigned: pajoye
Status: No Feedback Package: Zip Related
PHP Version: 5.3.3-dev OS: Linux 2.6.27
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-05-19 09:43 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-21 19:41 UTC] philip@php.net
-Status: Open +Status: Verified -PHP Version: 5.2.13 +PHP Version: 5.3.3-dev
 [2010-05-21 19:41 UTC] philip@php.net
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)
}
 [2010-05-22 00:16 UTC] philip@php.net
-Assigned To: +Assigned To: pajoye
 [2010-09-14 15:19 UTC] pajoye@php.net
-Status: Verified +Status: Feedback
 [2010-09-14 15:19 UTC] pajoye@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I can't reproduce the problem, can you try again pls?
 [2012-05-24 03:14 UTC] maxspeed40k at gmail dot com
reproduce the problem
PHP Version: 5.4.3
OS: windows 7
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 02:02:10 2014 UTC