summaryrefslogtreecommitdiff
path: root/lib/thandy/download.py
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-11-17 02:16:40 +0000
committerNick Mathewson <nickm@torproject.org>2008-11-17 02:16:40 +0000
commit32c62957f600c4dcba8fb24b6d00217876d84edd (patch)
tree078353ed88ee1b86d0d8a22fe0f0c985b99b1b95 /lib/thandy/download.py
parent082dc68c4c27cb55f53bb4830b3f0fe693f53116 (diff)
Avoid failure in the common-in-debugging case where we have a completely downloaded file in tmp
git-svn-id: file:///home/or/svnrepo/updater/trunk@17308 55e972cd-5a19-0410-ae62-a4d7a52db4cd
Diffstat (limited to 'lib/thandy/download.py')
-rw-r--r--lib/thandy/download.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/lib/thandy/download.py b/lib/thandy/download.py
index dab9a2c..8a9f083 100644
--- a/lib/thandy/download.py
+++ b/lib/thandy/download.py
@@ -189,16 +189,37 @@ class DownloadJob:
traceback.format_exc())
return False
+ def _checkTmpFile(self):
+ """DOCDOC"""
+ if self._wantHash and not self._repoFile:
+ gotHash = thandy.formats.getFileDigest(self._tmpPath)
+ if gotHash != self._wantHash:
+ raise thandy.DownloadError("File hash was not as expected.")
+ elif self._repoFile:
+ self._repoFile.checkFile(self._tmpPath, self._wantHash)
+
def _download(self):
# Implementation function. Unlike download(), can throw exceptions.
f_in = f_out = None
+ haveStalled = self.haveStalledFile()
+ if haveStalled and self._wantHash:
+ try:
+ self._checkTmpFile()
+ except thandy.Exception:
+ pass
+ else:
+ # What luck! This file was what we wanted.
+ thandy.util.ensureParentDir(self._destPath)
+ thandy.util.moveFile(self._tmpPath, self._destPath)
+ return
+
try:
url = self.getURL()
logging.info("Downloading %s", url)
- if self.haveStalledFile():
+ if haveStalled:
have_length = os.stat(self._tmpPath).st_size
logging.info("Have stalled file for %s with %s bytes", url,
have_length)
@@ -237,12 +258,7 @@ class DownloadJob:
if f_out is not None:
f_out.close()
- if self._wantHash and not self._repoFile:
- gotHash = thandy.formats.getFileDigest(self._tmpPath)
- if gotHash != self._wantHash:
- raise thandy.DownloadError("File hash was not as expected.")
- elif self._repoFile:
- self._repoFile.checkFile(self._tmpPath, self._wantHash)
+ self._checkTmpFile()
thandy.util.ensureParentDir(self._destPath)
thandy.util.moveFile(self._tmpPath, self._destPath)