]> granicus.if.org Git - python/commitdiff
Use fstat if we can; write MAGIC into file last.
authorGuido van Rossum <guido@python.org>
Sat, 22 Nov 1997 21:48:26 +0000 (21:48 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 22 Nov 1997 21:48:26 +0000 (21:48 +0000)
Lib/py_compile.py

index e9e90ff6efa159f25db32eace3be0f6c1afaad0c..1adc3a209c608d7236ccc0aba98d0272e50e1933 100644 (file)
@@ -14,16 +14,22 @@ def wr_long(f, x):
 def compile(file, cfile = None):
        import os, marshal, __builtin__
        f = open(file)
+       try:
+           timestamp = os.fstat(file.fileno())
+       except AttributeError:
+           timestamp = long(os.stat(file)[8])
        codestring = f.read()
        f.close()
-       timestamp = long(os.stat(file)[8])
        codeobject = __builtin__.compile(codestring, file, 'exec')
        if not cfile:
                cfile = file + (__debug__ and 'c' or 'o')
        fc = open(cfile, 'wb')
-       fc.write(MAGIC)
+       fc.write('\0\0\0\0')
        wr_long(fc, timestamp)
        marshal.dump(codeobject, fc)
+       fc.flush()
+       fc.seek(0, 0)
+       fc.write(MAGIC)
        fc.close()
        if os.name == 'mac':
                import macfs