From d26595557260f6d646462907006573b3ced711c0 Mon Sep 17 00:00:00 2001 From: erlkonig <2512500960@qq.com> Date: Tue, 26 Dec 2023 20:20:50 -0800 Subject: [PATCH] modify cp action to support dir copy --- livefs_edit/actions.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/livefs_edit/actions.py b/livefs_edit/actions.py index 263ce2d..722c33f 100644 --- a/livefs_edit/actions.py +++ b/livefs_edit/actions.py @@ -173,8 +173,13 @@ def interpret_path(ctxt, path): @register_action() def cp(ctxt, source, dest): - os.makedirs(interpret_path(ctxt, os.path.dirname(dest)), exist_ok=True) - shutil.copy(interpret_path(ctxt, source), interpret_path(ctxt, dest)) + if os.path.isdir(interpret_path(ctxt, source)): + source_basename=os.path.basename(os.path.dirname(source)) + os.makedirs(interpret_path(ctxt, os.path.dirname(dest))+"/"+source_basename, exist_ok=True) + shutil.copytree(interpret_path(ctxt, source), interpret_path(ctxt, dest)+"/"+source_basename, dirs_exist_ok = True) + else: + os.makedirs(interpret_path(ctxt, os.path.dirname(dest)), exist_ok=True) + shutil.copy(interpret_path(ctxt, source), interpret_path(ctxt, dest)) @register_action()