Skip to content

Commit

Permalink
Merge pull request #17350 from natefoo/posix-filesource-part
Browse files Browse the repository at this point in the history
[23.2] Write to a temp filename in posix file source plugin
  • Loading branch information
natefoo authored Jan 25, 2024
2 parents c078220 + add8b28 commit 34508cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/galaxy/files/sources/posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,18 @@ def _write_from(
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)
Expand Down

0 comments on commit 34508cd

Please sign in to comment.