[issue6074] .pyc files created readonly if .py file is readonly, python won't overwrite
Peter Simanyi
report at bugs.python.org
Wed May 27 00:17:25 CEST 2009
Peter Simanyi <psimanyi at namcobandaigames.com> added the comment:
I have a fix for this. The code is Windows-only. It has been verified to work for attached test script
showpycreadonlysleep.sh. It simply adds a "chmod" call. The issue is that the unlink() call silently fails
if the file is readonly, but unlink() succeeds if chmod() makes the file writable.
Out company would really appreciate having this fix integrated into 2.6 since we use the ActiveState 2.6
builds on Windows. I haven't test this on non-Windows platforms but it should not change the behavior on
non-Windows platforms if the #ifdef MS_WINDOWS is correct. The diff is below:
$ svn diff
Index: import.c
===================================================================
--- import.c (revision 72946)
+++ import.c (working copy)
@@ -840,6 +840,7 @@
static FILE *
open_exclusive(char *filename, mode_t mode)
{
+
#if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC)
/* Use O_EXCL to avoid a race condition when another process tries to
write the same file. When that happens, our open() call fails,
@@ -848,6 +849,9 @@
writable, the file will never be written. Oh well.
*/
int fd;
+#ifdef MS_WINDOWS
+ (void) chmod(filename, 0600);
+#endif
(void) unlink(filename);
fd = open(filename, O_EXCL|O_CREAT|O_WRONLY|O_TRUNC
#ifdef O_BINARY
It may be appropriate to document that the chmod() is only required on Windows, and therefore it is only
called on Windows to avoid slowing down non-Windows platforms.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6074>
_______________________________________
More information about the Python-bugs-list
mailing list