Suppress errors when checking if an alternative exists

This commit is contained in:
Adam Mendlik 2016-12-17 11:30:02 -07:00
parent 9e35f5dd08
commit 09dee3c611

View File

@ -112,12 +112,11 @@ def show_current(name):
salt '*' alternatives.show_current editor
'''
alt_link_path = '/etc/alternatives/{0}'.format(name)
try:
return os.readlink(alt_link_path)
return _read_link(name)
except OSError:
log.error(
'alternatives: path {0} does not exist'.format(alt_link_path)
'alternative: {0} does not exist'.format(name)
)
return False
@ -154,7 +153,10 @@ def check_installed(name, path):
salt '*' alternatives.check_installed name path
'''
return show_current(name) == path
try:
return _read_link(name) == path
except OSError:
return False
def install(name, link, path, priority):
@ -224,3 +226,13 @@ def set_(name, path):
if out['retcode'] > 0:
return out['stderr']
return out['stdout']
def _read_link(name):
'''
Read the link from /etc/alternatives
Throws an OSError if the link does not exist
'''
alt_link_path = '/etc/alternatives/{0}'.format(name)
return os.readlink(alt_link_path)