aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'portage_with_autodep/pym/portage/update.py')
-rw-r--r--portage_with_autodep/pym/portage/update.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/portage_with_autodep/pym/portage/update.py b/portage_with_autodep/pym/portage/update.py
index 52ab506..34e4663 100644
--- a/portage_with_autodep/pym/portage/update.py
+++ b/portage_with_autodep/pym/portage/update.py
@@ -86,10 +86,11 @@ def fixdbentries(update_iter, dbdir):
mydata = {}
for myfile in [f for f in os.listdir(dbdir) if f not in ignored_dbentries]:
file_path = os.path.join(dbdir, myfile)
- mydata[myfile] = io.open(_unicode_encode(file_path,
+ with io.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
- errors='replace').read()
+ errors='replace') as f:
+ mydata[myfile] = f.read()
updated_items = update_dbentries(update_iter, mydata)
for myfile, mycontent in updated_items.items():
file_path = os.path.join(dbdir, myfile)
@@ -132,10 +133,11 @@ def grab_updates(updpath, prev_mtimes=None):
if update_data or \
file_path not in prev_mtimes or \
long(prev_mtimes[file_path]) != mystat[stat.ST_MTIME]:
- content = io.open(_unicode_encode(file_path,
+ f = io.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['repo.content'], errors='replace'
- ).read()
+ mode='r', encoding=_encodings['repo.content'], errors='replace')
+ content = f.read()
+ f.close()
update_data.append((file_path, mystat, content))
return update_data
@@ -155,6 +157,7 @@ def parse_updates(mycontent):
if len(mysplit) != 3:
errors.append(_("ERROR: Update command invalid '%s'") % myline)
continue
+ valid = True
for i in (1, 2):
try:
atom = Atom(mysplit[i])
@@ -168,7 +171,11 @@ def parse_updates(mycontent):
else:
errors.append(
_("ERROR: Malformed update entry '%s'") % myline)
+ valid = False
break
+ if not valid:
+ continue
+
if mysplit[0] == "slotmove":
if len(mysplit)!=4:
errors.append(_("ERROR: Update command invalid '%s'") % myline)
@@ -252,14 +259,19 @@ def update_config_files(config_root, protect, protect_mask, update_iter, match_c
recursivefiles.append(x)
myxfiles = recursivefiles
for x in myxfiles:
+ f = None
try:
- file_contents[x] = io.open(
+ f = io.open(
_unicode_encode(os.path.join(abs_user_config, x),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'],
- errors='replace').readlines()
+ errors='replace')
+ file_contents[x] = f.readlines()
except IOError:
continue
+ finally:
+ if f is not None:
+ f.close()
# update /etc/portage/packages.*
ignore_line_re = re.compile(r'^#|^\s*$')