[issue6074] .pyc files created readonly if .py file is readonly, python won't overwrite

Kevin Chen report at bugs.python.org
Sun Aug 19 14:50:38 CEST 2012


Kevin Chen added the comment:

I propose a fix:

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,
       which is just fine (since it's only a cache).
       XXX If the file exists and is writable but the directory is not
       writable, the file will never be written.  Oh well.
    */
    int fd;
    (void) unlink(filename);
    fd = open(filename, O_EXCL|O_CREAT|O_WRONLY|O_TRUNC
#ifdef O_BINARY
                            |O_BINARY   /* necessary for Windows */
#endif
#ifdef __VMS
            , mode, "ctxt=bin", "shr=nil"
#elif defined(MS_WINDOWS)
			, mode | _S_IWRITE
#else
            , mode
#endif
          );

    if (fd < 0 )
        return NULL;
    return fdopen(fd, "wb");
#else
    /* Best we can do -- on Windows this can't happen anyway */
    return fopen(filename, "wb");
#endif
}

----------------------

so doesn't matter what the .py file permission is under windows, the .pyc file will always have both read and write permissions.

----------
nosy: +lowlifer123

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6074>
_______________________________________


More information about the Python-bugs-list mailing list