#013517: Not possible to add directories

Description:

I want to have empty directories on my zip that seems to be not possible.

Bug or Feature i don`t know...



Warning: fopen(ez.app\images): failed to open stream: Permission denied in C:\ph
p5\PEAR\ezc\Archive\checksums.php on line 142

Warning: file_get_contents(ez.app\images): failed to open stream: Permission den
ied in C:\php5\PEAR\ezc\Archive\zip\zip.php on line 476

Warning: fopen(ez.app\scripts): failed to open stream: Permission denied in C:\p
hp5\PEAR\ezc\Archive\checksums.php on line 142

Warning: file_get_contents(ez.app\scripts): failed to open stream: Permission de
nied in C:\php5\PEAR\ezc\Archive\zip\zip.php on line 476
Closing archive ez.app.zip.


Environment:

Operating System:
PHP Version: (please be specific, like '4.4.3' or '5.1.5')
Database and version:
Browser (and version):


- Attachments
bug.zip (1.3 kb)
[Download] [Permanent Link]

- Comments

Björn, you would have to provide more accurate information in order for us to do anything with this bug report. A bug report should always includes a step-by-step guide to say what exactly you are doing. This should include a *short* but *independent* script -- 20 lines, without making use of additional resources. In case the bug relates to an external resource (such as a tar file), you will need to provide it.

#257918 by Derick Rethans on August 26th, 2008 [Permanent Link]

I added all to a little test suite for you... bug.zip... My goal is to add a empty directory "var/bjoern".



C:\workspace\bug>php test.php

Warning: fopen(var): failed to open stream: Permission denied in C:\php5\PEAR\ez
c\Archive\checksums.php on line 142

Warning: file_get_contents(var): failed to open stream: Permission denied in C:php5\PEAR\ezc\Archive\zip\zip.php on line 476

C:\workspace\bug>php test.php

Warning: fopen(var): failed to open stream: Permission denied in C:\php5\PEAR\ez
c\Archive\checksums.php on line 142

Warning: file_get_contents(var): failed to open stream: Permission denied in C:php5\PEAR\ezc\Archive\zip\zip.php on line 476

#257926 by Björn Dieding@xrow.de on August 26th, 2008 [Permanent Link]

The Archive component relies on fopen() to add files and directories to archive, and on Windows fopen() does not work on directories ("Permission denied" error).

On Linux this is the way you would add all the files and directories from your uploaded example to a zip file:


$archive = ezcArchive::open( "my_archive.zip", ezcArchive::ZIP );

$archive->truncate();

$filesToAppend[] = "var/";
$filesToAppend[] = "var/bjoern/";
$filesToAppend[] = "var/Neues Textdokument (2).txt";
$filesToAppend[] = "var/Neues Textdokument.txt";

$archive->append( $filesToAppend, '' );

This code also adds the 'var' folder to the archive. Use 'var' as the second parameter for append() to prevent adding the 'var' folder to the archive.

#259281 by Alexandru Stanoi on December 2nd, 2008 [Permanent Link]

On closer inspection, the code works in Windows as well. But the first file ('var/') is not needed, because an empty entry is created in the archive.

So the code to add the files in the 'var' folder (with the empty subfolder 'bjoern') to a zip archive on Windows and Linux is:


$archive = ezcArchive::open( "my_archive.zip", ezcArchive::ZIP );

$archive->truncate();

$filesToAppend[] = "var/bjoern/";
$filesToAppend[] = "var/Neues Textdokument (2).txt";
$filesToAppend[] = "var/Neues Textdokument.txt";

$archive->append( $filesToAppend, '' );

or $archive->append( $filesToAppend, 'var' ); if you don't want the 'var' folder in the archive.

#259284 by Alexandru Stanoi on December 2nd, 2008 [Permanent Link]

Hmm your solution might work...

Please consider...

your proposal looks to me like a workaround and also mean that for my secenario I need to search a big big dir twice meaning I would consume more ram and more cpu time.

Do you think that with some additional code/checks you can make it work like that?



$archive = ezcArchive::open( "my_archive.zip", ezcArchive::ZIP );

$archive->truncate();

$filesToAppend[] = "var";

$archive->append( $filesToAppend, 'var' );


#259288 by Björn Dieding@xrow.de on December 2nd, 2008 [Permanent Link]

We fixed the notice that is thrown on Windows when adding directories to an archive (in SVN).

You don't need to read the directory twice. Just browse through the directory recursively and add every file and directory you find to the archive as you go. One way to do it is to use the new Base functionality of ezcBase::walkRecursive() (also in SVN). The next code shows how to browse recursively the directory that you want to add to an archive and add all files and directories which are found to the archive:


class ArchiveContext extends ezcBaseFileFindContext
{
    public $archive;
    public $prefix;
}

function findRecursiveCallback( ezcBaseFileFindContext $context, $sourceDir, $fileName, $fileInfo )
{
    $path = "{$sourceDir}/{$fileName}";
    if ( is_dir( $path ) )
    {
        $path .= '/';
    }
    $context->archive->append( array( $path ), $context->prefix );
}

function appendRecursive( $archive, $sourceDir, $prefix )
{
    $context = new ArchiveContext();
    $context->archive = $archive;
    $context->prefix = $prefix;
    ezcBaseFile::walkRecursive( $sourceDir, array(), array(), 'findRecursiveCallback', $context );
}

$archive = ezcArchive::open( "my_archive.zip", ezcArchive::ZIP );
$archive->truncate();

// the 2nd parameter is the directory, the 3rd parameter is the prefix
appendRecursive( $archive, 'var', 'var' );

Of course it would be easier to have this functionality by default in Archive. You can file a feature request for it, but it won't be added in the eZ Components 2008.2 release (out this month) because we are already in the beta phase.

#259315 by Alexandru Stanoi on December 5th, 2008 [Permanent Link]

The warnings were fixed in SVN rev. 9533. The Archive tutorial was updated with information on how to add directories on Windows and how to add a directory tree recursively. The fix will be available in Archive 1.3.1 (part of eZ Components 2008.2rc1).

#259317 by Alexandru Stanoi on December 5th, 2008 [Permanent Link]

Yes I would like it.. It is far more handy.

Please create a feature request.

#259346 by Björn Dieding@xrow.de on December 8th, 2008 [Permanent Link]

- History
Properties
Type Bug
Priority Medium
Component Components » Archive
Affects Unknown
Fix Version 2008.2RC1 - eZ components 2008.2RC1
Reporter Björn Dieding@xrow.de
Responsible Alexandru Stanoi
Status 0 Closed
Resolution Fixed
Created August 21st, 2008
Updated December 8th, 2008
Resolved December 5th, 2008
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #015537
  Graph shows to small and truncated rotated axis labels