[elbe-devel] [PATCH 7/9] elbepack: filesystem: change file permissions during open()
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Mon Jul 29 10:46:34 CEST 2024
_write_file() only changes the file permissions after having written all
the data.
Switch to open(opener=) to do this directly when opening the file.
Now _write_file() is unused and can be removed.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/filesystem.py | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index e7b487abf78b..d05eb2d4d111 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -330,16 +330,12 @@ class Filesystem:
return flist
- @staticmethod
- def _write_file(path, f, cont, mode):
- f.write(cont)
- f.close()
- if mode is not None:
- os.chmod(path, mode)
-
def write_file(self, path, mode, cont):
- path = self.realpath(path)
- self._write_file(path, open(path, 'w'), cont, mode)
+ def opener(path, flags):
+ return os.open(path, flags, mode)
+
+ with self.open(path, 'w', opener=opener) as f:
+ f.write(cont)
def append_file(self, path, cont):
with self.open(path, 'a') as f:
--
2.45.2
More information about the elbe-devel
mailing list