From 79d2e645d8f8593e4beda0a18666c9d6be1fe3dd Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 1 Jul 2010 17:17:29 +0000 Subject: [PATCH] deal better with stale contents.xml file in local directory --- direct/src/p3d/AppRunner.py | 8 +++++++- direct/src/p3d/HostInfo.py | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/direct/src/p3d/AppRunner.py b/direct/src/p3d/AppRunner.py index 1a120a9899..5ba23797a3 100644 --- a/direct/src/p3d/AppRunner.py +++ b/direct/src/p3d/AppRunner.py @@ -802,7 +802,8 @@ class AppRunner(DirectObject): self.readConfigXml() - def addPackageInfo(self, name, platform, version, hostUrl, hostDir = None): + def addPackageInfo(self, name, platform, version, hostUrl, hostDir = None, + recurse = False): """ Called by the browser for each one of the "required" packages that were preloaded before starting the application. If for some reason the package isn't already downloaded, this @@ -830,6 +831,11 @@ class AppRunner(DirectObject): platform = None package = host.getPackage(name, version, platform = platform) if not package: + if not recurse: + # Maybe the contents.xml file isn't current. Re-fetch it. + if host.redownloadContentsFile(self.http): + return self.addPackageInfo(name, platform, version, hostUrl, hostDir = hostDir, recurse = True) + message = "Couldn't find %s %s on %s" % (name, version, hostUrl) raise OSError, message diff --git a/direct/src/p3d/HostInfo.py b/direct/src/p3d/HostInfo.py index b377ca2bc6..7ca0e47760 100644 --- a/direct/src/p3d/HostInfo.py +++ b/direct/src/p3d/HostInfo.py @@ -106,10 +106,13 @@ class HostInfo: # https-protected hostUrl, it will be the cleartext channel. self.downloadUrlPrefix = self.hostUrlPrefix - def downloadContentsFile(self, http, redownload = False): + def downloadContentsFile(self, http, redownload = False, + hashVal = None): """ Downloads the contents.xml file for this particular host, synchronously, and then reads it. Returns true on success, - false on failure. """ + false on failure. If hashVal is not None, it should be a + HashVal object, which will be filled with the hash from the + new contents.xml file.""" if self.hasCurrentContentsFile(): # We've already got one. @@ -159,6 +162,8 @@ class HostInfo: f = open(tempFilename.toOsSpecific(), 'wb') f.write(rf.getData()) f.close() + if hashVal: + hashVal.hashString(rf.getData()) if not self.readContentsFile(tempFilename, freshDownload = True): self.notify.warning("Failure reading %s" % (url)) @@ -192,14 +197,15 @@ class HostInfo: # Now download it again. self.hasContentsFile = False - if not self.downloadContentsFile(http, redownload = True): - return False - hv2 = HashVal() - filename = Filename(self.hostDir, 'contents.xml') - hv2.hashFile(filename) + if not self.downloadContentsFile(http, redownload = True, + hashVal = hv2): + return False - if hv1 != hv2: + if hv2 == HashVal(): + self.notify.info("%s didn't actually redownload." % (url)) + return False + elif hv1 != hv2: self.notify.info("%s has changed." % (url)) return True else: