mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-22 21:25:43 -05:00
exec/file: makedir(): add mode=None arg
This commit is contained in:
parent
cebac83186
commit
a4cfc3c3e5
1 changed files with 9 additions and 1 deletions
10
exec/file.py
10
exec/file.py
|
@ -144,7 +144,13 @@ def remove_file(path: str, recursive=False):
|
||||||
raise Exception(f"Unable to remove {path}: cmd returned {rc}")
|
raise Exception(f"Unable to remove {path}: cmd returned {rc}")
|
||||||
|
|
||||||
|
|
||||||
def makedir(path, user: Optional[Union[str, int]] = None, group: Optional[Union[str, int]] = None, parents: bool = True):
|
def makedir(
|
||||||
|
path,
|
||||||
|
user: Optional[Union[str, int]] = None,
|
||||||
|
group: Optional[Union[str, int]] = None,
|
||||||
|
parents: bool = True,
|
||||||
|
mode: Optional[Union[int, str]] = None,
|
||||||
|
):
|
||||||
if not root_check_exists(path):
|
if not root_check_exists(path):
|
||||||
try:
|
try:
|
||||||
if parents:
|
if parents:
|
||||||
|
@ -153,6 +159,8 @@ def makedir(path, user: Optional[Union[str, int]] = None, group: Optional[Union[
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
except:
|
except:
|
||||||
run_root_cmd(['mkdir'] + (['-p'] if parents else []) + [path])
|
run_root_cmd(['mkdir'] + (['-p'] if parents else []) + [path])
|
||||||
|
if mode is not None:
|
||||||
|
chmod(path, mode=mode)
|
||||||
chown(path, user, group)
|
chown(path, user, group)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue