exec/file.py: add {root_,}makedir()
This commit is contained in:
parent
2535d6bbd8
commit
818b354000
1 changed files with 16 additions and 0 deletions
16
exec/file.py
16
exec/file.py
|
@ -119,3 +119,19 @@ def remove_file(path: str, recursive=False):
|
|||
rc = run_root_cmd(cmd).returncode
|
||||
if rc:
|
||||
raise Exception(f"Unable to remove {path}: cmd returned {rc}")
|
||||
|
||||
|
||||
def makedir(path, user: Optional[str] = None, group: Optional[str] = None, parents: bool = True):
|
||||
if not root_check_exists(path):
|
||||
try:
|
||||
if parents:
|
||||
os.makedirs(path, exist_ok=True)
|
||||
else:
|
||||
os.mkdir(path)
|
||||
except:
|
||||
run_root_cmd(['mkdir'] + (['-p'] if parents else []) + [path])
|
||||
chown(path, user, group)
|
||||
|
||||
|
||||
def root_makedir(path, parents: bool = True):
|
||||
return makedir(path, user='root', group='root', parents=parents)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue