-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File permission on zip member reported incorrectly #1
Comments
I was able to replicate this issue as well. If you are interested in specifying permissions yourself, here's how you can do it: Here is a snippet of our usage: # 664 permissions
FILE_PERMISSION_664 = stat.S_IFREG | 0 | 0 | 0 | (stat.S_IRUSR | stat.S_IWUSR) | \
(stat.S_IRGRP | stat.S_IWGRP) | stat.S_IROTH
class PermissiveZipEntry(ZipEntry):
"""
A type of ZipEntry that sets files added to zip files to 664.
"""
@classmethod
def from_archive(cls, archive, encoding=ENCODING):
"""
Instantiates an Entry class and sets all the properties from an
archive header.
"""
e = _libarchive.archive_entry_new()
try:
call_and_check(_libarchive.archive_read_next_header2, archive._a,
archive._a, e)
mode = _libarchive.archive_entry_filetype(e)
mode |= _libarchive.archive_entry_perm(e)
entry = cls(
pathname=_libarchive.archive_entry_pathname(e).decode(encoding),
size=_libarchive.archive_entry_size(e),
mtime=_libarchive.archive_entry_mtime(e),
mode=FILE_PERMISSION_664,
hpos=archive.header_position,
)
finally:
_libarchive.archive_entry_free(e)
return entry
@classmethod
def from_file(cls, f, entry=None, encoding=ENCODING):
"""
Instantiates an Entry class and sets all the properties from a file on
the file system. f can be a file-like object or a path.
"""
if entry is None:
entry = cls(encoding=encoding)
if entry.pathname is None:
if isinstance(f, basestring):
st = os.stat(f)
entry.pathname = f
entry.size = st.st_size
entry.mtime = st.st_mtime
elif hasattr(f, 'fileno'):
st = os.fstat(f.fileno())
entry.pathname = getattr(f, 'name', None)
entry.size = st.st_size
entry.mtime = st.st_mtime
else:
entry.pathname = getattr(f, 'pathname', None)
entry.size = getattr(f, 'size', 0)
entry.mtime = getattr(f, 'mtime', time.time())
entry.mode = FILE_PERMISSION
return entry
def to_archive(self, archive):
""" Creates an archive header and writes it to the given archive. """
e = _libarchive.archive_entry_new()
try:
_libarchive.archive_entry_set_pathname(e, self.pathname.encode(self.encoding))
_libarchive.archive_entry_set_filetype(e, stat.S_IFMT(self.mode))
_libarchive.archive_entry_set_perm(e, stat.S_IMODE(self.mode))
_libarchive.archive_entry_set_size(e, self.size)
_libarchive.archive_entry_set_mtime(e, self.mtime, 0)
call_and_check(_libarchive.archive_write_header, archive._a,
archive._a, e)
#self.hpos = archive.header_position
finally:
_libarchive.archive_entry_free(e)
def isdir(self):
return stat.S_ISDIR(self.mode)
def isfile(self):
return stat.S_ISREG(self.mode)
def issym(self):
return stat.S_ISLNK(self.mode)
def isfifo(self):
return stat.S_ISFIFO(self.mode)
def ischr(self):
return stat.S_ISCHR(self.mode)
def isblk(self):
return stat.S_ISBLK(self.mode)
# Create a ZipFile with file permissions of 664
f = open('/tmp/test.zip', 'w')
# Create a ZipFile with an entry class of PermissiveZipEntry
z = ZipFile(f, mode='w', entry_class=PermissiveZipEntry)
# write to the zip file here
z.close()
f.close() |
https://code.google.com/p/python-libarchive/issues/detail?id=6
Reported by [email protected], Jan 10, 2015
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Expected output is:
Output displayed is:
What version of the product are you using? On what operating system?
libarchive-3.1.2, python-libarchive-3.1.2-1
RHEL6
Please provide any additional information below.
The problem is most likely with libarchive/init.py. I wrote another python program, /tmp/t2.py, using the raw libarchive commands and it gave the expected output.
/tmp/t1.py
/tmp/t2.py
The text was updated successfully, but these errors were encountered: