add option to set owner when creating file/folder
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
30cbc33217
commit
423bc70634
@ -155,11 +155,11 @@ def run_steps(lxc: LXC):
|
||||
case "script":
|
||||
lxc_utils.run_script_step_parser(lxc, step)
|
||||
case "file_create":
|
||||
lxc.create_file(step["path"], step.get("permission", 644))
|
||||
lxc.create_file(step["path"], step.get("permission", 644), step.get("owner", "root"))
|
||||
case "file_copy":
|
||||
lxc.pve.copy_file_to_lxc(lxc, get_path(lxc, step["path"]), step["destination"])
|
||||
case "folder":
|
||||
lxc.create_directory(step["path"], step.get("permission", 755))
|
||||
lxc.create_directory(step["path"], step.get("permission", 755), step.get("owner", "root"))
|
||||
case "folder_copy":
|
||||
lxc.pve.copy_folder_to_lxc(lxc, get_path(lxc, step["path"]), step["destination"])
|
||||
case "command":
|
||||
|
@ -104,7 +104,7 @@ class LinuxMachine():
|
||||
def list_dir(self, directory: str or Path):
|
||||
pass
|
||||
|
||||
def create_file(self, file: str or Path, permission: int = 644):
|
||||
def create_file(self, file: str or Path, permission: int = 644, owner: str = "root"):
|
||||
"""Create file"""
|
||||
if isinstance(file, Path):
|
||||
file = str(file.as_posix())
|
||||
@ -112,8 +112,11 @@ class LinuxMachine():
|
||||
self.run_command(f"touch {file}", return_status_code=True)
|
||||
if permission != 644:
|
||||
self.run_command(f"chmod {permission} {file}", return_status_code=True)
|
||||
if owner != "root":
|
||||
self.run_command(f"chown {owner} {file}", return_status_code=True)
|
||||
|
||||
def create_directory(self, directory: str or Path, permission: int = 755, use_ssh: bool = True):
|
||||
def create_directory(self, directory: str or Path, permission: int = 755, owner: str = "root",
|
||||
use_ssh: bool = True):
|
||||
"""Create directory"""
|
||||
if isinstance(directory, Path):
|
||||
directory = str(directory.as_posix())
|
||||
@ -121,6 +124,8 @@ class LinuxMachine():
|
||||
self.run_command(f"mkdir -p {directory}", return_status_code=True, use_ssh=use_ssh)
|
||||
if permission != 755:
|
||||
self.run_command(f"chmod -R {permission} {directory}", return_status_code=True, use_ssh=use_ssh)
|
||||
if owner != "root":
|
||||
self.run_command(f"chown -R {owner} {directory}", return_status_code=True)
|
||||
|
||||
def delete_file(self, file: str or Path, use_ssh: bool = True):
|
||||
"""Delete file"""
|
||||
|
Loading…
Reference in New Issue
Block a user