osbuild: fix missing initialization of fd in osbuild.loop.Loop
When osbuild.loop.Loop calls `__init__()` it assigns the `self.fd` on open. However if that open call fails for whatever reason (not found, permissions) the cleanup in `__del__` will fail in confusing ways because `self.fd` is not initialized yet. It also prevents the correct error from getting reported. A tiny test is added to ensure this does not regress.
This commit is contained in:
parent
1374faa488
commit
edbf409a40
2 changed files with 6 additions and 0 deletions
|
|
@ -120,6 +120,7 @@ class Loop:
|
|||
self.devname = f"loop{minor}"
|
||||
self.minor = minor
|
||||
self.on_close = None
|
||||
self.fd = -1
|
||||
|
||||
with contextlib.ExitStack() as stack:
|
||||
if not dir_fd:
|
||||
|
|
|
|||
|
|
@ -253,3 +253,8 @@ def test_on_close(tempdir):
|
|||
lo.close()
|
||||
|
||||
ctl.close()
|
||||
|
||||
|
||||
def test_loop_handles_error_in_init():
|
||||
with pytest.raises(FileNotFoundError):
|
||||
lopo = loop.Loop("non-existing")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue