Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

archiving symlinks with python zipfile

I have a script that creates zip files of dirs containing symlinks. I was surprised to find that the zipfiles have zipped the targets of the links as opposed to the links themselves, which is what I wanted and expected. Anyone know how to get zipfile to zip the links?

like image 302
Larry Martell Avatar asked Mar 03 '16 21:03

Larry Martell


1 Answers

It is possible to have zipfile store symbolic links, instead of the files themselves. For an example, see here. The relevant part of the script is storing the symbolic link attribute within the zipinfo:

zipInfo = zipfile.ZipInfo(archiveRoot)
zipInfo.create_system = 3
# long type of hex val of '0xA1ED0000L',
# say, symlink attr magic...
zipInfo.external_attr = 2716663808L
zipOut.writestr(zipInfo, os.readlink(fullPath))
like image 116
MuertoExcobito Avatar answered Nov 01 '22 08:11

MuertoExcobito