Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed from os.umask to os.chmod #206

Merged
merged 8 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions src/filelock/_soft.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def _acquire(self) -> None:
)
try:
fd = os.open(self._lock_file, flags, self._mode)
os.chmod(fd, self._mode)
except OSError as exception:
if exception.errno == EEXIST: # expected if cannot lock
pass
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
3 changes: 2 additions & 1 deletion src/filelock/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def _acquire(self) -> None:
| os.O_TRUNC # truncate file if not empty
)
try:
fd = os.open(self._lock_file, flags, self._mode)
fd = os.open(self._lock_file, flags)
os.chmod(fd, self._mode)
except OSError as exception:
if exception.errno == ENOENT: # No such file or directory
raise
Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ autosectionlabel
caplog
eacces
extlinks
fchmod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

filelock
filemode
frameinfo
Expand Down