Skip to content

Commit d7e1e84

Browse files
changed from os.umask to os.chmod (#206)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0b10287 commit d7e1e84

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

docs/changelog.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Changelog
22
=========
3+
v3.10.2 (2023-03-22)
4+
--------------------
5+
- Bug fix for using filelock with threaded programs causing undesired file permissions - by :user:`jahrules`.
6+
37
v3.10.1 (2023-03-22)
48
--------------------
59
- Handle pickle for :class:`filelock.Timeout` :pr:`203` - by :user:`TheMatt2`.

src/filelock/_api.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ def acquire(
179179
with self._thread_lock:
180180
if not self.is_locked:
181181
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
182-
previous_umask = os.umask(0)
183-
try:
184-
self._acquire()
185-
finally:
186-
os.umask(previous_umask) # reset umask to initial value
182+
self._acquire()
187183
if self.is_locked:
188184
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
189185
break

src/filelock/_unix.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class UnixFileLock(BaseFileLock):
3232

3333
def _acquire(self) -> None:
3434
open_flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC
35-
fd = os.open(self._lock_file, open_flags, self._mode)
35+
fd = os.open(self._lock_file, open_flags)
36+
os.chmod(fd, self._mode)
3637
try:
3738
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
3839
except OSError:

tests/test_filelock.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ def test_lock_mode_soft(tmp_path: Path) -> None:
440440
assert lock.is_locked
441441

442442
mode = filemode(os.stat(lock_path).st_mode)
443-
assert mode == "-rw-rw-rw-"
443+
if sys.platform == "win32":
444+
assert mode == "-rw-rw-rw-"
445+
else:
446+
assert mode == "-rw-r--r--"
444447

445448
lock.release()
446449

0 commit comments

Comments
 (0)