Skip to content

Commit

Permalink
Merge pull request #326 from AlbertDeFusco/zip-file-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertDeFusco committed Jul 3, 2021
2 parents 3394ac6 + 1d4db03 commit a35a2f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion anaconda_project/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ def _extractall_chmod(zf, destination):
for zinfo in zf.infolist():
out_path = zf.extract(zinfo.filename, path=destination)
mode = zinfo.external_attr >> 16
os.chmod(out_path, mode)
if not (mode == 0):
os.chmod(out_path, mode)


def _extract_files_zip(zip_path, src_and_dest, frontend):
Expand Down
34 changes: 33 additions & 1 deletion anaconda_project/test/test_project_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4828,7 +4828,7 @@ def check(dirname):
_CONTENTS_SYMLINK = 3


def _make_zip(archive_dest_dir, contents):
def _make_zip(archive_dest_dir, contents, mode_zero=False):
archivefile = os.path.join(archive_dest_dir, "foo.zip")
with zipfile.ZipFile(archivefile, 'w') as zf:
for (key, what) in contents.items():
Expand All @@ -4838,6 +4838,10 @@ def _make_zip(archive_dest_dir, contents):
key = key + os.sep
zf.writestr(key, "")
elif what is _CONTENTS_FILE:
if mode_zero:
info = zipfile.ZipInfo(key)
info.external_attr = 16
zf.writestr(info, "hello")
zf.writestr(key, "hello")
else:
raise AssertionError("can't put this in a zip")
Expand Down Expand Up @@ -4952,6 +4956,34 @@ def check(dirname):
with_directory_contents(dict(), archivetest)


def test_unarchive_zip_mode_zero():
def archivetest(archive_dest_dir):
archivefile = _make_zip(archive_dest_dir, {
'a/a.txt': _CONTENTS_FILE,
'a/q/b.txt': _CONTENTS_FILE,
'a/c': _CONTENTS_DIR,
'a': _CONTENTS_DIR
},
mode_zero=True)

# with zipfile.ZipFile(archivefile, 'r') as zf:
# print(repr(zf.namelist()))

def check(dirname):
unpacked = os.path.join(dirname, "foo")
status = project_ops.unarchive(archivefile, unpacked)

assert status.errors == []
assert status
assert os.path.isdir(unpacked)
_assert_dir_contains(unpacked, ['a.txt', 'c', 'q/b.txt'])
assert status.project_dir == unpacked

with_directory_contents(dict(), check)

with_directory_contents(dict(), archivetest)


def test_unarchive_zip_to_current_directory():
def archivetest(archive_dest_dir):
archivefile = _make_zip(archive_dest_dir, {
Expand Down

0 comments on commit a35a2f2

Please sign in to comment.