/[gentoo-src]/portage/pym/orig_dict_cache.py
Gentoo

Contents of /portage/pym/orig_dict_cache.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download) (as text)
Tue Nov 9 23:20:47 2004 UTC (9 years, 11 months ago) by ferringb
Branch: MAIN
CVS Tags: portage_041204, HEAD
Branch point for: portage_2_1
Changes since 1.6: +7 -14 lines
File MIME type: text/x-python
see changelog.  finished moving all filtering logic into listdir, so that the caching method
is strictly that, caching.  removed EmptyOnError from listdir, it's not used, and is buggy-
first level files won't return None when EmptyOnError=False, w/ recursive anything beyond 1st level would.

Updated listdir calls to remove emptyonerror reference.  It wasn't ever used, if it was (in conjunction with
recursive) it would result in a traceback.

1 #!/usr/bin/python
2 # orig_dict_cache.py; older listdir caching implementation
3 # Copyright 1999-2004 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License v2
5 #$Header: /var/cvsroot/gentoo-src/portage/pym/orig_dict_cache.py,v 1.6 2004/11/09 20:59:26 ferringb Exp $
6
7 """per process caching of os.listdir returns.
8 Symlink unaware, so beware of webs of symlinks"""
9
10 import portage_util, os, stat
11 import portage_file
12
13 dircache = {}
14 cacheHit = 0
15 cacheMiss = 0
16 cacheStale = 0
17
18 def cacheddir(my_original_path):
19 """return results from cache, updating cache if its stale/incomplete"""
20 global cacheHit, cacheMiss, cacheStale, dircache
21 mypath=portage_file.normpath(my_original_path)
22 if dircache.has_key(mypath):
23 cacheHit += 1
24 cached_mtime, list, ftype = dircache[mypath]
25 else:
26 cacheMiss += 1
27 cached_mtime, list, ftype = -1, [], []
28 pathstat = os.stat(mypath)
29 if stat.S_ISDIR(pathstat[stat.ST_MODE]):
30 mtime = pathstat[stat.ST_MTIME]
31 else:
32 raise Exception
33 if mtime != cached_mtime:
34 if dircache.has_key(mypath):
35 cacheStale += 1
36 list = os.listdir(mypath)
37 ftype = []
38 for x in list:
39 try:
40 pathstat = os.lstat(mypath+"/"+x)
41
42 if stat.S_ISREG(pathstat[stat.ST_MODE]):
43 ftype.append(0)
44 elif stat.S_ISDIR(pathstat[stat.ST_MODE]):
45 ftype.append(1)
46 elif stat.S_ISLNK(pathstat[stat.ST_MODE]):
47 pathstat = os.stat(mypath+"/"+x)
48 if stat.S_ISREG(pathstat[stat.ST_MODE]):
49 ftype.append(2)
50 elif stat.S_ISDIR(pathstat[stat.ST_MODE]):
51 ftype.append(3)
52 else:
53 ftype.append(4)
54
55 except SystemExit, e:
56 raise
57 except:
58 ftype.append(3)
59 dircache[mypath] = mtime, list, ftype
60
61 return list[:],ftype[:]
62
63 portage_util.writemsg("cacheddirStats: H:%d/M:%d/S:%d\n" % (cacheHit, cacheMiss, cacheStale),10)
64 return ret_list, ret_ftype

  ViewVC Help
Powered by ViewVC 1.1.20