diff options
author | Steven Knight <knight@baldmt.com> | 2002-02-09 22:26:59 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-02-09 22:26:59 (GMT) |
commit | aeefea2d7f66b819bbaf6dff8a8afef63b05722e (patch) | |
tree | 2aa7a54a83057a80ae70daf235f2aefe8477ec0d /src/engine/SCons | |
parent | 490f796a5ca21af009f406e51e751823fef8ee5c (diff) | |
download | SCons-aeefea2d7f66b819bbaf6dff8a8afef63b05722e.zip SCons-aeefea2d7f66b819bbaf6dff8a8afef63b05722e.tar.gz SCons-aeefea2d7f66b819bbaf6dff8a8afef63b05722e.tar.bz2 |
Make writing a .sconsign more robust by writing to a temporary file first and renaming it.
Diffstat (limited to 'src/engine/SCons')
-rw-r--r-- | src/engine/SCons/Sig/__init__.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/engine/SCons/Sig/__init__.py b/src/engine/SCons/Sig/__init__.py index 52d8b33..d1e546f 100644 --- a/src/engine/SCons/Sig/__init__.py +++ b/src/engine/SCons/Sig/__init__.py @@ -29,6 +29,7 @@ The Signature package for the scons software construction utility. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import os import os.path import string import SCons.Node @@ -114,17 +115,38 @@ class SConsignFile: def write(self): """ Write the .sconsign file to disk. + + Try to write to a temporary file first, and rename it if we + succeed. If we can't write to the temporary file, it's + probably because the directory isn't writable (and if so, + how did we build anything in this directory, anyway?), so + try to write directly to the .sconsign file as a backup. + If we can't rename, try to copy the temporary contents back + to the .sconsign file. Either way, always try to remove + the temporary file at the end. """ if self.dirty: + temp = os.path.join(self.dir.path, '.scons%d' % os.getpid()) try: + file = open(temp, 'wt') + fname = temp + except: file = open(self.sconsign, 'wt') + fname = self.sconsign + keys = self.entries.keys() + keys.sort() + for name in keys: + file.write("%s: %s\n" % (name, self.entries[name])) + file.close + if fname != self.sconsign: + try: + os.rename(fname, self.sconsign) + except: + open(self.sconsign, 'wb').write(open(fname, 'rb').read()) + try: + os.unlink(temp) except: pass - else: - keys = self.entries.keys() - keys.sort() - for name in keys: - file.write("%s: %s\n" % (name, self.entries[name])) class Calculator: |