os.utime() Operation not permitted

1,632 views
Skip to first unread message

Dirk Makowski

unread,
Jun 7, 2011, 1:16:58 PM6/7/11
to mod...@googlegroups.com
Hi all,

from a Pyramid webapp I'd like to set the modification time of a file with "os.utime()". But apache throws this error
OSError: [Errno 1] Operation not permitted
The file has set permissions to 666, so even world may read/write it, so should Apache.
(Running the same app with Pyramid's built-in web server works well.)
Thanks in advance.

KR, Dirk

Damjan

unread,
Jun 7, 2011, 1:30:59 PM6/7/11
to modwsgi
> from a Pyramid webapp I'd like to set the modification time of a file with
> "os.utime()". But apache throws this error
> OSError: [Errno 1] Operation not permitted
> The file has set permissions to 666, so even world may read/write it, so
> should Apache.

When changing permissions, it's the permissions on the containing
directory which are important.

--
damjan

Dirk Makowski

unread,
Jun 7, 2011, 2:22:27 PM6/7/11
to mod...@googlegroups.com
The containing directory, up to its grand-father, is 777.

KR, Dirk

Graham Dumpleton

unread,
Jun 7, 2011, 7:52:44 PM6/7/11
to mod...@googlegroups.com
On 8 June 2011 02:22, Dirk Makowski <dirk.m...@googlemail.com> wrote:
> The containing directory, up to its grand-father, is 777.
> KR, Dirk

If not hard wired, try printing out the arguments supplied to
os.utime() at time call being made to make sure valid. Ensure the path
is actually absolute and not relative as working directory under
Apache could be anything. Also print out os.geteuid() and os.getgid()
to make sure they are what you think they should be. If on a Linux box
see if SELinux extensions enabled.

Graham

Dirk Makowski

unread,
Jun 7, 2011, 9:13:45 PM6/7/11
to mod...@googlegroups.com
Yes, path is absolute, no SELinux enabled, and the accessing process is apache - as expected. But since permissions allow read/write for world, the latter should not matter.
I actually do this:
    si = os.stat(fn)
    fn_txt = re.sub(r'\.yaml$', '.txt', fn)
    si_txt = os.stat(fn_txt)
    #print fn, si.st_mtime, fn_txt, si_txt.st_mtime
    #print os.geteuid(), os.getgid()
    if si.st_mtime < si_txt.st_mtime:
        # set file's mtime, keep its ctime
        #os.utime(fn, (si.st_ctime, si_txt.st_mtime) )
        # xxx st_mtime is read-only attribute xxx si.st_mtime = si_txt.st_mtime
        # re-read stat
        si = os.stat(fn)
If mtime of a *.txt file is newer than that of corresponding *.yaml file, change mtime of yaml file. Still have no clue why it fails.

Dirk
Reply all
Reply to author
Forward
0 new messages