Edit report at https://bugs.php.net/bug.php?id=55195&edit=1
ID: 55195
Comment by: ralph at ralphschindler dot com
Reported by: kedomingo at gmail dot com
Summary: PharData::buildFromDirectory does not seem to close
the file after archiving
Status: Open
Type: Bug
Package: PHAR related
Operating System: Windows 7 Professional 32bit
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Why should you be able to delete the currently open phar?
It seems to me that $file2 is still open for modification in PHP, for example,
you can call setStub(), or add new files or metadata to the $phar you have
open.
Since this is the case,
Even unlinkArchive() seems to imply in its documentation that the $phar needs
to
have the reference removed before you can unlink it:
http://www.php.net/manual/en/phar.unlinkarchive.php
I am inclined to say that this is not an issue.
Previous Comments:
------------------------------------------------------------------------
[2012-04-21 20:23:19] michaelmotes at email dot com
I worked around this bug by simply destroying the phar object, unset($phar).
------------------------------------------------------------------------
[2011-07-12 22:37:59] kedomingo at gmail dot com
Description:
------------
While I can create a file, write to it, close it, and delete it via unlink, I
can't delete a file created by the buildFromDirectory function of PharData. I
suspect that the file has been left open.
Test script:
---------------
<?php
$file = uniqid().".txt"; /// Demo: Script can create and delete a file (if
properly closed) normally
if( !($f = fopen($file, 'w')) ) echo "Could not open $file <br />\n";
if( !fwrite($f, 'test') ) echo "Could not write to $file <br />\n";
if( !fclose($f) ) echo "Could not close $file <br />\n";
if( !unlink($file) ) echo "Could not delete $file <br />\n";
if( !is_dir( $dir = dirname(__FILE__) . '/phartest' ) ) { /// Create test
directory for PharData
mkdir( dirname(__FILE__) . '/phartest' );
for($i = 0; $i < 3; $i++) { $f = fopen($dir . "/file$i.txt", 'w');
fwrite($f, $i); fclose($f); };
}
$file2 = uniqid().".zip"; /// Create test archive in the same directory as the
demo file
$phar = new PharData($file2);
if( $phar->buildFromDirectory($dir) )
if(!unlink($file2)) /// Did phar close the file? Can we delete it?
echo "Could not delete $file2!";
?>
Expected result:
----------------
I expect that the call to unlink($file2) will delete the newly created archive
(with filename $file2)
Actual result:
--------------
Warning: unlink(<$file2>): Permission denied in C:\htdocs\phartest.php on line
17
Could not delete <$file2>!
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55195&edit=1