ObjectStore/get_tree: make sure to clean up the context manager
Even if the yield raises an exception, we must always unmount to clean up. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
dcc9384ba8
commit
9371eb9eaa
1 changed files with 4 additions and 2 deletions
|
|
@ -145,8 +145,10 @@ class ObjectStore:
|
|||
with tempfile.TemporaryDirectory(dir=self.store) as tmp:
|
||||
if tree_id:
|
||||
subprocess.run(["mount", "-o", "bind,ro,mode=0755", f"{self.refs}/{tree_id}", tmp], check=True)
|
||||
yield tmp
|
||||
subprocess.run(["umount", "--lazy", tmp], check=True)
|
||||
try:
|
||||
yield tmp
|
||||
finally:
|
||||
subprocess.run(["umount", "--lazy", tmp], check=True)
|
||||
else:
|
||||
# None was given as tree_id, just return an empty directory
|
||||
yield tmp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue