From e1a4dadc2f8d966d692118ecd84a55933d4a85d7 Mon Sep 17 00:00:00 2001 From: Kieran O'Leary Date: Thu, 14 Aug 2025 10:56:54 +0100 Subject: [PATCH] Adds retry when failing to rename tmp folder to data --- bagit.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bagit.py b/bagit.py index c9c1737..eab85d3 100755 --- a/bagit.py +++ b/bagit.py @@ -12,6 +12,7 @@ import signal import sys import tempfile +import time import unicodedata import warnings from collections import defaultdict @@ -229,7 +230,16 @@ def make_bag( _("Moving %(source)s to %(destination)s"), {"source": temp_data, "destination": "data"}, ) - os.rename(temp_data, "data") + while True: + try: + os.rename(temp_data, "data") + break + except PermissionError as e: + if hasattr(e, "winerror") and e.winerror == 5: + LOGGER.warning(_("PermissionError [WinError 5] when renaming temp folder. Retrying in 10 seconds...")) + time.sleep(10) + else: + raise # permissions for the payload directory should match those of the # original directory