Lines 9-14
from portage.cache import cache_errors
Link Here
|
9 |
import errno |
9 |
import errno |
10 |
import stat |
10 |
import stat |
11 |
import sys |
11 |
import sys |
|
|
12 |
import os as _os |
12 |
from portage import os |
13 |
from portage import os |
13 |
from portage import _encodings |
14 |
from portage import _encodings |
14 |
from portage import _unicode_encode |
15 |
from portage import _unicode_encode |
Lines 32-64
class database(fs_template.FsBased):
Link Here
|
32 |
self._ensure_dirs() |
33 |
self._ensure_dirs() |
33 |
|
34 |
|
34 |
def _getitem(self, cpv): |
35 |
def _getitem(self, cpv): |
35 |
fp = os.path.join(self.location, cpv) |
36 |
fp = self.location + _os.sep + cpv |
36 |
try: |
37 |
try: |
37 |
myf = codecs.open(_unicode_encode(fp, |
38 |
myf = codecs.open(_unicode_encode(fp, |
38 |
encoding=_encodings['fs'], errors='strict'), |
39 |
encoding=_encodings['fs'], errors='strict'), |
39 |
mode='r', encoding=_encodings['repo.content'], |
40 |
mode='r', encoding=_encodings['repo.content'], |
40 |
errors='replace') |
41 |
errors='replace') |
41 |
try: |
42 |
try: |
42 |
d = self._parse_data(myf.readlines(), cpv) |
43 |
d = self._parse_data(myf.read().split("\n"), cpv) |
43 |
if '_mtime_' not in d: |
44 |
if '_mtime_' not in d: |
44 |
# Backward compatibility with old cache |
45 |
# Backward compatibility with old cache |
45 |
# that uses mtime mangling. |
46 |
# that uses mtime mangling. |
46 |
d['_mtime_'] = long(os.fstat(myf.fileno()).st_mtime) |
47 |
d['_mtime_'] = long(_os.fstat(myf.fileno()).st_mtime) |
47 |
return d |
48 |
return d |
48 |
finally: |
49 |
finally: |
49 |
myf.close() |
50 |
myf.close() |
50 |
except (IOError, OSError) as e: |
51 |
except (IOError, OSError) as e: |
51 |
if e.errno != errno.ENOENT: |
52 |
if e.errno != errno.ENOENT: |
52 |
raise cache_errors.CacheCorruption(cpv, e) |
53 |
raise cache_errors.CacheCorruption(cpv, e) |
53 |
raise KeyError(cpv) |
54 |
raise KeyError(cpv, e) |
54 |
|
55 |
|
55 |
def _parse_data(self, data, cpv): |
56 |
def _parse_data(self, data, cpv): |
56 |
try: |
57 |
try: |
57 |
d = dict(map(lambda x:x.rstrip("\n").split("=", 1), data)) |
58 |
return dict( x.split("=", 1) for x in data ) |
58 |
except ValueError as e: |
59 |
except ValueError as e: |
59 |
# If a line is missing an "=", the split length is 1 instead of 2. |
60 |
# If a line is missing an "=", the split length is 1 instead of 2. |
60 |
raise cache_errors.CacheCorruption(cpv, e) |
61 |
raise cache_errors.CacheCorruption(cpv, e) |
61 |
return d |
|
|
62 |
|
62 |
|
63 |
def _setitem(self, cpv, values): |
63 |
def _setitem(self, cpv, values): |
64 |
# import pdb;pdb.set_trace() |
64 |
# import pdb;pdb.set_trace() |
Lines 101-107
class database(fs_template.FsBased):
Link Here
|
101 |
os.remove(fp) |
101 |
os.remove(fp) |
102 |
raise cache_errors.CacheCorruption(cpv, e) |
102 |
raise cache_errors.CacheCorruption(cpv, e) |
103 |
|
103 |
|
104 |
|
|
|
105 |
def _delitem(self, cpv): |
104 |
def _delitem(self, cpv): |
106 |
# import pdb;pdb.set_trace() |
105 |
# import pdb;pdb.set_trace() |
107 |
try: |
106 |
try: |
Lines 112-122
class database(fs_template.FsBased):
Link Here
|
112 |
else: |
111 |
else: |
113 |
raise cache_errors.CacheCorruption(cpv, e) |
112 |
raise cache_errors.CacheCorruption(cpv, e) |
114 |
|
113 |
|
115 |
|
|
|
116 |
def __contains__(self, cpv): |
114 |
def __contains__(self, cpv): |
117 |
return os.path.exists(os.path.join(self.location, cpv)) |
115 |
return os.path.exists(os.path.join(self.location, cpv)) |
118 |
|
116 |
|
119 |
|
|
|
120 |
def __iter__(self): |
117 |
def __iter__(self): |
121 |
"""generator for walking the dir struct""" |
118 |
"""generator for walking the dir struct""" |
122 |
dirs = [self.location] |
119 |
dirs = [self.location] |
Lines 140-143
class database(fs_template.FsBased):
Link Here
|
140 |
continue |
137 |
continue |
141 |
yield p[len_base+1:] |
138 |
yield p[len_base+1:] |
142 |
dirs.pop(0) |
139 |
dirs.pop(0) |
143 |
|
|
|