r29243 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29242‎ | r29243 | r29244 >
Date:22:55, 3 January 2008
Author:brion
Status:old
Tags:
Comment:
Write index HTML pages to temporary files, then atomic-copy over.
Might or might not actually be atomic on the NFS, but should avoid some freakouts. :)
Modified paths:
  • /trunk/backup/WikiDump.py (modified) (history)
  • /trunk/backup/monitor.py (modified) (history)

Diff [purge]

Index: trunk/backup/WikiDump.py
@@ -47,10 +47,18 @@
4848 return "-".join((key[0:4], key[4:6], key[6:8]))
4949
5050 def dumpFile(filename, text):
51 - """Dump a string to a file."""
52 - file = open(filename, "wt")
 51+ """Dump a string to a file, as atomically as possible, via a temporary file in the same directory."""
 52+
 53+ # I'd use os.tempnam() here but it whines about symlinks attacks.
 54+ tempFilename = filename + ".tmp"
 55+
 56+ file = open(tempFilename, "wt")
5357 file.write(text)
5458 file.close()
 59+
 60+ # This may fail across filesystems or on Windows.
 61+ # Of course nothing else will work on Windows. ;)
 62+ os.rename(tempFilename, filename)
5563
5664 def readFile(filename):
5765 file = open(filename, "r")
Index: trunk/backup/monitor.py
@@ -30,9 +30,7 @@
3131
3232 def updateIndex():
3333 outputFileName = os.path.join(config.publicDir, config.index)
34 - outputFile = open(outputFileName, "w")
35 - outputFile.write(generateIndex())
36 - outputFile.close()
 34+ WikiDump.dumpFile(outputFileName, generateIndex())
3735
3836 if __name__ == "__main__":
3937 updateIndex()

Status & tagging log