Skip to content

Commit

Permalink
allow to force
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed May 14, 2024
1 parent 4016b74 commit 263cbac
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions library/1.0.0/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
RE_MODE = re.compile(r"^(0o)?([0-7]{3})$")


def chown(path, uid, gid):
def chown(path, uid, gid, force=False):
if not pathlib.Path(path).exists():
utils.throw_error(f"Path [{path}] does not exist")

if any(pathlib.Path(path).iterdir()):
if not force:
utils.throw_error(
f"Path [{path}] is not empty, skipping... Use [force=True] to override"
)

if not RE_ID.match(uid):
utils.throw_error(f"User ID must be a number, but got [{uid}]")
if not RE_ID.match(gid):
Expand All @@ -20,10 +26,16 @@ def chown(path, uid, gid):
return ""


def chmod(path, mode):
def chmod(path, mode, force=False):
if not pathlib.Path(path).exists():
utils.throw_error(f"Path [{path}] does not exist")

if any(pathlib.Path(path).iterdir()):
if not force:
utils.throw_error(
f"Path [{path}] is not empty, skipping... Use [force=True] to override"
)

if not RE_MODE.match(mode):
utils.throw_error(
f"Mode must be in octal format, but got [{mode}]. Example: 0o755 or 755"
Expand Down

0 comments on commit 263cbac

Please sign in to comment.