php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75066 Result of PharData::convertData produces undeletable file
Submitted: 2017-08-12 11:05 UTC Modified: 2017-08-12 13:53 UTC
From: csongor at halmai dot hu Assigned:
Status: Not a bug Package: PHAR related
PHP Version: 7.0.22 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: csongor at halmai dot hu
New email:
PHP Version: OS:

 

 [2017-08-12 11:05 UTC] csongor at halmai dot hu
Description:
------------
Executing the sample script on Windows 7 with php 7.0.4 (sorry, I cannot try a newer version), produces a ZIP file that cannot be deleted by the same script. 

The unlink() reports a "Permission denied" error message. 

If I uncomment the line of the unlinkArchive() then I get "PHP Fatal error:  Uncaught PharException: phar archive "x.zip" has open file handles or objects.  fclose() all file handles, and unset() all objects prior to calling unlinkArchive() in ....php:8"

I cannot unlink the tgz either, the messages are the same. 

When the script finishes then the file can be deleted after that.

The same script on an old Linux with php 5.5.16 works well, the zip file can be deleted without any issue. 

Test script:
---------------
<?php
	$tgzName = 'x.tgz';
	$zipName = 'x.zip';
	
	$phar    = new PharData($tgzName);
	$zip     = $phar->convertToData(Phar::ZIP);
	
	// PharData::unlinkArchive($tgzName);  // this also fails
	unlink($zipName);    // this fails.

Expected result:
----------------
The created *.zip file should be able to be deleted. 

Actual result:
--------------
"Permission denied" if only the unlink() is called.

PharException is thrown if unlinkArchive() is called before invoking unlink().


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-12 11:16 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-08-12 11:16 UTC] requinix@php.net
You posted the error message so you must now be aware that you cannot unlink an archive if it has an open file handle or Phar object. That means you can't remove x.tgz because of $phar, or x.zip because of $zip.

So why do you think either should be deleteable?
 [2017-08-12 11:44 UTC] csongor at halmai dot hu
-Status: Feedback +Status: Closed
 [2017-08-12 11:44 UTC] csongor at halmai dot hu
Oh, sorry, I think I misunderstood how it is supposed to work. It's OK now. Thanks.
 [2017-08-12 13:53 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC