Skip to content

Commit

Permalink
add win access control
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxuanzhuang committed Dec 7, 2024
1 parent bd749d7 commit f3767d3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,16 +894,33 @@ def test_unsupported_format(self, traj):
def test_persistent_offsets_readonly(self, tmpdir):
shutil.copy(self.filename, str(tmpdir))

os.chmod(str(tmpdir), 0o555)
if os.name == 'nt':
# Windows platform: deny write access using `icacls`
subprocess.run(
f"icacls {tmpdir} /deny Users:W",
shell=True,
check=True # Raises an error if the command fails
)
else:
# Non-Windows platforms: use chmod for read and execute only
os.chmod(str(tmpdir), 0o555)

filename = str(tmpdir.join(os.path.basename(self.filename)))
# try to write a offsets file
with pytest.warns(UserWarning, match="Couldn't save offsets"):
self._reader(filename)
assert_equal(os.path.exists(XDR.offsets_filename(filename)), False)

os.chmod(str(tmpdir), 0o777)

if os.name == 'nt':
# Windows platform: deny write access using `icacls`
subprocess.run(
f"icacls {tmpdir} /grant Users:W",
shell=True,
check=True # Raises an error if the command fails
)
else:
# Non-Windows platforms: use chmod for read and execute only
os.chmod(str(tmpdir), 0o777)
shutil.rmtree(tmpdir)

def test_offset_lock_created(self):
Expand Down

0 comments on commit f3767d3

Please sign in to comment.