Skip to content

Commit d20b222

Browse files
committed
Tweaks
1 parent bc288a8 commit d20b222

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

dissect/hypervisor/disk/vdi.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@
1818
class VDI:
1919
"""VirtualBox Virtual Disk Image (VDI) implementation.
2020
21-
If provided with file-like objects, the caller is responsible for closing them.
22-
When provided with paths, the VDI class will manage the file handles.
21+
Use :method:`open` to get a stream for reading from the VDI file. The stream will handle reading
22+
from the parent disk if necessary (and provided).
23+
24+
If provided with a file-like object, the caller is responsible for closing it.
25+
When provided with a path, the VDI class will manage the file handle.
26+
27+
If providing a parent file-like object, the caller is responsible for the lifecycle of that object.
2328
2429
Args:
2530
fh: File-like object or path of the VDI file.
26-
parent: Optional file-like object or path for the parent disk (for differencing disks).
31+
parent: Optional file-like object for the parent disk (for differencing disks).
2732
"""
2833

29-
def __init__(self, fh: BinaryIO | Path, parent: BinaryIO | Path | None = None):
34+
def __init__(self, fh: BinaryIO | Path, parent: BinaryIO | None = None):
3035
if isinstance(fh, Path):
3136
self.path = fh
3237
self.fh = self.path.open("rb")
3338
else:
3439
self.path = None
3540
self.fh = fh
3641

37-
if isinstance(parent, Path):
38-
self.parent_path = parent
39-
self.parent = self.parent_path.open("rb")
40-
else:
41-
self.parent_path = None
42-
self.parent = parent
42+
self.parent = parent
4343

4444
self.fh.seek(0)
4545
self.preheader = c_vdi.VDIPREHEADER(self.fh)
@@ -102,9 +102,6 @@ def close(self) -> None:
102102
if self.path is not None:
103103
self.fh.close()
104104

105-
if self.parent_path is not None and self.parent is not None:
106-
self.parent.close()
107-
108105

109106
class VDIStream(AlignedStream):
110107
def __init__(self, vdi: VDI):

0 commit comments

Comments
 (0)