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

Fixed lockfile check when using a Docker read-only filesystem #3832

Merged
merged 6 commits into from
Oct 26, 2022
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package/MDAnalysis/coordinates/XDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _load_offsets(self):
try:
with fasteners.InterProcessLock(lock_name) as filelock:
pass
except PermissionError:
except (PermissionError, OSError):
Copy link
Member

Choose a reason for hiding this comment

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

A reproducer for the original handled PermissionError is straightforward, like below, I wonder if we could cook something up for the other error? May not be worth much energy though.

--- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py
+++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py
@@ -904,3 +904,14 @@ class TestTRRReader_offsets(_GromacsReader_offsets):
         9155712, 10300176
     ])
     _reader = mda.coordinates.TRR.TRRReader
+
+
+def test_offset_readonly_handle(tmpdir):
+    with tmpdir.as_cwd():
+        curr_path = os.getcwd()
+        new_gro = os.path.join(curr_path, os.path.basename(GRO))
+        new_xtc = os.path.join(curr_path, os.path.basename(XTC))
+        shutil.copyfile(GRO, new_gro)
+        shutil.copyfile(XTC, new_xtc)
+        os.chmod(curr_path, 0o555)
+        u = mda.Universe(new_gro, new_xtc)

Copy link
Member

@zemanj zemanj Sep 18, 2022

Choose a reason for hiding this comment

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

According to the Python docs, PermissionError is a subclass of OSError, so your code is currently equivalent to only checking for OSError.
I'd advise against a simple check for OSError only, though, as this exception class covers many kinds of OS-related errors.
To narrow down the cause of the exception, it might be better to catch OSError, then check if it's a PermissionError or the errno member of the exception is the one you encountered. If so, raise the warning as before, otherwise just raise for the exception to bubble up.
For checking the errno, there should be a suitable constant in the errno module of the standard library so you don't have to hard-code numbers here.

EDIT: It's errno.EROFS.

warnings.warn(f"Cannot write lock/offset file in same location as "
"{self.filename}. Using slow offset calculation.")
self._read_offsets(store=True)
Expand Down