Show More
@@ -1009,14 +1009,26 b' def opener(base, audit=True):' | |||
|
1009 | 1009 | d, fn = os.path.split(name) |
|
1010 | 1010 | fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d) |
|
1011 | 1011 | os.close(fd) |
|
1012 | ofp = posixfile(temp, "wb") | |
|
1012 | # Temporary files are created with mode 0600, which is usually not | |
|
1013 | # what we want. If the original file already exists, just copy | |
|
1014 | # its mode. Otherwise, manually obey umask. | |
|
1015 | try: | |
|
1016 | st_mode = os.lstat(name).st_mode | |
|
1017 | except OSError, inst: | |
|
1018 | if inst.errno != errno.ENOENT: | |
|
1019 | raise | |
|
1020 | st_mode = 0666 & ~_umask | |
|
1021 | os.chmod(temp, st_mode) | |
|
1013 | 1022 | try: |
|
1014 | 1023 | try: |
|
1015 | 1024 | ifp = posixfile(name, "rb") |
|
1016 | 1025 | except IOError, inst: |
|
1026 | if inst.errno == errno.ENOENT: | |
|
1027 | return temp | |
|
1017 | 1028 | if not getattr(inst, 'filename', None): |
|
1018 | 1029 | inst.filename = name |
|
1019 | 1030 | raise |
|
1031 | ofp = posixfile(temp, "wb") | |
|
1020 | 1032 | for chunk in filechunkiter(ifp): |
|
1021 | 1033 | ofp.write(chunk) |
|
1022 | 1034 | ifp.close() |
@@ -1025,8 +1037,6 b' def opener(base, audit=True):' | |||
|
1025 | 1037 | try: os.unlink(temp) |
|
1026 | 1038 | except: pass |
|
1027 | 1039 | raise |
|
1028 | st = os.lstat(name) | |
|
1029 | os.chmod(temp, st.st_mode) | |
|
1030 | 1040 | return temp |
|
1031 | 1041 | |
|
1032 | 1042 | class atomictempfile(posixfile): |
@@ -1067,16 +1077,16 b' def opener(base, audit=True):' | |||
|
1067 | 1077 | try: |
|
1068 | 1078 | nlink = nlinks(f) |
|
1069 | 1079 | except OSError: |
|
1080 | nlink = 0 | |
|
1070 | 1081 | d = os.path.dirname(f) |
|
1071 | 1082 | if not os.path.isdir(d): |
|
1072 | 1083 | os.makedirs(d) |
|
1073 |
|
|
|
1074 |
|
|
|
1075 | return atomicfile(f, mode) | |
|
1076 |
|
|
|
1077 | return atomictempfile(f, mode) | |
|
1078 | if nlink > 1: | |
|
1079 | rename(mktempcopy(f), f) | |
|
1084 | if atomic: | |
|
1085 | return atomicfile(f, mode) | |
|
1086 | elif atomictemp: | |
|
1087 | return atomictempfile(f, mode) | |
|
1088 | if nlink > 1: | |
|
1089 | rename(mktempcopy(f), f) | |
|
1080 | 1090 | return posixfile(f, mode) |
|
1081 | 1091 | |
|
1082 | 1092 | return o |
General Comments 0
You need to be logged in to leave comments.
Login now