[yum-cvs] yum/yum misc.py,1.10,1.11

Seth Vidal skvidal at login.linux.duke.edu
Thu Jun 23 04:54:52 UTC 2005


Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv10179/yum

Modified Files:
	misc.py 
Log Message:

make tmpdir be an option to pass into getCacheDir()


Index: misc.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/misc.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- misc.py	26 Feb 2005 09:11:56 -0000	1.10
+++ misc.py	23 Jun 2005 04:54:50 -0000	1.11
@@ -7,9 +7,13 @@
 import struct
 import re
 import pgpmsg
+import tempfile
+import glob
 import rpm
-import rpmUtils
+import pwd
+from stat import *
 
+import rpmUtils
 from Errors import MiscError
 
 ###########
@@ -254,3 +258,28 @@
                 return 2
 
     return -1
+
+def getCacheDir(tmpdir='/var/tmp'):
+    """return a path to a valid and safe cachedir - only used when not running
+       as root or when --tempcache is set"""
+    
+    uid = os.geteuid()
+    try:
+        usertup = pwd.getpwuid(uid)
+        username = usertup[0]
+    except KeyError:
+        return None # if it returns None then, well, it's bollocksed
+
+    # check for /var/tmp/yum-username-* - 
+    prefix = 'yum-%s-' % username    
+    dirpath = '%s/%s*' % (tmpdir, prefix)
+    cachedirs = glob.glob(dirpath)
+    
+    for thisdir in cachedirs:
+        stats = os.lstat(thisdir)
+        if S_ISDIR(stats[0]) and S_IMODE(stats[0]) == 448 and stats[4] == uid:
+            return thisdir
+
+    # make the dir (tempfile.mkdtemp())
+    cachedir = tempfile.mkdtemp(prefix=prefix, dir=tmpdir)
+    return cachedir




More information about the Yum-cvs-commits mailing list