From 881b2bb5c9c80f80eed127d84cd5da99439892f8 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 18 Nov 2022 18:01:08 +0100 Subject: [PATCH] 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`. --- osbuild/mounts.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osbuild/mounts.py b/osbuild/mounts.py index a818950a..f3374b75 100644 --- a/osbuild/mounts.py +++ b/osbuild/mounts.py @@ -60,12 +60,14 @@ class MountManager: source = self.devices.device_abspath(mount.device) + root = os.fspath(self.root) + args = { "source": source, "target": mount.target, - "root": self.root, - "tree": self.devices.tree, + "root": root, + "tree": os.fspath(self.devices.tree), "options": mount.options, } @@ -80,10 +82,10 @@ class MountManager: self.mounts[mount.name] = res return res - if not path.startswith(self.root): + if not path.startswith(root): 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