Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

S3: cleanup if key.get_contents_to_filename fails #1201

Merged
merged 1 commit into from

2 participants

@hashbackup

if key.get_contents_to_filename fails, it leaves an empty file and open file descriptor behind. Instead, remove the file (since we created it, or at least truncated it to 0 length) and close the file descriptor.

@hashbackup hashbackup S3: cleanup if key.get_contents_to_filename fails
if key.get_contents_to_filename fails, it leaves an empty file and open file descriptor behind.  Instead, remove the file (since we created it, or at least truncated it to 0 length) and close the file descriptor.
af97f2a
@jamesls jamesls merged commit af97f2a into boto:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 24, 2012
  1. @hashbackup

    S3: cleanup if key.get_contents_to_filename fails

    hashbackup authored
    if key.get_contents_to_filename fails, it leaves an empty file and open file descriptor behind.  Instead, remove the file (since we created it, or at least truncated it to 0 length) and close the file descriptor.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 5 deletions.
  1. +10 −5 boto/s3/key.py
View
15 boto/s3/key.py
@@ -1468,11 +1468,16 @@ def get_contents_to_filename(self, filename, headers=None,
http://goo.gl/EWOPb for details.
"""
fp = open(filename, 'wb')
- self.get_contents_to_file(fp, headers, cb, num_cb, torrent=torrent,
- version_id=version_id,
- res_download_handler=res_download_handler,
- response_headers=response_headers)
- fp.close()
+ try:
+ self.get_contents_to_file(fp, headers, cb, num_cb, torrent=torrent,
+ version_id=version_id,
+ res_download_handler=res_download_handler,
+ response_headers=response_headers)
+ except Exception:
+ os.remove(filename)
+ raise
+ finally:
+ fp.close()
# if last_modified date was sent from s3, try to set file's timestamp
if self.last_modified != None:
try:
Something went wrong with that request. Please try again.