Browse Source

In threaded programs, more than one thread can try to add the same object at
the same time and this can cause os.mkdir to fail.

Bruce Duncan 15 years ago
parent
commit
b4a7c9ee38
1 changed files with 4 additions and 1 deletions
  1. 4 1
      dulwich/object_store.py

+ 4 - 1
dulwich/object_store.py

@@ -470,8 +470,11 @@ class DiskObjectStore(PackBasedObjectStore):
         :param obj: Object to add
         :param obj: Object to add
         """
         """
         dir = os.path.join(self.path, obj.id[:2])
         dir = os.path.join(self.path, obj.id[:2])
-        if not os.path.isdir(dir):
+        try:
             os.mkdir(dir)
             os.mkdir(dir)
+        except OSError, e:
+            if e.errno != errno.EEXIST:
+                raise
         path = os.path.join(dir, obj.id[2:])
         path = os.path.join(dir, obj.id[2:])
         if os.path.exists(path):
         if os.path.exists(path):
             return # Already there, no need to write again
             return # Already there, no need to write again