Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.5

Bug #6546 File added twice
Submitted: 2006-01-21 17:17 UTC
From: david at olate dot co dot uk Assigned: pfischer
Status: Assigned Package: File_Archive
PHP Version: 5.1.2 OS: Red Hat Enterprise Linux
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 35 + 42 = ?

 
 [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.

Comments

 [2006-04-28 18:25 UTC] bryn at mrpath dot com (bryn)
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 (David Sanders)
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 (David Sanders)
PS. That file was File/Archive/Reader/Directory.php
 [2006-07-24 11:02 UTC] dsanders at baselinesolutions dot com dot au (David Sanders)
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 (Pablo Fischer)
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 (Pablo Fischer)
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 (Pablo Fischer)
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. ====
 [2007-05-14 10:05 UTC] sinasalek (Sina Salek)
the patch worked for me.
 [2008-09-16 12:56 UTC] immesys (Michael Andersen)
Has this bug been fixed yet, and if so has it been submitted? The diff supplied works but the version I get when using 'pear install' on ubuntu still has the bug. If this bug was submitted two years ago, shouldn't something have happened by now?