9000N/A--- Python-2.4.3/Python/import.c.patch6 2006-09-15 14:58:49.716280000 -0400
9000N/A+++ Python-2.4.3/Python/import.c 2006-09-15 15:47:04.381256000 -0400
9000N/A@@ -816,19 +816,28 @@
9000N/A
9000N/A /* Write a compiled module to a file, placing the time of last
9000N/A modification of its source into the header.
9000N/A- Errors are ignored, if a write error occurs an attempt is made to
9000N/A- remove the file. */
9000N/A+ Write to a temporary file first so that creating the file is atomic.
9000N/A+ Errors are ignored, if a write/unlink/rename error occurs an attempt
9000N/A+ is made to remove the temporary file. */
9000N/A
9000N/A static void
9000N/A write_compiled_module(PyCodeObject *co, char *cpathname, long mtime)
9000N/A {
9000N/A FILE *fp;
9000N/A+ char *tmppathname;
9000N/A
9000N/A- fp = open_exclusive(cpathname);
9000N/A+ /* the temporary file is called cpathname + ".tmp" */
9000N/A+ if ((tmppathname = PyMem_Malloc(strlen(cpathname) + strlen(".tmp") + 1))
9000N/A+ == NULL) {
9000N/A+ return;
9000N/A+ }
9000N/A+ sprintf (tmppathname, "%s.tmp", cpathname);
9000N/A+ fp = open_exclusive(tmppathname);
9000N/A if (fp == NULL) {
9000N/A if (Py_VerboseFlag)
9000N/A PySys_WriteStderr(
9000N/A- "# can't create %s\n", cpathname);
9000N/A+ "# can't create %s\n", tmppathname);
9000N/A+ PyMem_Free(tmppathname);
9000N/A return;
9000N/A }
9000N/A PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);
9000N/A@@ -837,10 +846,11 @@
9000N/A PyMarshal_WriteObjectToFile((PyObject *)co, fp, Py_MARSHAL_VERSION);
9000N/A if (fflush(fp) != 0 || ferror(fp)) {
9000N/A if (Py_VerboseFlag)
9000N/A- PySys_WriteStderr("# can't write %s\n", cpathname);
9000N/A+ PySys_WriteStderr("# can't write %s\n", tmppathname);
9000N/A /* Don't keep partial file */
9000N/A fclose(fp);
9000N/A- (void) unlink(cpathname);
9000N/A+ (void) unlink(tmppathname);
9000N/A+ PyMem_Free(tmppathname);
9000N/A return;
9000N/A }
9000N/A /* Now write the true mtime */
9000N/A@@ -848,8 +858,30 @@
9000N/A PyMarshal_WriteLongToFile(mtime, fp, Py_MARSHAL_VERSION);
9000N/A fflush(fp);
9000N/A fclose(fp);
9000N/A+ /* Delete the old compiled file, if exists */
9000N/A+ if (unlink (cpathname)) {
9000N/A+ if ((errno != ENOENT)) {
9000N/A+ /* the file exists but could not be deleted */
9000N/A+ if (Py_VerboseFlag)
9000N/A+ PySys_WriteStderr(
9000N/A+ "# can't unlink %s\n", cpathname);
9000N/A+ (void) unlink(tmppathname);
9000N/A+ PyMem_Free(tmppathname);
9000N/A+ return;
9000N/A+ }
9000N/A+ }
9000N/A+ /* rename the tmp file to the real file name */
9000N/A+ if (rename (tmppathname, cpathname)) {
9000N/A+ if (Py_VerboseFlag)
9000N/A+ PySys_WriteStderr(
9000N/A+ "# can't rename %s to %s\n", tmppathname, cpathname);
9000N/A+ (void) unlink(tmppathname);
9000N/A+ PyMem_Free(tmppathname);
9000N/A+ return;
9000N/A+ }
9000N/A if (Py_VerboseFlag)
9000N/A PySys_WriteStderr("# wrote %s\n", cpathname);
9000N/A+ PyMem_Free(tmppathname);
9000N/A }
9000N/A
9000N/A
9000N/A