Add lock-file functionality for qvm-template install.

This commit is contained in:
WillyPillow 2020-07-26 02:08:46 +08:00
parent c573faa9c0
commit e6392ba4ec

View File

@ -25,6 +25,7 @@ TEMP_DIR = '/var/tmp'
PACKAGE_NAME_PREFIX = 'qubes-template-'
CACHE_DIR = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'qvm-template')
UNVERIFIED_SUFFIX = '.unverified'
LOCK_FILE = '/var/tmp/qvm-template.lck'
def qubes_release():
if os.path.exists('/usr/share/qubes/marker-vm'):
@ -142,7 +143,15 @@ def parse_config(path):
def install(args, app, version_selector=VersionSelector.LATEST,
ignore_existing=False):
# TODO: Lock, mentioned in the note above
try:
with open(LOCK_FILE, 'x') as _:
pass
except FileExistsError:
parser.error(('%s already exists.'
' Perhaps another instance of qvm-template is running?')
% LOCK_FILE)
try:
transaction_set = rpm.TransactionSet()
rpm_list = []
@ -200,7 +209,8 @@ def install(args, app, version_selector=VersionSelector.LATEST,
# Another check for already-downloaded RPMs
if not ignore_existing and name in app.domains:
print(('Template \'%s\' already installed, skipping...'
' (You may want to use the {reinstall,upgrade,downgrade}'
' (You may want to use the'
' {reinstall,upgrade,downgrade}'
' operations.)') % name, file=sys.stderr)
continue
@ -233,6 +243,8 @@ def install(args, app, version_selector=VersionSelector.LATEST,
tpl.features['template-reponame'] = reponame
tpl.features['template-summary'] = \
package_hdr[rpm.RPMTAG_SUMMARY]
finally:
os.remove(LOCK_FILE)
def qrexec_popen(args, app, service, stdout=subprocess.PIPE, filter_esc=True):
if args.updatevm: