lib.util.copy(): Move closure __copy_tree() to top
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m33s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m57s
CI / Packaging test (pull_request) Successful in 0s

__copy_tree() is a closure inside copy(), and per janware coding
conventions, closures should be defined at the top of a function with
preceding code, so move it to the top of copy().

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-11-01 08:17:55 +01:00
commit 159c72e63b
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -179,22 +179,6 @@ async def copy(
parents: bool = False,
) -> Exception | str | list[str]:
# Destination address / addresses
ret: str | list[str]
if not isinstance(src, (str, FileContext)):
ret = []
for uri in src: # TODO: Group identical netlocs into one CopyContext
rr = await copy(uri, dst, owner, group, mode, throw, recursive, parents)
if isinstance(rr, Exception):
return rr
if isinstance(rr, list):
ret.extend(rr)
if isinstance(rr, str):
ret.append(rr)
else:
raise Exception(f'copy() returned unexpected type {type(rr)}')
return ret
async def __copy_tree(src_path: str, dst_path: str) -> list[str]:
ret: list[str] = []
s_st = await ctx.src.stat(src_path)
@ -222,6 +206,22 @@ async def copy(
ret.append(d_path)
return ret
# Destination address / addresses
ret: str | list[str]
if not isinstance(src, (str, FileContext)):
ret = []
for uri in src: # TODO: Group identical netlocs into one CopyContext
rr = await copy(uri, dst, owner, group, mode, throw, recursive, parents)
if isinstance(rr, Exception):
return rr
if isinstance(rr, list):
ret.extend(rr)
if isinstance(rr, str):
ret.append(rr)
else:
raise Exception(f'copy() returned unexpected type {type(rr)}')
return ret
try:
from .CopyContext import CopyContext