From 6f500dc81b547102376584eb0de012a4a5f97d20 Mon Sep 17 00:00:00 2001 From: Yan Cheng <58191769+yanchengnv@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:52:44 -0400 Subject: [PATCH] fix clone to keep original (#2755) --- .../app_common/storages/filesystem_storage.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nvflare/app_common/storages/filesystem_storage.py b/nvflare/app_common/storages/filesystem_storage.py index b1d5547a0f..bfa82654f0 100644 --- a/nvflare/app_common/storages/filesystem_storage.py +++ b/nvflare/app_common/storages/filesystem_storage.py @@ -29,6 +29,20 @@ def _write(path: str, content, mv_file=True): + """Create a file at the specified 'path' with the specified 'content'. + + Args: + path: the path of the file to be created + content: content for the file to be created. It could be either bytes, or path (str) to the source file that + contains the content. + mv_file: whether the destination file should be created simply by moving the source file. This is applicable + only when the 'content' is the path of the source file. If mv_file is False, the destination is created + by copying from the source file, and the source file will remain intact; If mv_file is True, the + destination file is created by "move" the source file, and the original source file will no longer exist. + + Returns: + + """ tmp_path = path + "_" + str(uuid.uuid4()) try: Path(os.path.dirname(path)).mkdir(parents=True, exist_ok=True) @@ -162,7 +176,7 @@ def clone_object(self, from_uri: str, to_uri: str, meta: dict, overwrite_existin from_full_uri = self._object_path(from_uri) from_data_path = os.path.join(from_full_uri, DATA) - _write(data_path, from_data_path) + _write(data_path, from_data_path, mv_file=False) meta_path = os.path.join(full_uri, META) try: