Skip to content

Commit 7498a5e

Browse files
kieranjolacdha
authored andcommitted
Adds retry when failing to rename tmp folder to data
1 parent 861ddac commit 7498a5e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bagit.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import signal
1313
import sys
1414
import tempfile
15+
import time
1516
import unicodedata
1617
import warnings
1718
from collections import defaultdict
@@ -229,7 +230,16 @@ def make_bag(
229230
_("Moving %(source)s to %(destination)s"),
230231
{"source": temp_data, "destination": "data"},
231232
)
232-
os.rename(temp_data, "data")
233+
while True:
234+
try:
235+
os.rename(temp_data, "data")
236+
break
237+
except PermissionError as e:
238+
if hasattr(e, "winerror") and e.winerror == 5:
239+
LOGGER.warning(_("PermissionError [WinError 5] when renaming temp folder. Retrying in 10 seconds..."))
240+
time.sleep(10)
241+
else:
242+
raise
233243

234244
# permissions for the payload directory should match those of the
235245
# original directory

0 commit comments

Comments
 (0)