core: chroot: validate name for rootfs chroot (MR 2332)

Make sure we get a valid name in the rootfs type chroot.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-23 21:07:24 +02:00 committed by Oliver Smith
parent 35eff91564
commit 9daa888f0f
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -70,6 +70,10 @@ class Chroot:
if self.__type == ChrootType.IMAGE and not Path(self.__name).exists():
raise ValueError(f"Image file '{self.__name}' does not exist")
# rootfs suffixes must have a valid device name
if self.__type == ChrootType.ROOTFS and (len(self.__name) < 3 or "-" not in self.__name):
raise ValueError(f"Invalid device name: '{self.__name}'")
def __str__(self) -> str:
if len(self.__name) > 0 and self.type != ChrootType.IMAGE:
return f"{self.__type.value}_{self.__name}"