PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » File Formats » File_Archive » Bug #6546

File added twice

Details

Submitted2006-01-21 17:17 UTC
Fromdavid at olate dot co dot uk
Assignedpfischer
StatusAssigned
PackageFile_Archive
PHP Version5.1.2
OSRed Hat Enterprise Linux
Roadmaps(Not assigned)

Comments

[2006-01-21 17:17 UTC] david at olate dot co dot uk

Description:
------------
If you archive a directory, the first file is added to the archive twice.

Test script:
---------------
Directory /home/frame4net/public_html/downloads/cart-2 contains:

-rw-r--r-- 1 apache apache 1024 Jan 21 12:02 1mb.test-file

<?php
$tmpdir = '/home/frame4net/public_html/downloads/cart-2';
File_Archive::extract($tmpdir, File_Archive::toArchive('Cart-2.zip', File_Archive::toOutput()));
?>

Expected result:
----------------
The output Cart-2.zip file should only contain 1 instance of 1mb.test-file

Actual result:
--------------
There are 2 instances of 1mb.test-file both exactly the same.

[2006-04-28 18:25 UTC] bryn at mrpath dot com

We're seeing this not just for the first file. We get 3 copies of files that are in subfolders when we pass file_archive a folder to zip

We are zipping a directory tree that looks like this:

folder/
file1.jpg
file2.jpg
SubFolder1/
file3.jpg
file4.jpg

so the zip ends up containing

file1.jpg
file2.jpg
file3.jpg
file3.jpg
file3.jpg
file4.jpg
file4.jpg
file4.jpg

[2006-06-05 07:22 UTC] dsanders at baselinesolutions dot com dot au

Perhaps a patch is in order...

@@ -101,6 +101,8 @@ class File_Archive_Reader_Directory exte
}
}

+ $this->source = null;
+
while ($this->source === null ||
($error = $this->source->next()) !== true) {

[2006-06-05 07:24 UTC] dsanders at baselinesolutions dot com dot au

PS. That file was File/Archive/Reader/Directory.php

[2006-07-24 11:02 UTC] dsanders at baselinesolutions dot com dot au

Actually that diff is incorrect, I didn't understand how the process of adding files worked. I think the following patch takes care of this bug:

@@ -101,7 +101,9 @@ class File_Archive_Reader_Directory exte
}
}

+ $file = null;
while ($this->source === null ||
+ $file == '.' || $file == '..' ||
($error = $this->source->next()) !== true) {

if ($this->source !== null) {

The problem is that the dot and dotdot directories don't always appear first. Run ls -Ul on a directory (U lists the entries in directory order, which I presume is the same as readdir). When the dot and dotdot entries are skipped, the next() in the while condition is called again, causing the file or directory to be duplicated in the archive.

[2007-01-08 19:08 UTC] pfischer at php dot net

This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.

I couldn't reproduce it in SVN I think Vincent fixed it but forgot to close this bug.

[2007-01-17 02:27 UTC] pfischer at php dot net

I'll try to find a better solution since seems the patch only works in some cases.

[2007-01-17 02:29 UTC] pfischer at php dot net

Here's a copy of a mail I got from David Sanders, the reason to have it here is for feedback.

====
Doing an ls -lUa should show you the order in which the filesystem stores the files which is the same order as readdir()

Here's an example:

[dave@mozart contacts]$ ls -lUa
total 20
-rw-rw-r-- 1 dave dave 172 Jan 17 11:48 prospective.csv
drwxrwxr-x 3 dave dave 4096 Jan 16 23:41 ..
drwxr-xr-x 2 dave dave 4096 Jan 17 11:48 .
-rw-r--r-- 1 dave dave 150 Jan 17 11:48 current.csv
-rw-r--r-- 1 dave dave 146 Jan 17 11:48 assessors.csv

Note that '.' and '..' do not come first. I've attached the zip file that was created from this directory.

The files that are duplicated are the ones before '.' and '..', that is prospective.csv which is duplicated twice due to both '.' and '..' following it straight after.
====