lib.util.copy(): Require recursive for directories #169
2 changed files with 19 additions and 1 deletions
|
|
@ -259,7 +259,13 @@ async def copy(
|
|||
ret += '/' + basename
|
||||
src_root = '' if ctx.src.chroot else ctx.src.root
|
||||
s_st = await ctx.src.stat(src_root)
|
||||
if recursive and s_st.is_dir and not s_st.is_gettable:
|
||||
if s_st.is_dir and not s_st.is_gettable:
|
||||
# -- A directory is not a single fetchable object,
|
||||
# and cp copies directories only with -r
|
||||
if not recursive:
|
||||
raise Exception(
|
||||
f'Copying directory "{src}" requires recursive=True'
|
||||
)
|
||||
return await __copy_tree(src_root, ret)
|
||||
|
||||
result = await ctx.src.get(src_root, throw = True)
|
||||
|
|
|
|||
|
|
@ -174,6 +174,18 @@ async def run_tests() -> None:
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
# -- A directory without recursive fails with a clear error,
|
||||
# for a plain context and for a kvfile store alike
|
||||
for src in [
|
||||
uri(os.path.join(tmp, 'src/a')),
|
||||
f'kvfile:///{tmp}/src/a',
|
||||
]:
|
||||
try:
|
||||
await copy(src, uri(os.path.join(tmp, 'dst/dir-copy')))
|
||||
raise AssertionError('expected an exception')
|
||||
except Exception as e:
|
||||
assert 'recursive' in str(e), e
|
||||
|
||||
def main() -> None:
|
||||
asyncio.run(run_tests())
|
||||
print('All util copy tests passed')
|
||||
|
|
|
|||
Loading…
Reference in a new issue