Browse Source

On Windows, os.rename will thrown WindowsError if the destination already exists. Fixes #448

Akbar Gumbira 8 years ago
parent
commit
4fc96f1179
1 changed files with 5 additions and 1 deletions
  1. 5 1
      dulwich/object_store.py

+ 5 - 1
dulwich/object_store.py

@@ -567,7 +567,11 @@ class DiskObjectStore(PackBasedObjectStore):
         # Move the pack in.
         entries.sort()
         pack_base_name = self._get_pack_basepath(entries)
-        os.rename(path, pack_base_name + '.pack')
+        try:
+            os.rename(path, pack_base_name + '.pack')
+        except WindowsError:
+            os.remove(pack_base_name + '.pack')
+            os.rename(path, pack_base_name + '.pack')
 
         # Write the index.
         index_file = GitFile(pack_base_name + '.idx', 'wb')