If a corrupt Apple Software Update dist file fails to parse when detecting blocking applications, simply assume there are no blocking applications instead of crashing.

This commit is contained in:
Justin McWilliams
2012-06-29 15:40:15 -04:00
parent 7d3d7d1ac8
commit a788ac2e06
+16 -12
View File
@@ -30,6 +30,7 @@ import time
import urllib2
import urlparse
from xml.dom import minidom
from xml.parsers import expat
from Foundation import NSDate
from Foundation import CFPreferencesCopyAppValue
@@ -323,7 +324,7 @@ class AppleUpdates(object):
# rewrite all URLs, including pkgs, to point to local caches.
self.RewriteCatalogURLs(catalog, rewrite_pkg_urls=True)
FoundationPlist.writePlist(catalog, self.local_catalog_path)
def _GetPreferredLocalization(self, list_of_localizations):
'''Picks the best localization from a list of available
localizations.'''
@@ -341,17 +342,17 @@ class AppleUpdates(object):
list_of_localizations, None)
if preferred_langs:
return preferred_langs[0]
# first fallback, return en or English
if 'English' in list_of_localizations:
return 'English'
elif 'en' in list_of_localizations:
return 'en'
# if we get this far, just return the first language
# in the list of available languages
return list_of_localizations[0]
def GetDistributionForProductKey(self, product_key):
'''Returns the path to a distibution file from the local cache for the given
product_key.'''
@@ -371,17 +372,20 @@ class AppleUpdates(object):
fileurl = fileurl[len('file://localhost'):]
return urllib2.unquote(fileurl)
return None
def GetBlockingApps(self, product_key):
'''Given a product key, finds the cached softwareupdate dist file,
'''Given a product key, finds the cached softwareupdate dist file,
then parses it, looking for must-close apps and converting them to
Munki's blocking_applications'''
distfile = self.GetDistributionForProductKey(product_key)
if not distfile:
return []
dom = minidom.parse(distfile)
try:
dom = minidom.parse(distfile)
except expat.ExpatError:
return []
must_close_app_ids = []
must_close_items = dom.getElementsByTagName('must-close')
@@ -391,7 +395,7 @@ class AppleUpdates(object):
keys = app.attributes.keys()
if 'id' in keys:
must_close_app_ids.append(app.attributes['id'].value)
blocking_apps = []
for id in must_close_app_ids:
resultcode, fileref, nsurl = LSFindApplicationForInfo(
@@ -402,9 +406,9 @@ class AppleUpdates(object):
pathname = urllib2.unquote(fileurl).rstrip('/')
appname = os.path.basename(pathname)
blocking_apps.append(appname)
return blocking_apps
def _WriteFilteredCatalog(self, product_ids, catalog_path):
"""Write out a sucatalog containing only the updates in product_ids.