mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-22 21:25:43 -05:00
exec/file: add copy_file()
This commit is contained in:
parent
7666b91efc
commit
ba5aa209dd
1 changed files with 7 additions and 4 deletions
11
exec/file.py
11
exec/file.py
|
@ -4,7 +4,7 @@ import os
|
|||
import stat
|
||||
import subprocess
|
||||
|
||||
from shutil import rmtree
|
||||
from shutil import copyfile, rmtree
|
||||
from tempfile import mkdtemp
|
||||
from typing import Optional, Union
|
||||
|
||||
|
@ -41,7 +41,7 @@ def chown(path: str, user: Optional[Union[str, int]] = None, group: Optional[Uni
|
|||
raise Exception(f"Failed to change owner of '{path}' to '{owner}'")
|
||||
|
||||
|
||||
def chmod(path, mode: Union[int, str] = 0o0755, force_sticky=True, privileged: bool = True):
|
||||
def chmod(path: str, mode: Union[int, str] = 0o0755, force_sticky=True, privileged: bool = True):
|
||||
if not isinstance(mode, str):
|
||||
octal = oct(mode)[2:]
|
||||
else:
|
||||
|
@ -60,11 +60,14 @@ def chmod(path, mode: Union[int, str] = 0o0755, force_sticky=True, privileged: b
|
|||
raise Exception(f"Failed to set mode of '{path}' to '{chmod}'")
|
||||
|
||||
|
||||
def root_check_exists(path):
|
||||
copy_file = copyfile
|
||||
|
||||
|
||||
def root_check_exists(path: str):
|
||||
return os.path.exists(path) or run_root_cmd(['[', '-e', path, ']']).returncode == 0
|
||||
|
||||
|
||||
def root_check_is_dir(path):
|
||||
def root_check_is_dir(path: str):
|
||||
return os.path.isdir(path) or run_root_cmd(['[', '-d', path, ']'])
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue