From: Zac Medico Date: Wed, 26 Sep 2007 04:19:04 +0000 (-0000) Subject: Use ensure_dirs() and apply_permissions() to avoid redundant X-Git-Tag: v2.1.3.16~126 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=100fdc5db0d85916bebe1313916931f00cb3fc77;p=portage.git Use ensure_dirs() and apply_permissions() to avoid redundant chown/chmod calls. This helps avoid 'Permission denied' errors during elog_process() when the ebuild command is run by normal user (issue reported by graaff). (trunk r7789) svn path=/main/branches/2.1.2/; revision=7820 --- diff --git a/pym/elog_modules/mod_save.py b/pym/elog_modules/mod_save.py index 4e1cd2cf8..97213e040 100644 --- a/pym/elog_modules/mod_save.py +++ b/pym/elog_modules/mod_save.py @@ -1,5 +1,6 @@ import os, time from portage_data import portage_uid, portage_gid +from portage_util import ensure_dirs def process(mysettings, cpv, logentries, fulltext): cpv_path = cpv.replace("/", ":") @@ -8,10 +9,7 @@ def process(mysettings, cpv, logentries, fulltext): elogdir = os.path.join(mysettings["PORT_LOGDIR"], "elog") else: elogdir = os.path.join(os.sep, "var", "log", "portage", "elog") - if not os.path.exists(elogdir): - os.makedirs(elogdir) - os.chown(elogdir, portage_uid, portage_gid) - os.chmod(elogdir, 02770) + ensure_dirs(elogdir, uid=portage_uid, gid=portage_gid, mode=02770) elogfilename = elogdir+"/"+cpv_path+":"+time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time()))+".log" elogfile = open(elogfilename, "w") diff --git a/pym/elog_modules/mod_save_summary.py b/pym/elog_modules/mod_save_summary.py index 7cb310d95..7dbfc03cc 100644 --- a/pym/elog_modules/mod_save_summary.py +++ b/pym/elog_modules/mod_save_summary.py @@ -1,19 +1,18 @@ import os, time from portage_data import portage_uid, portage_gid +from portage_util import ensure_dirs, apply_permissions def process(mysettings, cpv, logentries, fulltext): if mysettings["PORT_LOGDIR"] != "": elogdir = os.path.join(mysettings["PORT_LOGDIR"], "elog") else: elogdir = os.path.join(os.sep, "var", "log", "portage", "elog") - if not os.path.exists(elogdir): - os.makedirs(elogdir) - os.chown(elogdir, portage_uid, portage_gid) - os.chmod(elogdir, 02770) + ensure_dirs(elogdir, uid=portage_uid, gid=portage_gid, mode=02770) # TODO: Locking elogfilename = elogdir+"/summary.log" elogfile = open(elogfilename, "a") + apply_permissions(elogfilename, mode=060, mask=0) elogfile.write(">>> Messages generated by process %d on %s for package %s:\n\n" % \ (os.getpid(), time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time())), cpv)) elogfile.write(fulltext)