File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,7 @@ class UnixFileLock(BaseFileLock):
38
38
39
39
def _acquire (self ) -> None :
40
40
ensure_directory_exists (self .lock_file )
41
- open_flags = os .O_RDWR | os .O_TRUNC
42
- if not Path (self .lock_file ).exists ():
43
- open_flags |= os .O_CREAT
41
+ open_flags = os .O_RDWR | os .O_TRUNC | os .O_CREAT
44
42
fd = os .open (self .lock_file , open_flags , self ._context .mode )
45
43
with suppress (PermissionError ): # This locked is not owned by this UID
46
44
os .fchmod (fd , self ._context .mode )
Original file line number Diff line number Diff line change @@ -814,3 +814,12 @@ def __init__(self, file_path: str) -> None:
814
814
lock_path = tmp_path / "a"
815
815
lock = FilePathLock (str (lock_path ))
816
816
assert lock .lock_file == str (lock_path ) + ".lock"
817
+
818
+
819
+ @pytest .mark .parametrize ("lock_type" , [FileLock , SoftFileLock ])
820
+ def test_lock_is_removed (tmp_path : Path , lock_type : type [BaseFileLock ]) -> None :
821
+ lock_path = tmp_path / "test.lock"
822
+ lock = lock_type (lock_path )
823
+ with lock :
824
+ assert Path .exists (lock_path )
825
+ assert not Path .exists (lock_path )
You can’t perform that action at this time.
0 commit comments