Skip to content
Snippets Groups Projects
Commit 6012be54 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

tarball: Fix also directory permissions in normalize_permissions

It exist cases when an uncompressed tarball has directories without
any traversal or read permissions so ensure to also fix directory
permissions in normalize_permissions function.
parent be9403c6
No related branches found
Tags v0.5.3
No related merge requests found
......@@ -179,8 +179,11 @@ def normalize_permissions(path: str):
Args:
path: the path under which permissions should be normalized
"""
for dirpath, _, fnames in os.walk(path):
os.chmod(dirpath, 0o0755)
os.chmod(path, 0o0755)
for dirpath, dnames, fnames in os.walk(path):
for dname in dnames:
dpath = os.path.join(dirpath, dname)
os.chmod(dpath, 0o0755)
for fname in fnames:
fpath = os.path.join(dirpath, fname)
if not os.path.islink(fpath):
......
......@@ -6,6 +6,7 @@
import hashlib
import os
import shutil
import stat
import pytest
......@@ -186,16 +187,26 @@ def test_normalize_permissions(tmp_path):
file_path.touch()
file_path.chmod(perms)
# add directory without any permission
dir_path = tmp_path / "dir"
dir_path.mkdir(mode=stat.S_IFDIR)
for file in tmp_path.iterdir():
assert file.stat().st_mode == 0o100000 | int(file.name)
if file.is_dir():
assert file.stat().st_mode == stat.S_IFDIR
else:
assert file.stat().st_mode == 0o100000 | int(file.name)
tarball.normalize_permissions(str(tmp_path))
for file in tmp_path.iterdir():
if int(file.name) & 0o100: # original file was executable for its owner
assert file.stat().st_mode == 0o100755
if file.is_dir():
assert file.stat().st_mode == stat.S_IFDIR + 0o000755
else:
assert file.stat().st_mode == 0o100644
if int(file.name) & 0o100: # original file was executable for its owner
assert file.stat().st_mode == 0o100755
else:
assert file.stat().st_mode == 0o100644
def test_unpcompress_zip_imploded(tmp_path, datadir):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment