[elbe-devel] [PATCH 3/6] elbevalidate: path: introduce _create_from_posixpath()

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon May 27 14:12:16 CEST 2024


This helper creates an ImagePath from an existing ImagePath and a new
PosixPath.
This functionality is used in a few places, and more will follow.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbevalidate/path.py | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/elbevalidate/path.py b/elbevalidate/path.py
index 936ae3fffeb3..5a342d3b2b13 100644
--- a/elbevalidate/path.py
+++ b/elbevalidate/path.py
@@ -22,14 +22,17 @@ class _PurePath:
         self._p = pathlib.PurePosixPath(*pathsegments)
         self._guestfs = guestfs
 
-    def joinpath(self, *pathsegments):
+    def _create_from_posixpath(self, p):
         return type(self)(
-                self._p.joinpath(*pathsegments),
+                p,
                 device=self.device,
                 guestfs=self._guestfs,
                 root=self.root,
         )
 
+    def joinpath(self, *pathsegments):
+        return self._create_from_posixpath(self._p.joinpath(*pathsegments))
+
     def __truediv__(self, key):
         try:
             return self.joinpath(key)
@@ -125,11 +128,7 @@ class Path(_PurePath):
 
     def readlink(self):
         with _guestfs_ctx():
-            return type(self)(
-                self._guestfs.readlink(self._path),
-                device=self.device,
-                guestfs=self._guestfs,
-            )
+            return self._create_from_posixpath(self._guestfs.readlink(self._path))
 
     def exists(self):
         with _guestfs_ctx():

-- 
2.45.1



More information about the elbe-devel mailing list