Ignore plist files without Label key

Some of the files in the directories listed in `launchctl._launchd_paths()` might not represent a service and have no Label key (for example `/System/Library/LaunchDaemons/com.apple.jetsamproperties.Mac.plist ` on MacOS 10.12). Previously this prevented the `service` module from working correctly as any state trying to access `launchctl._available_services()` would fail with an uncaught `AttributeError` exception when encountering such a file.
This commit is contained in:
Adaephon-GH 2017-01-24 15:27:12 +01:00 committed by GitHub
parent 6869621ed1
commit 616292c6b1

View file

@ -77,11 +77,17 @@ def _available_services():
else:
plist = plistlib.readPlistFromBytes(salt.utils.to_bytes(plist_xml))
available_services[plist.Label.lower()] = {
'filename': filename,
'file_path': true_path,
'plist': plist,
}
try:
available_services[plist.Label.lower()] = {
'filename': filename,
'file_path': true_path,
'plist': plist,
}
except AttributeError:
# As of MacOS 10.12 there might be plist files without Label key
# in the searched directories. As these files do not represent
# services, thay are not added to the list.
pass
return available_services