Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31256bf

Browse files
committed
chgrp: Improve --preserve-root handling efficiency
1 parent de3d12c commit 31256bf

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

userland/utilities/chgrp.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
parser.add_option(
8989
"--from",
9090
dest="from_spec", # prevent name collision with the `from` keyword
91-
metavar="[CURRENT_OWNER][:CURRENT_GROUP]",
91+
metavar="[CURRENT_OWNER][:[CURRENT_GROUP]]",
9292
help="only affect files with CURRENT_OWNER and CURRENT_GROUP"
9393
" (either is optional and only checked if given)",
9494
)
@@ -226,16 +226,6 @@ def chown(file: Path) -> None:
226226
if opts.recursive:
227227

228228
def traverse(file: Path) -> None:
229-
nonlocal failed
230-
231-
if opts.preserve_root and file.root == str(file):
232-
print(
233-
f"recursive operation on '{file}' prevented; use --no-preserve-root to override",
234-
file=sys.stderr,
235-
)
236-
failed = True
237-
return
238-
239229
for child in file.iterdir():
240230
if child.is_dir(follow_symlinks=opts.recurse_mode == "L"):
241231
traverse(child)
@@ -245,6 +235,15 @@ def traverse(file: Path) -> None:
245235
if file.is_dir(
246236
follow_symlinks=opts.recurse_mode == "H" or opts.recurse_mode == "L"
247237
):
238+
if opts.preserve_root and file.root == str(file):
239+
failed = True
240+
print(
241+
f"recursive operation on '{file}' prevented;"
242+
" use --no-preserve-root to override",
243+
file=sys.stderr,
244+
)
245+
continue
246+
248247
traverse(file)
249248
else:
250249
chown(file)

0 commit comments

Comments
 (0)