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:
parent
0a29694593
commit
881b2bb5c9
1 changed files with 6 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue