1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

btrfs module utils: pass command as list to run_command() (#11240)

* btrfs module utils: pass command as list to run_command()

* add changelog frag
This commit is contained in:
Alexei Znamensky 2025-12-03 00:08:41 +13:00 committed by GitHub
parent 0a802ecdcb
commit 8d51c5f666
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- btrfs module utils - make execution of external commands safer by passing arguments as list (https://github.com/ansible-collections/community.general/pull/11240).

View file

@ -37,7 +37,7 @@ class BtrfsCommands:
self.__btrfs: str = self.__module.get_bin_path("btrfs", required=True)
def filesystem_show(self) -> list[dict[str, t.Any]]:
command = f"{self.__btrfs} filesystem show -d"
command = [self.__btrfs, "filesystem", "show", "-d"]
result = self.__module.run_command(command, check_rc=True)
stdout = [x.strip() for x in result[1].splitlines()]
filesystems = []
@ -69,7 +69,7 @@ class BtrfsCommands:
return re.sub(r"^.*path\s", "", line)
def subvolumes_list(self, filesystem_path: str) -> list[dict[str, t.Any]]:
command = f"{self.__btrfs} subvolume list -tap {filesystem_path}"
command = [self.__btrfs, "subvolume", "list", "-tap", to_bytes(filesystem_path)]
result = self.__module.run_command(command, check_rc=True)
stdout = [x.split("\t") for x in result[1].splitlines()]
subvolumes: list[dict[str, t.Any]] = [{"id": 5, "parent": None, "path": "/"}]
@ -148,7 +148,7 @@ class BtrfsInfoProvider:
return [m for m in mountpoints if (m["device"] in devices)]
def __find_mountpoints(self) -> list[dict[str, t.Any]]:
command = f"{self.__findmnt_path} -t btrfs -nvP"
command = [self.__findmnt_path, "-t", "btrfs", "-nvP"]
result = self.__module.run_command(command)
mountpoints = []
if result[0] == 0: