mounts: convert paths to str during serialization

When creating the JSON data, call `os.fspath` on all paths, like
`root` and `devices.tree` to ensure they are strings; this allows
for tree to be an object that conforms to `os.PathLike`.
This commit is contained in:
Christian Kellner 2022-11-18 18:01:08 +01:00
parent 0a29694593
commit 881b2bb5c9

View file

@ -60,12 +60,14 @@ class MountManager:
source = self.devices.device_abspath(mount.device) source = self.devices.device_abspath(mount.device)
root = os.fspath(self.root)
args = { args = {
"source": source, "source": source,
"target": mount.target, "target": mount.target,
"root": self.root, "root": root,
"tree": self.devices.tree, "tree": os.fspath(self.devices.tree),
"options": mount.options, "options": mount.options,
} }
@ -80,10 +82,10 @@ class MountManager:
self.mounts[mount.name] = res self.mounts[mount.name] = res
return res return res
if not path.startswith(self.root): if not path.startswith(root):
raise RuntimeError(f"returned path '{path}' has wrong prefix") raise RuntimeError(f"returned path '{path}' has wrong prefix")
path = os.path.relpath(path, self.root) path = os.path.relpath(path, root)
self.mounts[mount.name] = path self.mounts[mount.name] = path