Skip to content

Commit 60f7f94

Browse files
committed
Fix mkdir race condition in LooseObjectDB.store
This replaces the conditional call to os.mkdir that raises an unintended FileExistsError if the directory is created between the check and the os.mkdir call, using a single os.makedirs call instead, with exist_ok=True. This way, we attempt creation in a way that produces no error if the directory is already present, while still raising FileExistsError if a non-directory filesystem entry (such as a regular file) is present where we want the directory to be.
1 parent d22ac20 commit 60f7f94

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Diff for: gitdb/db/loose.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
ObjectDBW
99
)
1010

11-
1211
from gitdb.exc import (
1312
BadObject,
1413
AmbiguousObjectName
@@ -33,10 +32,8 @@
3332
bin_to_hex,
3433
exists,
3534
chmod,
36-
isdir,
3735
isfile,
3836
remove,
39-
mkdir,
4037
rename,
4138
dirname,
4239
basename,
@@ -222,8 +219,7 @@ def store(self, istream):
222219
if tmp_path:
223220
obj_path = self.db_path(self.object_path(hexsha))
224221
obj_dir = dirname(obj_path)
225-
if not isdir(obj_dir):
226-
mkdir(obj_dir)
222+
os.makedirs(obj_dir, exist_ok=True)
227223
# END handle destination directory
228224
# rename onto existing doesn't work on NTFS
229225
if isfile(obj_path):

0 commit comments

Comments
 (0)