[elbe-devel] [PATCH v4 2/8] Add 'realpath' method to 'Filesystem'
dion at linutronix.de
dion at linutronix.de
Thu Jun 6 13:03:19 CEST 2019
From: Olivier Dion <dion at linutronix.de>
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/filesystem.py | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index d9f3e50e..4c925d1c 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -84,6 +84,29 @@ class Filesystem(object):
def mkdir(self, path):
os.makedirs(self.fname(path))
+ def realpath(self, path):
+ if path[0] != os.sep:
+ path = os.sep + path
+ path = path.split(os.sep)
+ path.reverse()
+ real_path = [self.path]
+ while path:
+ candidate = path.pop()
+ if candidate == '' or candidate == os.curdir:
+ continue
+ elif candidate == os.pardir:
+ if len(real_path) > 1:
+ real_path.pop()
+ else:
+ real_path.append(candidate)
+ new_path = os.sep.join(real_path)
+ if os.path.islink(new_path):
+ elements = os.readlink(new_path)
+ for element in reversed(elements.split(os.sep)):
+ path.append(element)
+ real_path.pop()
+ return os.sep.join(real_path)
+
def symlink(self, src, path, allow_exists=False):
try:
os.symlink(src, self.fname(path))
--
2.11.0
More information about the elbe-devel
mailing list