loop: add autoclear propert to LoopInfo
Small convenience property to check if the autoclear flag is set in the `lo_flags` member of the `LoopInfo`. Also add a corresponding test for it.
This commit is contained in:
parent
62082733e9
commit
61d5f15420
2 changed files with 13 additions and 1 deletions
|
|
@ -38,6 +38,11 @@ class LoopInfo(ctypes.Structure):
|
||||||
('lo_init', ctypes.c_uint64 * 2)
|
('lo_init', ctypes.c_uint64 * 2)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def autoclear(self) -> bool:
|
||||||
|
"""Return if `LO_FLAGS_AUTOCLEAR` is set in `lo_flags`"""
|
||||||
|
return bool(self.lo_flags & Loop.LO_FLAGS_AUTOCLEAR)
|
||||||
|
|
||||||
|
|
||||||
class Loop:
|
class Loop:
|
||||||
"""Loopback device
|
"""Loopback device
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ def test_basic(tempdir):
|
||||||
f = open(path, "wb+")
|
f = open(path, "wb+")
|
||||||
f.truncate(1024)
|
f.truncate(1024)
|
||||||
f.flush()
|
f.flush()
|
||||||
lo = ctl.loop_for_fd(f.fileno())
|
lo = ctl.loop_for_fd(f.fileno(), autoclear=True)
|
||||||
|
|
||||||
sb = os.fstat(f.fileno())
|
sb = os.fstat(f.fileno())
|
||||||
|
|
||||||
|
|
@ -46,6 +46,13 @@ def test_basic(tempdir):
|
||||||
assert info.lo_inode == sb.st_ino
|
assert info.lo_inode == sb.st_ino
|
||||||
assert info.lo_number == lo.minor
|
assert info.lo_number == lo.minor
|
||||||
|
|
||||||
|
# check for autoclear flags setting and helpers
|
||||||
|
assert info.autoclear
|
||||||
|
|
||||||
|
lo.set_status(autoclear=False)
|
||||||
|
info = lo.get_status()
|
||||||
|
assert not info.autoclear
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if lo:
|
if lo:
|
||||||
with contextlib.suppress(OSError):
|
with contextlib.suppress(OSError):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue