Skip to content

Commit

Permalink
changed from os.umask to os.chmod (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jahrules and pre-commit-ci[bot] authored Mar 22, 2023
1 parent 0b10287 commit d7e1e84
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
=========
v3.10.2 (2023-03-22)
--------------------
- Bug fix for using filelock with threaded programs causing undesired file permissions - by :user:`jahrules`.

v3.10.1 (2023-03-22)
--------------------
- Handle pickle for :class:`filelock.Timeout` :pr:`203` - by :user:`TheMatt2`.
Expand Down
6 changes: 1 addition & 5 deletions src/filelock/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ def acquire(
with self._thread_lock:
if not self.is_locked:
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
previous_umask = os.umask(0)
try:
self._acquire()
finally:
os.umask(previous_umask) # reset umask to initial value
self._acquire()
if self.is_locked:
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
break
Expand Down
3 changes: 2 additions & 1 deletion src/filelock/_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class UnixFileLock(BaseFileLock):

def _acquire(self) -> None:
open_flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC
fd = os.open(self._lock_file, open_flags, self._mode)
fd = os.open(self._lock_file, open_flags)
os.chmod(fd, self._mode)
try:
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_filelock.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def test_lock_mode_soft(tmp_path: Path) -> None:
assert lock.is_locked

mode = filemode(os.stat(lock_path).st_mode)
assert mode == "-rw-rw-rw-"
if sys.platform == "win32":
assert mode == "-rw-rw-rw-"
else:
assert mode == "-rw-r--r--"

lock.release()

Expand Down

0 comments on commit d7e1e84

Please sign in to comment.