diff options
-rw-r--r-- | git/util.py | 14 |
1 files 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 |