lib.util.copy(): Accept a FileContext as source
Using a FileContext, notably with its chroot flag set, is useful as a tree source in copy(), so allow it. Signed-off-by: Jan Lindemann <jan@janware.com> Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.1.0
This commit is contained in:
parent
ca04128a37
commit
482daa17e7
1 changed files with 32 additions and 7 deletions
|
|
@ -3,6 +3,7 @@ import os
|
|||
import stat
|
||||
import tempfile
|
||||
|
||||
from jw.pkg.lib.ec.Local import Local
|
||||
from jw.pkg.lib.util import copy
|
||||
|
||||
def uri(path: str) -> str:
|
||||
|
|
@ -99,6 +100,29 @@ async def run_tests() -> None:
|
|||
st = os.stat(os.path.join(dst_mode, 'sub/subsub/f3'))
|
||||
assert stat.S_IMODE(st.st_mode) == 0o640, st
|
||||
|
||||
# -- A chrooted context source: the empty address is the
|
||||
# context's root, and landing into an existing directory
|
||||
# takes the root's basename
|
||||
os.makedirs(os.path.join(tmp, 'dst/chroot'))
|
||||
src_fc = Local(uri(os.path.join(tmp, 'src/a')), chroot = True)
|
||||
ret = await copy(src_fc, uri(os.path.join(tmp, 'dst/chroot')), recursive = True)
|
||||
assert os.path.isfile(os.path.join(tmp, 'dst/chroot/a/f1')), ret
|
||||
assert os.path.isfile(os.path.join(tmp, 'dst/chroot/a/sub/f2')), ret
|
||||
|
||||
# -- A trailing slash does not change the source's name
|
||||
os.makedirs(os.path.join(tmp, 'dst/slash'))
|
||||
ret = await copy(
|
||||
uri(os.path.join(tmp, 'src/a/')),
|
||||
uri(os.path.join(tmp, 'dst/slash')),
|
||||
recursive = True,
|
||||
)
|
||||
assert isinstance(ret, list), ret
|
||||
assert os.path.join(tmp, 'dst/slash/a/f1') in ret, ret
|
||||
src_fc = Local(uri(os.path.join(tmp, 'src/a/')), chroot = True)
|
||||
ret = await copy(src_fc, uri(os.path.join(tmp, 'dst/slash')), recursive = True)
|
||||
assert isinstance(ret, list), ret
|
||||
assert os.path.join(tmp, 'dst/slash/a/f1') in ret, ret
|
||||
|
||||
# -- A missing source fails loudly
|
||||
try:
|
||||
await copy(
|
||||
|
|
|
|||
Loading…
Reference in a new issue