[elbe-devel] [PATCH v3 2/7] filesystem: Add context manager for TmpdirFilesystem

Olivier Dion dion at linutronix.de
Thu Aug 20 18:02:10 CEST 2020


Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/filesystem.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index 51697907..683899b7 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -507,6 +507,13 @@ class TmpdirFilesystem (Filesystem):
     def delete(self):
         shutil.rmtree(self.path, True)
 
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exec_type, exec_value, tb):
+        shutil.rmtree(self.path)
+        return False
+
 
 class ImgMountFilesystem(Filesystem):
     def __init__(self, mntpoint, dev):
-- 
2.28.0



More information about the elbe-devel mailing list