summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-10-29 05:22:39 +0000
committerZac Medico <zmedico@gentoo.org>2007-10-29 05:22:39 +0000
commit1486f1b6e33d7b29d39660fdd873fac796944430 (patch)
tree231393cbc4075e2b997996feb3e0fddd5c8f6807 /pym
parent58ae97c54525b1572f2c96ad81f28bca69b8edc2 (diff)
downloadportage-1486f1b6e33d7b29d39660fdd873fac796944430.tar.gz
portage-1486f1b6e33d7b29d39660fdd873fac796944430.tar.bz2
portage-1486f1b6e33d7b29d39660fdd873fac796944430.zip
Rewrite the dblink.getcontents() code to use str.split(" ")
for splitting CONTENTS lines so that even file paths that end with spaces can be handled. This patch makes the fix for bug #196836#c6 more complete. Some code for parsing old malformed symlink entries has been removed sinces it's probably not useful or worth maintaining anymore. svn path=/main/trunk/; revision=8337
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dbapi/vartree.py72
1 files changed, 37 insertions, 35 deletions
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index abc557583..6c10b7866 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -970,23 +970,38 @@ class dblink(object):
"file, line %d: '%s'\n" % (pos, contents_file),
noiselevel=-1)
continue
- mydat = line.split()
- correct_split_count = None
- if mydat:
- correct_split_count = contents_split_counts.get(mydat[0])
- if correct_split_count and len(mydat) != correct_split_count:
- if mydat[0] == "obj" and \
- len(mydat) > contents_split_counts["obj"]:
- # File name contains spaces. Use field widths to infer the
- # start and end points so that even multiple consecutive
- # spaces are parsed correctly.
- newsplit = ["obj"]
- filename_start = len(mydat[0]) + 1
- filename_end = len(line.rstrip()) - \
- len(mydat[-1]) - len(mydat[-2]) - 2
- newsplit.append(line[filename_start:filename_end])
- newsplit.extend(mydat[-2:])
- mydat = newsplit
+ if line.endswith("\n"):
+ line = line[:-1]
+ # Split on " " so that even file paths that
+ # end with spaces can be handled.
+ mydat = line.split(" ")
+ entry_type = mydat[0] # empty string if line is empty
+ correct_split_count = contents_split_counts.get(entry_type)
+ if correct_split_count and len(mydat) > correct_split_count:
+ # Apparently file paths contain spaces, so reassemble
+ # the split have the correct_split_count.
+ newsplit = [entry_type]
+ spaces_total = len(mydat) - correct_split_count
+ if entry_type == "sym":
+ try:
+ splitter = mydat.index("->", 2, len(mydat) - 2)
+ except ValueError:
+ writemsg("!!! Unrecognized CONTENTS entry on " + \
+ "line %d: '%s'\n" % (pos, line), noiselevel=-1)
+ continue
+ spaces_in_path = splitter - 2
+ spaces_in_target = spaces_total - spaces_in_path
+ newsplit.append(" ".join(mydat[1:splitter]))
+ newsplit.append("->")
+ target_end = splitter + spaces_in_target + 2
+ newsplit.append(" ".join(mydat[splitter + 1:target_end]))
+ newsplit.extend(mydat[target_end:])
+ else:
+ path_end = spaces_total + 2
+ newsplit.append(" ".join(mydat[1:path_end]))
+ newsplit.extend(mydat[path_end:])
+ mydat = newsplit
+
# we do this so we can remove from non-root filesystems
# (use the ROOT var to allow maintenance on other partitions)
try:
@@ -998,32 +1013,19 @@ class dblink(object):
mydat[1] = os.path.join(myroot, mydat[1].lstrip(os.path.sep))
if mydat[0] == "obj":
#format: type, mtime, md5sum
- pkgfiles[mydat[1]] = [mydat[0], mydat[-1], mydat[-2]]
+ pkgfiles[mydat[1]] = [mydat[0], mydat[3], mydat[2]]
elif mydat[0] == "dir":
#format: type
- pkgfiles[" ".join(mydat[1:])] = [mydat[0] ]
+ pkgfiles[mydat[1]] = [mydat[0]]
elif mydat[0] == "sym":
#format: type, mtime, dest
- x = len(mydat) - 1
- if (x >= 13) and (mydat[-1][-1] == ')'): # Old/Broken symlink entry
- mydat = mydat[:-10] + [mydat[-10:][stat.ST_MTIME][:-1]]
- writemsg("FIXED SYMLINK LINE: %s\n" % mydat, 1)
- x = len(mydat) - 1
- splitter = -1
- while (x >= 0):
- if mydat[x] == "->":
- splitter = x
- break
- x = x - 1
- if splitter == -1:
- return None
- pkgfiles[" ".join(mydat[1:splitter])] = [mydat[0], mydat[-1], " ".join(mydat[(splitter+1):-1])]
+ pkgfiles[mydat[1]] = [mydat[0], mydat[4], mydat[3]]
elif mydat[0] == "dev":
#format: type
- pkgfiles[" ".join(mydat[1:])] = [mydat[0] ]
+ pkgfiles[mydat[1]] = [mydat[0]]
elif mydat[0]=="fif":
#format: type
- pkgfiles[" ".join(mydat[1:])] = [mydat[0]]
+ pkgfiles[mydat[1]] = [mydat[0]]
else:
writemsg("!!! Unrecognized CONTENTS entry on " + \
"line %d: '%s'\n" % (pos, line), noiselevel=-1)