Skip to content

Commit a9aa894

Browse files
authored
Merge pull request #320 from andrewdnolan/toggle-recursive-perm-updates
Make recurisve permission updates optional
2 parents 1879a46 + 5027ff5 commit a9aa894

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mache/permissions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def update_permissions( # noqa: C901
1414
group_writable=False,
1515
other_readable=True,
1616
workers=4,
17+
recursive=True,
1718
):
1819
"""
1920
Update the group that a directory belongs to along with the "group" and
@@ -39,6 +40,9 @@ def update_permissions( # noqa: C901
3940
4041
workers : int, optional
4142
Number of threads to parallelize across
43+
44+
recursive : bool, optional
45+
Whether to traverse the path(s) provided recursively
4246
"""
4347

4448
if isinstance(base_paths, str):
@@ -68,7 +72,7 @@ def update_permissions( # noqa: C901
6872
mask = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO
6973

7074
for path in paths:
71-
print(f'Updating file permissions for: {path}')
75+
print(f'Updating file permissions (recursively) for: {path}')
7276

7377
# start by updating the top level path (file or directory)
7478
_update(
@@ -83,6 +87,9 @@ def update_permissions( # noqa: C901
8387
# iterate over the path recursively, only if it's a direcotry
8488
if path.is_file():
8589
continue
90+
# only iterate directories recursively if requested
91+
elif not recursive:
92+
continue
8693

8794
paths_iter = (p for p in Path(path).rglob('*'))
8895
n_files = sum(1 for _ in Path(path).rglob('*'))

0 commit comments

Comments
 (0)