From c75c0176dc23dbb50dc1420c2bfe181844e4ae47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 21 Apr 2018 15:07:21 +0200 Subject: [PATCH] tools/qvm-template-postprocess: fix reinstall action Do not remove template directory after reinstalling it in dom0. Fixes QubesOS/qubes-issues#3169 --- qubesadmin/tools/qvm_template_postprocess.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/qubesadmin/tools/qvm_template_postprocess.py b/qubesadmin/tools/qvm_template_postprocess.py index b6c43b3..c21abd6 100644 --- a/qubesadmin/tools/qvm_template_postprocess.py +++ b/qubesadmin/tools/qvm_template_postprocess.py @@ -196,14 +196,21 @@ def post_install(args): app = args.app vm_created = False + # reinstall and running in dom0, using the same directory as qubes core + local_reinstall = False try: # reinstall vm = app.domains[args.name] + if app.qubesd_connection_type == 'socket' and \ + args.dir == '/var/lib/qubes/vm-templates/' + args.name: + # VM exists and use use the same directory as target vm - on + # final cleanup remove only some files, not the whole directory + local_reinstall = True except KeyError: if app.qubesd_connection_type == 'socket' and \ args.dir == '/var/lib/qubes/vm-templates/' + args.name: # vm.create_on_disk() need to create the directory on its own, - # move it away for from its way + # move it away from its way tmp_sourcedir = os.path.join('/var/lib/qubes/vm-templates', 'tmp-' + args.name) shutil.move(args.dir, tmp_sourcedir) @@ -229,7 +236,13 @@ def post_install(args): yield from call_postinstall_service(vm) if not args.keep_source: - shutil.rmtree(args.dir) + if local_reinstall: + # remove only imported root img + root_path = os.path.join(args.dir, 'root.img') + for root_part in glob.glob(root_path + '.part.*'): + os.unlink(root_part) + else: + shutil.rmtree(args.dir) # if running as root, tell underlying storage layer about just freed # data blocks if os.getuid() == 0: