From 0ff89fd85f99d1989c00e02897e56c809437fa5a Mon Sep 17 00:00:00 2001 From: glrs <5999366+glrs@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:43:50 +0100 Subject: [PATCH] Fix rsync command to account for non-existed parent folders in destination --- lib/module_utils/report_transfer.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/module_utils/report_transfer.py b/lib/module_utils/report_transfer.py index 71a974a..6f50dd7 100644 --- a/lib/module_utils/report_transfer.py +++ b/lib/module_utils/report_transfer.py @@ -23,20 +23,26 @@ def transfer_report( logging.warning("Report transfer will not be attempted. Handle manually...") return False + # Build the remote directory path + remote_dir = f"{destination_path}/{project_id}" if sample_id: - remote_path = f"{user}@{server}:{destination_path}/{project_id}/{sample_id}/" - else: - remote_path = f"{user}@{server}:{destination_path}/{project_id}/" + remote_dir = f"{remote_dir}/{sample_id}" + + remote_path = f"{user}@{server}:{remote_dir}/" rsync_command = [ "rsync", "-avz", + "--rsync-path", + f"mkdir -p '{remote_dir}' && rsync", "-e", f"ssh -i {ssh_key}" if ssh_key else "ssh", str(report_path), remote_path, ] + logging.debug(f"RSYNC command: {' '.join(rsync_command)}") + try: # Execute the rsync command result = subprocess.run(