[elbe-devel] [PATCH v2 9/9] filesystem: Handle sysmlinks for w/r/a operations

Torben Hohn torben.hohn at linutronix.de
Wed May 13 14:11:16 CEST 2020


On Mon, May 04, 2020 at 02:00:12PM -0400, Olivier Dion wrote:
> 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>

Reviewed-by: Torben Hohn <torben.hohn 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
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list