This reverts commit 640a88575a3f637ecdf6b6f677913020129aca04.
Jason Dalton authored on 2013/03/08 13:42:01... | ... |
@@ -6,7 +6,6 @@ |
6 | 6 |
## License: GPL Version 2 |
7 | 7 |
|
8 | 8 |
import sys |
9 |
-import binascii |
|
10 | 9 |
|
11 | 10 |
if float("%d.%d" %(sys.version_info[0], sys.version_info[1])) < 2.4: |
12 | 11 |
sys.stderr.write("ERROR: Python 2.4 or higher required, sorry.\n") |
... | ... |
@@ -25,7 +24,7 @@ import subprocess |
25 | 25 |
import htmlentitydefs |
26 | 26 |
import socket |
27 | 27 |
import shutil |
28 |
-import binascii |
|
28 |
+import tempfile |
|
29 | 29 |
import S3.Exceptions |
30 | 30 |
|
31 | 31 |
from copy import copy |
... | ... |
@@ -805,18 +804,15 @@ def cmd_sync_remote2local(args): |
805 | 805 |
try: |
806 | 806 |
debug(u"dst_file=%s" % unicodise(dst_file)) |
807 | 807 |
# create temporary files (of type .s3cmd.XXXX.tmp) in the same directory |
808 |
- # for downloading and then rename once downloaded |
|
809 |
- |
|
810 |
- temp_file_name = str(u".s3cmd.%s.tmp" % binascii.hexlify(os.urandom(10))) |
|
811 |
- temp_file = os.path.join(os.path.dirname(dst_file), temp_file_name) |
|
812 |
- debug(u"created temp_file=%s" % unicodise(temp_file)) |
|
813 |
- |
|
814 |
- dst_stream = open(temp_file, "wb") |
|
808 |
+ # for downloading and then rename once downloaded |
|
809 |
+ chkptfd, chkptfname = tempfile.mkstemp(".tmp",".s3cmd.",os.path.dirname(dst_file)) |
|
810 |
+ debug(u"created chkptfname=%s" % unicodise(chkptfname)) |
|
811 |
+ dst_stream = os.fdopen(chkptfd, "wb") |
|
815 | 812 |
response = s3.object_get(uri, dst_stream, extra_label = seq_label) |
816 | 813 |
dst_stream.close() |
817 | 814 |
# download completed, rename the file to destination |
818 |
- os.rename(temp_file, dst_file) |
|
819 |
- debug(u"renamed temp_file_name=%s to dst_file=%s" % (unicodise(temp_file_name), unicodise(dst_file))) |
|
815 |
+ os.rename(chkptfname, dst_file) |
|
816 |
+ debug(u"renamed chkptfname=%s to dst_file=%s" % (unicodise(chkptfname), unicodise(dst_file))) |
|
820 | 817 |
if response['headers'].has_key('x-amz-meta-s3cmd-attrs') and cfg.preserve_attrs: |
821 | 818 |
attrs = parse_attrs_header(response['headers']['x-amz-meta-s3cmd-attrs']) |
822 | 819 |
if attrs.has_key('mode'): |