diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-12-15 21:18:19 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-12-15 21:18:19 +0000 |
commit | 5a6c54aeb95fcfdc70bef20e4a24a0bceed9ba45 (patch) | |
tree | c711d682c8349a5b2b1f2553b3825f058224a97b /lib/thandy/download.py | |
parent | eed069baf58952623ea035637eef154e10fa2038 (diff) |
Implement lengths in thandy objects, mostly:
Accept them, and when they're present, don't fetch more bytes than
specified, since that would be dangerous. Include lengths in every
generated object type except for the timestamp, since that would break
exising code.
git-svn-id: file:///home/or/svnrepo/updater/trunk@17629 55e972cd-5a19-0410-ae62-a4d7a52db4cd
Diffstat (limited to 'lib/thandy/download.py')
-rw-r--r-- | lib/thandy/download.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/thandy/download.py b/lib/thandy/download.py index 0c0d383..1d969e5 100644 --- a/lib/thandy/download.py +++ b/lib/thandy/download.py @@ -345,8 +345,8 @@ class DownloadStatusLog: class DownloadJob: """Abstract base class. Represents a thing to be downloaded, and the knowledge of how to download it.""" - def __init__(self, targetPath, tmpPath, wantHash=None, repoFile=None, - useTor=False): + def __init__(self, targetPath, tmpPath, wantHash=None, + repoFile=None, useTor=False, wantLength=None): """Create a new DownloadJob. When it is finally downloaded, store it in targetPath. Store partial results in tmpPath; if there is already a file in tmpPath, assume that it is an @@ -357,6 +357,7 @@ class DownloadJob: self._destPath = targetPath self._tmpPath = tmpPath self._wantHash = wantHash + self._wantLength = wantLength self._repoFile = repoFile self._useTor = useTor @@ -470,6 +471,12 @@ class DownloadJob: have_length = os.stat(self._tmpPath).st_size logging.info("Have stalled file for %s with %s bytes", url, have_length) + if self._wantLength != None: + if self._wantLength >= have_length: + logging.warn("Stalled file is too long; removing it") + self._removeTmpFile() + haveStalled = False + have_length = None else: have_length = None @@ -506,6 +513,13 @@ class DownloadJob: total += len(c) logging.debug("Got %s/%s bytes from %s", total, expectLength, url) + if self._wantLength != None and total > self._wantLength: + logging.warn("Read too many bytes from %s; got %s, but " + "wanted %s", url, total, self._wantLength) + break + + if self._wantLength != None and total != self._wantLength: + logging.warn("Length wrong on file %s", url) finally: if f_in is not None: |