Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6dfc870

Browse files
committed
No need to create the lock file beforehand
1 parent 547e6f0 commit 6dfc870

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

git/util.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -564,20 +564,14 @@ def _obtain_lock_or_raise(self):
564564

565565
lock_file = self._lock_file_path()
566566

567-
# Create lock file
567+
# Create file and lock
568568
try:
569-
open(lock_file, 'a').close()
570-
except OSError as e:
571-
# Silence error only if file exists
572-
if e.errno != 17: # 17 -> File exists
573-
raise
574-
575-
try:
576-
fd = os.open(lock_file, os.O_WRONLY, 0)
577-
flock(fd, LOCK_EX | LOCK_NB)
569+
fd = os.open(lock_file, os.O_CREAT, 0)
578570
except OSError as e:
579571
raise IOError(str(e))
580572

573+
flock(fd, LOCK_EX | LOCK_NB)
574+
581575
self._file_descriptor = fd
582576
self._owns_lock = True
583577

0 commit comments

Comments
 (0)