use test command to detect if folder

This commit is contained in:
Mathieu Broillet 2023-06-23 10:46:59 +02:00
parent e692c4df18
commit 6bd216615d
No known key found for this signature in database
GPG Key ID: 7D4F25BC50A0AA32

View File

@ -345,26 +345,22 @@ class LinuxMachine:
self.run_command(machine_utils.get_services_command(self.get_os_name(), "disable", service), self.run_command(machine_utils.get_services_command(self.get_os_name(), "disable", service),
return_status_code=True) 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"): def move(self, source, destination, permission: int = None, owner: str = "root"):
self.run_command(f"mv {source} {destination}", return_status_code=True) self.run_command(f"mv {source} {destination}", return_status_code=True)
if permission is not None: if permission is not None:
if "LXC" in str(self.__class__): if self.is_folder(source):
if self.pve.connection.sftp().is_remote_dir(source): permission = 755
permission = 755 self.run_command(f"chmod -R {permission} {destination}", return_status_code=True)
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)
else: 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 owner != "root":
if "LXC" in str(self.__class__): if self.is_folder(source):
if self.pve.connection.sftp().is_remote_dir(source): self.run_command(f"chown -R {owner} {destination}", return_status_code=True)
self.run_command(f"chown -R {owner} {destination}", return_status_code=True)
else:
self.run_command(f"chown {owner} {destination}", return_status_code=True)
else: else:
raise NotImplementedError("Owner setting is only supported for LXC machines") self.run_command(f"chown {owner} {destination}", return_status_code=True)