Use ensure_dirs() and apply_permissions() to avoid redundant
authorZac Medico <zmedico@gentoo.org>
Wed, 26 Sep 2007 04:19:04 +0000 (04:19 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 26 Sep 2007 04:19:04 +0000 (04:19 -0000)
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

pym/elog_modules/mod_save.py
pym/elog_modules/mod_save_summary.py

index 4e1cd2cf8fc384ba95c85a4873602e87dad588b3..97213e040ed94507fb8e9430f712e55a5f0910e3 100644 (file)
@@ -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")
index 7cb310d954a24bf877902bdfbd2669c237941ecf..7dbfc03cceb8ebfd3833d3e6b853af23e221b742 100644 (file)
@@ -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)