diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-09 12:17:06 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-09 12:18:44 +0000 |
commit | 8bddb0996c44ce8ce989359a7b4c9ff102466ef2 (patch) | |
tree | 1d3497bd5b0bd771b93aedcf535eda044520dc3b | |
parent | 9fe25bf02dceec04f0ffd6a05cc47146ceab9904 (diff) | |
download | lorry-8bddb0996c44ce8ce989359a7b4c9ff102466ef2.tar.gz |
Delete downloaded tarballs on failure
Previously if a tarball lorry failed, a 0-byte tar file would be kept
around and subsequent calls to lorry would return success without
actually importing anything.
-rwxr-xr-x | lorry | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -477,10 +477,15 @@ class Lorry(cliapp.Application): self.progress('.. checking if we need to fetch %s' % basename) if not os.path.exists(tardest): self.progress('.. attempting to fetch.') - with open(tardest, 'w') as tarfile: - urlfile = urllib2.urlopen(spec['url']) - tarfile.write(urlfile.read()) - urlfile.close() + try: + with open(tardest, 'w') as tarfile: + urlfile = urllib2.urlopen(spec['url']) + tarfile.write(urlfile.read()) + urlfile.close() + except Exception as e: + if os.path.exists(tardest): + os.unlink(tardest) + raise else: self.progress('.. no need to run, nothing to do') return |