mktemp permission issue, fix
Michal Ludvig authored on 2013/03/08 14:46:13... | ... |
@@ -812,6 +812,15 @@ def cmd_sync_remote2local(args): |
812 | 812 |
dst_stream.close() |
813 | 813 |
# download completed, rename the file to destination |
814 | 814 |
os.rename(chkptfname, dst_file) |
815 |
+ |
|
816 |
+ # set permissions on destination file |
|
817 |
+ original_umask = os.umask(0); |
|
818 |
+ os.umask(original_umask); |
|
819 |
+ mode = 0777 - original_umask; |
|
820 |
+ debug(u"mode=%s" % oct(mode)) |
|
821 |
+ |
|
822 |
+ os.chmod(dst_file, mode); |
|
823 |
+ |
|
815 | 824 |
debug(u"renamed chkptfname=%s to dst_file=%s" % (unicodise(chkptfname), unicodise(dst_file))) |
816 | 825 |
if response['headers'].has_key('x-amz-meta-s3cmd-attrs') and cfg.preserve_attrs: |
817 | 826 |
attrs = parse_attrs_header(response['headers']['x-amz-meta-s3cmd-attrs']) |
... | ... |
@@ -823,7 +832,9 @@ def cmd_sync_remote2local(args): |
823 | 823 |
os.utime(dst_file, (atime, mtime)) |
824 | 824 |
## FIXME: uid/gid / uname/gname handling comes here! TODO |
825 | 825 |
except OSError, e: |
826 |
- try: dst_stream.close() |
|
826 |
+ try: |
|
827 |
+ dst_stream.close() |
|
828 |
+ os.remove(chkptfname) |
|
827 | 829 |
except: pass |
828 | 830 |
if e.errno == errno.EEXIST: |
829 | 831 |
warning(u"%s exists - not overwriting" % (dst_file)) |
... | ... |
@@ -836,19 +847,25 @@ def cmd_sync_remote2local(args): |
836 | 836 |
continue |
837 | 837 |
raise e |
838 | 838 |
except KeyboardInterrupt: |
839 |
- try: dst_stream.close() |
|
839 |
+ try: |
|
840 |
+ dst_stream.close() |
|
841 |
+ os.remove(chkptfname) |
|
840 | 842 |
except: pass |
841 | 843 |
warning(u"Exiting after keyboard interrupt") |
842 | 844 |
return |
843 | 845 |
except Exception, e: |
844 |
- try: dst_stream.close() |
|
846 |
+ try: |
|
847 |
+ dst_stream.close() |
|
848 |
+ os.remove(chkptfname) |
|
845 | 849 |
except: pass |
846 | 850 |
error(u"%s: %s" % (file, e)) |
847 | 851 |
continue |
848 | 852 |
# We have to keep repeating this call because |
849 | 853 |
# Python 2.4 doesn't support try/except/finally |
850 | 854 |
# construction :-( |
851 |
- try: dst_stream.close() |
|
855 |
+ try: |
|
856 |
+ dst_stream.close() |
|
857 |
+ os.remove(chkptfname) |
|
852 | 858 |
except: pass |
853 | 859 |
except S3DownloadError, e: |
854 | 860 |
error(u"%s: download failed too many times. Skipping that file." % file) |