mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #1172 from benoitc/fix/1171
don't check if a file is writable using os.stat
This commit is contained in:
commit
f6b172dfec
@ -338,9 +338,13 @@ class Logger(object):
|
|||||||
util.check_is_writeable(output)
|
util.check_is_writeable(output)
|
||||||
h = logging.FileHandler(output)
|
h = logging.FileHandler(output)
|
||||||
# make sure the user can reopen the file
|
# make sure the user can reopen the file
|
||||||
if not util.is_writable(h.baseFilename, self.cfg.user,
|
try:
|
||||||
self.cfg.group):
|
|
||||||
os.chown(h.baseFilename, self.cfg.user, self.cfg.group)
|
os.chown(h.baseFilename, self.cfg.user, self.cfg.group)
|
||||||
|
except OSError:
|
||||||
|
# it's probably OK there, we assume the user has given
|
||||||
|
# /dev/null as a parameter.
|
||||||
|
pass
|
||||||
|
|
||||||
h.setFormatter(fmt)
|
h.setFormatter(fmt)
|
||||||
h._gunicorn = True
|
h._gunicorn = True
|
||||||
log.addHandler(h)
|
log.addHandler(h)
|
||||||
|
|||||||
@ -162,21 +162,6 @@ def chown(path, uid, gid):
|
|||||||
gid = abs(gid) & 0x7FFFFFFF # see note above.
|
gid = abs(gid) & 0x7FFFFFFF # see note above.
|
||||||
os.chown(path, uid, gid)
|
os.chown(path, uid, gid)
|
||||||
|
|
||||||
def is_writable(path, uid, gid):
|
|
||||||
gid = abs(gid) & 0x7FFFFFFF
|
|
||||||
st = os.stat(path)
|
|
||||||
|
|
||||||
if st.st_uid == uid:
|
|
||||||
return st.st_mode & st.S_IWUSR != 0
|
|
||||||
|
|
||||||
user = pwd.getpwuid(uid)[0]
|
|
||||||
groups = [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]
|
|
||||||
groups.append(gid)
|
|
||||||
|
|
||||||
if st.st_gid in groups:
|
|
||||||
return st.st_mode & stat.S_IWGRP != 0
|
|
||||||
|
|
||||||
return st.st_mode & stat.S_IWOTH != 0
|
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
def _waitfor(func, pathname, waitall=False):
|
def _waitfor(func, pathname, waitall=False):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user