[elbe-devel] [PATCH v2 9/9] filesystem: Handle sysmlinks for w/r/a operations
Olivier Dion
dion at linutronix.de
Mon May 4 20:00:12 CEST 2020
Filesystem.fname() doesn't follow symlinks which is a problem if any
of the path's parts is an absolute symlink.
Using Filesystem.realpath() ensures that we get the right file.
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/filesystem.py | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index a77c8dba..99c5a013 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -208,26 +208,26 @@ class Filesystem(object):
return flist
- def write_file(self, path, mode, cont):
- f = self.open(path, "w")
+ def _write_file(self, path, f, cont, mode):
f.write(cont)
f.close()
if mode is not None:
- self.chmod(path, mode)
+ os.chmod(path, mode)
- def append_file(self, path, content, mode=None):
- f = self.open(path, "a")
- f.write(content)
- f.close()
- if mode is not None:
- self.chmod(path, mode)
+ def write_file(self, path, mode, cont):
+ path = self.realpath(path)
+ self._write_file(path, open(path, "w"), cont, mode)
+
+ def append_file(self, path, cont, mode=None):
+ path = self.realpath(path)
+ self._write_file(path, open(path, "a"), cont, mode)
def read_file(self, path, gzip=False):
+ path = self.realpath(path)
if gzip:
- print('read gzip '+path)
- fp = self.open_gz(path, "r")
+ fp = gzip.open(path, mode)
else:
- fp = self.open(path, "r")
+ fp = open(path, "r")
with fp:
retval = fp.read()
--
2.26.2
More information about the elbe-devel
mailing list