From 6bd216615d7e6ffc31090d38082c463c53280881 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Fri, 23 Jun 2023 10:46:59 +0200 Subject: [PATCH] use test command to detect if folder --- src/machine/machine.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/machine/machine.py b/src/machine/machine.py index cdddf27..c6eb785 100644 --- a/src/machine/machine.py +++ b/src/machine/machine.py @@ -345,26 +345,22 @@ class LinuxMachine: self.run_command(machine_utils.get_services_command(self.get_os_name(), "disable", service), return_status_code=True) + def is_folder(self, path: str) -> bool: + self.run_command(f"test -d {path}", return_status_code=True) + def move(self, source, destination, permission: int = None, owner: str = "root"): self.run_command(f"mv {source} {destination}", return_status_code=True) if permission is not None: - if "LXC" in str(self.__class__): - if self.pve.connection.sftp().is_remote_dir(source): - permission = 755 - self.run_command(f"chmod -R {permission} {destination}", return_status_code=True) - else: - permission = 644 - self.run_command(f"chmod {permission} {destination}", return_status_code=True) + if self.is_folder(source): + permission = 755 + self.run_command(f"chmod -R {permission} {destination}", return_status_code=True) else: - raise NotImplementedError("Permission setting is only supported for LXC machines") + permission = 644 + self.run_command(f"chmod {permission} {destination}", return_status_code=True) if owner != "root": - if "LXC" in str(self.__class__): - if self.pve.connection.sftp().is_remote_dir(source): - self.run_command(f"chown -R {owner} {destination}", return_status_code=True) - else: - self.run_command(f"chown {owner} {destination}", return_status_code=True) + if self.is_folder(source): + self.run_command(f"chown -R {owner} {destination}", return_status_code=True) else: - raise NotImplementedError("Owner setting is only supported for LXC machines") - + self.run_command(f"chown {owner} {destination}", return_status_code=True)