From 8c48015e70479afcaf71944f48a366e99b346ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Sat, 17 Oct 2015 21:59:51 -0400 Subject: [PATCH] try to work around Windows idiocy of open files apparently, we may be able to rewrite an open file if we rename it first. i have no way to test this, unfortunately --- borg/upgrader.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/borg/upgrader.py b/borg/upgrader.py index 8503c0ea8..6f82e5c6b 100644 --- a/borg/upgrader.py +++ b/borg/upgrader.py @@ -91,10 +91,14 @@ class AtticRepositoryUpgrader(Repository): # works because our old file handle is still open # so even though the file is removed, we can still # read it until the file is closed. - os.unlink(filename) + os.rename(filename, filename + '.tmp') with open(filename, 'wb') as new_segment: new_segment.write(new_magic) new_segment.write(segment.read()) + # the little dance with the .tmp file is necessary + # because Windows won't allow overwriting an open + # file. + os.unlink(filename + '.tmp') def find_attic_keyfile(self): """find the attic keyfiles