creating zipfile with symlinks

Larry Martell larry.martell at gmail.com
Fri Mar 4 17:09:59 EST 2016


On Fri, Mar 4, 2016 at 9:22 AM, Gene Heskett <gheskett at wdtv.com> wrote:
> On Friday 04 March 2016 07:18:57 Larry Martell wrote:
>
>> On Thu, Mar 3, 2016 at 10:32 PM, Larry Martell
> <larry.martell at gmail.com> wrote:
>> > On Thu, Mar 3, 2016 at 4:58 PM, Chris Angelico <rosuav at gmail.com>
> wrote:
>> >> On Fri, Mar 4, 2016 at 8:38 AM, MRAB <python at mrabarnett.plus.com>
> wrote:
>> >>> Is it even possible to zip a link?
>> >>>
>> >>> A quick search came up with this:
>> >>>
>> >>> Are hard links possible within a zip archive?
>> >>> http://stackoverflow.com/questions/8859616/are-hard-links-possible
>> >>>-within-a-zip-archive
>> >>
>> >> Hard links are different. Symlinks are files containing the target
>> >> filename, with a special mode bit set. I'm not sure if it's a
>> >> standard feature of all zip archivers, but on my Debian system, I
>> >> can use "zip --symlinks" to create such a zip. How that will unzip
>> >> on a system that doesn't understand symlinks, I don't know.
>> >>
>> >> rosuav at sikorsky:~/tmp$ ls -l
>> >> total 4
>> >> -rw-r--r-- 1 rosuav rosuav 162 Mar  4 08:48 aaa.zip
>> >> lrwxrwxrwx 1 rosuav rosuav   4 Mar  4 08:49 qwer -> asdf
>> >> rosuav at sikorsky:~/tmp$ unzip -l aaa.zip
>> >> Archive:  aaa.zip
>> >>   Length      Date    Time    Name
>> >> ---------  ---------- -----   ----
>> >>         4  2016-03-04 08:45   qwer
>> >> ---------                     -------
>> >>         4                     1 file
>> >>
>> >>
>> >> That's a broken symlink (there is no "asdf" in the directory), and
>> >> zip and unzip are both fine with that.
>> >>
>> >> Now, how the Python zipfile module handles this, I don't know. The
>> >> ZipInfo shows a file mode of 'lrwxrwxrwx', but when I call
>> >> extract(), it comes out as a regular file. You might have to do
>> >> some work manually, or else just drop to an external command with
>> >> --symlinks.
>> >
>> > Thanks. That's what I ended up doing.
>>
>> Unfortunately very slow - around 8 minutes to zip a 7GB dir using the
>> command line zip vs. 13 seconds with the python zipfile module.
>
> Obviously the python version is not doing very much, or has enough python
> magic in it to be truely called magic. In any case Larry, the operative
> phrase for any of the various compression methods is TANSTAAFL.
>
> To generate a compressed archive of 7GB of data, is going to take time,
> and I don't care what size that compressors dictionary block is. 13
> seconds is simply not a believeable figure.
>
> I also note carefully that no one has allowed as to what exactly this
> python version does do.  Thats scary...

I clearly did not have enough coffee when I wrote that (it was 7am -
if I had written it at 7pm I would have said I clearly had had too
much gin ;-).

Anyway, I checked again and it was 2 minutes. But still much faster
then the command line zip.



More information about the Python-list mailing list