cython-devel

changeset 1782:e66a36990c06

Create new c file to play better with hard links (Trac #220)
author Robert Bradshaw <robertwb@math.washington.edu>
date Thu Feb 26 14:05:53 2009 -0800 (2 years ago)
parents 6c54ca49c2af
children 15f1ccea98a1
files Cython/Utils.py
line diff
1.1 --- a/Cython/Utils.py Thu Feb 26 00:38:33 2009 -0800 1.2 +++ b/Cython/Utils.py Thu Feb 26 14:05:53 2009 -0800 1.3 @@ -10,22 +10,22 @@ 1.4 return base + newsuf 1.5 1.6 def open_new_file(path): 1.7 - # Open and truncate existing file to 1.8 - # preserve metadata on the Mac. 1.9 - return open(path, "w+") 1.10 + if os.path.exists(path): 1.11 + # Make sure to create a new file here so we can 1.12 + # safely hard link the output files. 1.13 + os.unlink(path) 1.14 + return open(path, "w") 1.15 1.16 def castrate_file(path, st): 1.17 # Remove junk contents from an output file after a 1.18 - # failed compilation, but preserve metadata on Mac. 1.19 + # failed compilation. 1.20 # Also sets access and modification times back to 1.21 # those specified by st (a stat struct). 1.22 try: 1.23 - f = open(path, "r+") 1.24 + f = open_new_file(path) 1.25 except EnvironmentError: 1.26 pass 1.27 else: 1.28 - f.seek(0, 0) 1.29 - f.truncate() 1.30 f.write( 1.31 "#error Do not use this file, it is the result of a failed Cython compilation.\n") 1.32 f.close()