From add8b28efac80cf3abf969c4d420815a215c4749 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Wed, 24 Jan 2024 13:52:32 -0500 Subject: [PATCH] Write to a temp filename in posix file source plugin --- lib/galaxy/files/sources/posix.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/files/sources/posix.py b/lib/galaxy/files/sources/posix.py index cb117e6bc53..a844cf68b55 100644 --- a/lib/galaxy/files/sources/posix.py +++ b/lib/galaxy/files/sources/posix.py @@ -105,14 +105,18 @@ class PosixFilesSource(BaseFilesSource): target_native_path = os.path.normpath(target_native_path) assert target_native_path.startswith(os.path.normpath(effective_root)) - target_native_path_parent = os.path.dirname(target_native_path) + target_native_path_parent, target_native_path_name = os.path.split(target_native_path) if not os.path.exists(target_native_path_parent): if self.allow_subdir_creation: os.makedirs(target_native_path_parent) else: raise Exception("Parent directory does not exist.") - shutil.copyfile(native_path, target_native_path) + # Use a temporary name while writing so anything that consumes written files can detect when they've completed, + # and identify interrupted writes + target_native_path_part = os.path.join(target_native_path_parent, f"_{target_native_path_name}.part") + shutil.copyfile(native_path, target_native_path_part) + os.rename(target_native_path_part, target_native_path) def _to_native_path(self, source_path: str, user_context=None): source_path = os.path.normpath(source_path)