How to create symlink in zipfile in python

本小妞迷上赌 提交于 2019-12-13 00:40:01

问题


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.

来源:https://stackoverflow.com/questions/43196350/how-to-create-symlink-in-zipfile-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!