1

I have a zipfile which is stored in memory as io.BytesIO buffer. Within, the zipfile, I need to create a symlink to one of the directories.

Below is what I have tried so far (from this similar question on SO) but it is not creating the link as I want at top level.

Link to be created to : root/scale/lib/hypervisor/kvm/pika_3_5

Link name : 'pika'

Link location : at top level

Existing Zipfile : data['egg_buffer']

with zipfile.ZipFile(data['egg_buffer'], 'a') as zip_buffer:
    dest = 'root/scale/lib/hypervisor/kvm/pika_3_5'
    info = zipfile.ZipInfo('pika')
    info.external_attr |= 0120000 << 16L # symlink file type
    info.compress_type = zipfile.ZIP_STORED
    zip_buffer.writestr(info, dest)
data['egg_buffer'].seek(os.SEEK_SET)

Actually this is creating a file at root level with name 'pika' but it is not a symlink and has content as text root/scale/lib/hypervisor/esx65/pika_3_5 instead.

Dharman
  • 30,962
  • 25
  • 85
  • 135
ViFI
  • 971
  • 1
  • 11
  • 27
  • 1
    Are you trying to extract this on windows? Unix symlinks don't work on windows, they will show up as file with the target as content. – mata Apr 04 '17 at 07:30
  • Possible duplicate of [archiving symlinks with python zipfile](https://stackoverflow.com/questions/35782941/archiving-symlinks-with-python-zipfile) – JosephH Dec 08 '18 at 16:30

0 Answers0