Skip to content

Commit

Permalink
fix: allow chown to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Dec 12, 2024
1 parent dcdc827 commit 632a1da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.12.1
- fix: better paths for docker setup
- fix: allow chown to fail
0.12.0
- feat: add dcor_config.json for docker images
0.11.8
Expand Down
16 changes: 13 additions & 3 deletions dcor_control/inspect/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import pwd
import stat
import warnings


def ask(prompt):
Expand Down Expand Up @@ -75,7 +76,11 @@ def check_permission(path: str | pathlib.Path,
if mode is not None:
os.chmod(path, mode)
if user is not None:
os.chown(path, uid, gid)
try:
os.chown(path, uid, gid)
except BaseException:
warnings.warn(
f"Failed to set ownership '{uid}:{gid}' for '{path}'")

# Check mode
pmode = stat.S_IMODE(path.stat().st_mode)
Expand Down Expand Up @@ -117,8 +122,13 @@ def check_permission(path: str | pathlib.Path,
chowner = ask(f"Owner of '{path}' is '{pusr}:{pgrp}', "
f"but should be '{user}:{group}'")
if chowner:
did_something += 1
os.chown(path, uid, gid)
try:
os.chown(path, uid, gid)
except BaseException:
warnings.warn(
f"Failed to set ownership '{uid}:{gid}' for '{path}'")
else:
did_something += 1

return did_something

Expand Down

0 comments on commit 632a1da

Please sign in to comment.