Open miurahr opened 5 years ago
Here is a use case; https://github.com/miurahr/aqtinstall/blob/topic-pylzma04/aqt/installer.py
FILE_ATTRIBUTE_READONLY = 0x01
FILE_ATTRIBUTE_HIDDEN = 0x02
FILE_ATTRIBUTE_SYSTEM = 0x04
FILE_ATTRIBUTE_DIRECTORY = 0x10
FILE_ATTRIBUTE_ARCHIVE = 0x20
FILE_ATTRIBUTE_NORMAL = 0x80
FILE_ATTRIBUTE_TEMPORARY = 0x0100
def _set_file_property(target_f, outfilename):
if os.name == 'posix':
st_mode = target_f.get_mode()
if st_mode is not None:
os.chmod(outfilename, st_mode)
elif os.name == 'nt':
if target_f.is_hidden():
win32api.SetFileAttributes(outfilename, FILE_ATTRIBUTE_HIDDEN)
if target_f.is_readonly():
win32api.SetFileAttributes(outfilename, FILE_ATTRIBUTE_READONLY)
if target_f.is_system_file():
win32api.SetFileAttributes(outfilename, FILE_ATTRIBUTE_SYSTEM)
It is redundant in Windows code, so it is better to introduce get_file_attribute()
method to grab all bits like st_mode.
It also should support symbolic link.
There is a stat
module in python which handle file modes and formats, we can help user to use stat.ISLINK(mode)
to check archive file formats.
It is better that py7zlib have an API to retrieve file modes. I've been working for it and PR soon.
And I'd like to propose supporting Unix file mode (rwx) p7zip on UNIX has an attribute trick to store a file mode, when FILE_ATTRIBUTE_UNIX_EXTENSION bit is set, then store a mode in high 16bit.
https://github.com/warexify/p7zip/blob/master/CPP/7zip/Archive/7z/7zUpdate.cpp#L882
Here is a proposal of API design.
There are some design issue that how it should be in Windows platform. A question is whether it checks unix attribute extension only on Unix/Linux/Mac, or always checks it on any platform.