alchemy-fr / Zippy

PHP zip/tar/bz2 archives (de)compression library with commandline or extensions
Other
470 stars 106 forks source link

Cant delete file #127

Open nmsobri opened 7 years ago

nmsobri commented 7 years ago

Is there a way to close the file that zippy had open?

$zippy = Zippy::load();

#Open the archive
$archive = $zippy->open( $destination_file );

#List the file
$lists = array();
foreach( $archive as $member ) {
    if ( !$member->isDir() ) {
        $lists[] = $member;
    }
}

#Extracts the archive
$archive->extract( ROOT_PATH . 'images/upload/' );

unlink($destination_file) //<-------cant delete file, it gives error "Text file busy"
fabre-thibaud commented 7 years ago

I cannot reproduce your issue with the following code:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$archivePath = 'test.zip';

copy('source.zip', $archivePath);

$zippy = Alchemy\Zippy\Zippy::load();
$archive = $zippy->open($archivePath);

$lists = array();
foreach( $archive as $member ) {
        if ( !$member->isDir() ) {
                $lists[] = $member;
        }
}

$archive->extract(__DIR__ . '/extract');

unlink($archivePath);

Can you provide more details about the environment in which the error is occuring ?

nmsobri commented 7 years ago

I'm running the php code inside vagrant machine

Host : Windows 10 Guest: Ubuntu 14.04 Server : Apache2 Php : Php5.6

I'm pretty sure its somehow related to zippy not releasing file pointer to the open file. When i commented all the code related to zippy, it can delete the file.

fabre-thibaud commented 7 years ago

Maybe the ZIP process is not closed correctly on Windows platforms. I will try to reproduce in the same env as yours.

filippotoso commented 2 years ago

I solved this issue setting $archive to null before the unlink() call:

// ...

$archive->extract(__DIR__ . '/extract');

$archive = null;

unlink($archivePath);