Commit 709f45f8 authored by Nikos Skalkotos's avatar Nikos Skalkotos

windows: Fix a bug in Registry class

Make sure the guestfs handler is never cached in registry class. There
are cases where the guestfs handler is recreated in image class. The
registry code should always access the guestfs handler from the image
class and never from a local copy.
parent cc930fbc
......@@ -174,6 +174,7 @@ class Image(object):
# process was introduced in version 1.19.16
if self.check_guestfs_version(1, 19, 16) >= 0:
self.g.shutdown()
self.g.close()
else:
self.g.kill_subprocess()
......
......@@ -265,7 +265,7 @@ class Windows(OSBase):
self.root)
self.vm = VM(self.image.device, self.sysprep_params)
self.registry = Registry(self.image.g, self.root)
self.registry = Registry(self.image)
# If the image is already sysprepped we cannot further customize it
with self.mount(readonly=True, silent=True):
......
......@@ -51,23 +51,26 @@ def safe_add_node(hive, parent, name):
class Registry(object):
"""Windows Registry manipulation methods"""
def __init__(self, guestfs_handler, root_partition):
self.g = guestfs_handler
self.root = root_partition
def __init__(self, image):
# Do not copy the guestfs handler. It may be overwritten by the image
# class in the future
self.image = image
self.root = image.root
def open_hive(self, hive, write=False):
"""Returns a context manager for opening a hive file of the image for
reading or writing.
"""
systemroot = self.g.inspect_get_windows_systemroot(self.root)
systemroot = self.image.g.inspect_get_windows_systemroot(self.root)
path = "%s/system32/config/%s" % (systemroot, hive)
try:
path = self.g.case_sensitive_path(path)
path = self.image.g.case_sensitive_path(path)
except RuntimeError as err:
raise FatalError("Unable to retrieve file: %s. Reason: %s" %
(hive, str(err)))
g = self.g # OpenHive class needs this since 'self' gets overwritten
# OpenHive class needs this since 'self' gets overwritten
g = self.image.g
class OpenHive:
"""The OpenHive context manager"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment