Skip to content

Commit

Permalink
ENH Better error detection for permission problems
Browse files Browse the repository at this point in the history
Previously, if a lock could not be created due to missing permissions
(or other issues), jug would treat this identically to failing to lock
because a lock already existed.

Now, it specifically looks for FileExistsError (introduced in Python
3.3) to detect a locked version
  • Loading branch information
luispedro committed May 15, 2024
1 parent b6c7a23 commit 0e155f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
* Tasklet: Support for lambda functions in Tasklets
* pack: bugfix when using local imports
* jug: better error detection for permission problems

Version 2.3.1 Sun 5 November 2023 by luispedro
* jug: update for Python 3.12
Expand Down
2 changes: 1 addition & 1 deletion jug/backends/file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def get(self):
F.write('Lock created on {0}\n'.format(datetime.now().strftime('%Y-%m-%d (%Hh%M.%S)')))
F.close()
return True
except OSError:
except FileExistsError:
return False

def release(self):
Expand Down
15 changes: 15 additions & 0 deletions jug/tests/test_file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from jug.backends.file_store import file_store
from jug.hash import hash_one

import pytest
import os
from io import BytesIO

def test_encode_decode_empty_string():
Expand Down Expand Up @@ -84,3 +86,16 @@ def test_pack_cleanup(tmpdir):

fs = file_store(tmpdir)
assert len(list(fs.list())) == 2


def test_lock_permissions(tmpdir):
tmpdir = str(tmpdir)
os.makedirs(tmpdir, exist_ok=True)
fs = file_store(tmpdir)
lock = fs.getlock(hash_one('k0'))
assert lock.get()
lock.release()
os.chmod(tmpdir + '/locks', 0o444)
with pytest.raises(PermissionError):
lock.get()

0 comments on commit 0e155f1

Please sign in to comment.