From 0cb90d4cebcb2a5c32166bc34e350100019f13cf Mon Sep 17 00:00:00 2001 From: Thomas Ziegler Date: Mon, 8 Jul 2024 08:49:03 +0200 Subject: [PATCH 1/2] uses shutil.move instead of copy and unlink --- barman/clients/walrestore.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/barman/clients/walrestore.py b/barman/clients/walrestore.py index afc93c9c0..ebc23d464 100755 --- a/barman/clients/walrestore.py +++ b/barman/clients/walrestore.py @@ -31,6 +31,7 @@ import subprocess import sys import time +from pathlib import Path import barman from barman.utils import force_str @@ -243,15 +244,14 @@ def try_deliver_from_spool(config, dest_file): :param argparse.Namespace config: the configuration from command line :param dest_file: The destination file object """ - spool_file = os.path.join(config.spool_dir, config.wal_name) + spool_file = Path(config.spool_dir, config.wal_name) # id the file is not present, give up - if not os.path.exists(spool_file): + if not spool_file.exists(): return try: - shutil.copyfileobj(open(spool_file, "rb"), dest_file) - os.unlink(spool_file) + shutil.move(spool_file, dest_file) sys.exit(0) except IOError as e: exit_with_error( From 0150c432581317265438d17c8e428e2799356a1f Mon Sep 17 00:00:00 2001 From: Thomas Ziegler Date: Mon, 8 Jul 2024 12:44:36 +0200 Subject: [PATCH 2/2] removes Pathlib, fixes typing issues --- barman/clients/walrestore.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/barman/clients/walrestore.py b/barman/clients/walrestore.py index ebc23d464..97fa3a7b5 100755 --- a/barman/clients/walrestore.py +++ b/barman/clients/walrestore.py @@ -31,7 +31,6 @@ import subprocess import sys import time -from pathlib import Path import barman from barman.utils import force_str @@ -75,7 +74,7 @@ def main(args=None): return # never reached # If the file is present in SPOOL_DIR use it and terminate - try_deliver_from_spool(config, dest_file) + try_deliver_from_spool(config, dest_file.name) # If required load the list of files to download in parallel additional_files = peek_additional_files(config) @@ -242,12 +241,12 @@ def try_deliver_from_spool(config, dest_file): return otherwise. :param argparse.Namespace config: the configuration from command line - :param dest_file: The destination file object + :param dest_file: The path to the destination file """ - spool_file = Path(config.spool_dir, config.wal_name) + spool_file = str(os.path.join(config.spool_dir, config.wal_name)) # id the file is not present, give up - if not spool_file.exists(): + if not os.path.exists(spool_file): return try: @@ -255,7 +254,7 @@ def try_deliver_from_spool(config, dest_file): sys.exit(0) except IOError as e: exit_with_error( - "Failure copying %s to %s: %s" % (spool_file, dest_file.name, e) + "Failure moving %s to %s: %s" % (spool_file, dest_file, e) )