Home » File Formats » File_Archive » Bug #4165
tar and tar.gz directory structure not maintained
Details
| Submitted | 2005-04-16 19:18 UTC |
|---|---|
| From | dmytton at php dot net |
| Assigned | vincentlascaux |
| Status | Closed |
| Package | File_Archive |
| PHP Version | 5.0.3 |
| OS | Windows & Fedora Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-04-16 19:18 UTC] dmytton at php dot net
Description:
------------
When generating a dynamic .tar or .tar.gz archive, the directory structure is not maintained. When using the same code to generate a .zip and .tar.bz2 file, the directory structure is maintained.
Reproduce code:
---------------
// Generate .tar file from dir/
$source = File_Archive::read('dir', 'dir'); $source->extract(File_Archive::toArchive('dir'.'.tar', File_Archive::toFiles()));
// Generate .tar.gz file from dir/
$source = File_Archive::read('dir', 'dir'); $source->extract(File_Archive::toArchive('dir'.'.tar.gz', File_Archive::toFiles()));
Expected result:
----------------
The archive should maintain the full directory structure.
Actual result:
--------------
All the files are in the root directory with no directory names or structure preserved.
[2005-04-16 20:04 UTC] lascauv4 at cti dot ecp dot fr
I haven't been able to reproduce the problem (the directory structure is maintained in my tar files as well as zip, tar.gz, tgz...)
How are you checking that the directory structure is lost?
Could you send me by email the tar file generated by the script?
[2005-04-16 20:14 UTC] dmytton at php dot net
Sent the incorrect .tar.gz file and correct .zip file generated via e-mail.
[2005-04-16 21:16 UTC] lascauv4 at cti dot ecp dot fr
I did not receive anything... I think my web hoster does not allow zip files as attached files :(
Could you post a URL were I could download the files?
[2005-04-16 21:21 UTC] dmytton at php dot net
You can download them at
http://expanse.olate.co.uk/5a9ac4-iono.zip
http://expanse.olate.co.uk/b5d71d-iono.tar.gz
[2005-04-16 21:37 UTC] lascauv4 at cti dot ecp dot fr
WinRAR shows the same directory structure in both files. What reader are you using to read the tar file?
If there is a bug, it is probably in the tar writer, that generate something invalid that winrar understands but not your writer. In this case, I really don't understand why it works for tar.bz2.
[2005-04-16 21:42 UTC] dmytton at php dot net
Yes, you are correct, it does load fine in WinRar. I used Winzip (9.0) to view it, which does not show the directories. But my system is configured to view .tar.bz2 files in WinRar which is why I found no problem with those.
[2005-04-16 22:00 UTC] lascauv4 at cti dot ecp dot fr
Here is the technical explaination of the bug (or at least that's what I think):
There are two versions of the tar file. The difference is in the headers: they are both 512 bytes long, but the oldest version does not use the last 256 bytes (for more details, see http://www.mkssoftware.com/docs/man4/tar.4.asp). I think that the version of winzip you are using does not understand the latest version of the tar headers
The new version allows longer names (up to 255 bytes long) by allowing to split the name in two locations. What I did was putting the file name in the first location and the path in the second. If winzip doesnt read the last 256 bytes, it won't read the path info.
In CVS, I now split the filename after 100bytes, which mean that winzip will have no problem if the filename is less than 100byte long.
The quickfix is to change line 67 of File/Archive/Writer/Tar.php from $pos = strrpos($filename, "/"); to $pos = false; and not using filenames longer than 100bytes long (including directory).
Could you please check that doing so solves the problem?
[2005-04-16 22:07 UTC] dmytton at php dot net
Yes, that did indeed fix the problem. Great!
[2005-04-16 22:15 UTC] lascauv4 at cti dot ecp dot fr
This bug has been fixed in CVS.
In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.
In case this was a pear.php.net website problem, the change will show
up on the website in short time.
Thank you for the report, and for helping us make PEAR better.
[2005-04-22 19:00 UTC] dmytton at php dot net
I am now using the latest version - 1.0.1 - and this problem still exists.
[2005-04-22 19:50 UTC] dmytton at php dot net
The example code would probably be the same as when I originally submitted the bug. I've changed the code slightly from that however:
$location = 'deep/dir/''
$ext = '.tar.gz';
$source = File_Archive::read($location, $location); $source->extract(File_Archive::toArchive($location.$ext, File_Archive::toFiles()));
I have uploaded a file at http://expanse.olate.co.uk/a1a743-iono.tar.gz which demonstrates this problem. Just open it with WinZip and you will see. This is a problem with file paths over 100 characters I believe.