Skip to content

Commit e6c128f

Browse files
committed
Use fstat if we can; write MAGIC into file last.
1 parent 8700fe6 commit e6c128f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Lib/py_compile.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ def wr_long(f, x):
1414
def compile(file, cfile = None):
1515
import os, marshal, __builtin__
1616
f = open(file)
17+
try:
18+
timestamp = os.fstat(file.fileno())
19+
except AttributeError:
20+
timestamp = long(os.stat(file)[8])
1721
codestring = f.read()
1822
f.close()
19-
timestamp = long(os.stat(file)[8])
2023
codeobject = __builtin__.compile(codestring, file, 'exec')
2124
if not cfile:
2225
cfile = file + (__debug__ and 'c' or 'o')
2326
fc = open(cfile, 'wb')
24-
fc.write(MAGIC)
27+
fc.write('\0\0\0\0')
2528
wr_long(fc, timestamp)
2629
marshal.dump(codeobject, fc)
30+
fc.flush()
31+
fc.seek(0, 0)
32+
fc.write(MAGIC)
2733
fc.close()
2834
if os.name == 'mac':
2935
import macfs

0 commit comments

Comments
 (0)