From 6dfc870cffcfa7ca29e30301fff256e4e5b181f3 Mon Sep 17 00:00:00 2001 From: Daniele Esposti Date: Wed, 14 Sep 2016 10:23:34 +0100 Subject: No need to create the lock file beforehand --- git/util.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/git/util.py b/git/util.py index fff8ddc0..8d97242c 100644 --- a/git/util.py +++ b/git/util.py @@ -564,20 +564,14 @@ class LockFile(object): lock_file = self._lock_file_path() - # Create lock file + # Create file and lock try: - open(lock_file, 'a').close() - except OSError as e: - # Silence error only if file exists - if e.errno != 17: # 17 -> File exists - raise - - try: - fd = os.open(lock_file, os.O_WRONLY, 0) - flock(fd, LOCK_EX | LOCK_NB) + fd = os.open(lock_file, os.O_CREAT, 0) except OSError as e: raise IOError(str(e)) + flock(fd, LOCK_EX | LOCK_NB) + self._file_descriptor = fd self._owns_lock = True -- cgit v1.2.1