commit: 413b207a133f5b40fbd6d8281a92e9cfe9e68eac
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Feb 20 23:55:22 2015 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Feb 20 23:55:22 2015 +0000
URL:
http://sources.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=413b207a
quse: improve handling of desc/ files
Make sure we don't underflow the buffer incase there are random files
in the subdir, and chop the ".desc" from the display.
---
quse.c | 9 ++++++++-
tests/quse/dotest | 4 +++-
tests/quse/list01.good | 4 ++--
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/quse.c b/quse.c
index 825fba3..875733c 100644
--- a/quse.c
+++ b/quse.c
@@ -161,7 +161,11 @@ skip_file:
}
while ((de = readdir(d)) != NULL) {
- if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
+ s = strlen(de->d_name);
+ if (s < 6)
+ continue;
+ p = de->d_name + s - 5;
+ if (strcmp(p, ".desc"))
continue;
snprintf(buf, buflen, "%s/profiles/desc/%s", portdir,
de->d_name);
@@ -170,6 +174,9 @@ skip_file:
continue;
}
+ /* Chop the trailing .desc for better display */
+ *p = '\0';
+
while (getline(&buf, &buflen, fp[0]) != -1) {
if (buf[0] == '#' || buf[0] == '\n')
continue;
diff --git a/tests/quse/dotest b/tests/quse/dotest
index 44fe143..0b204a4 100755
--- a/tests/quse/dotest
+++ b/tests/quse/dotest
@@ -60,7 +60,9 @@ f="$d/desc/elibc.desc"
all=$(entries "$f" | awk '{print $1}')
for x in ${all} ; do
quse -CD $x > x
- sed -n -e "/^$x - /{s|^[^ ]* - | ${f##*/}:$x: |;p}" "$f" > good
+ dispf=${f##*/}
+ dispf=${dispf%.desc}
+ sed -n -e "/^$x - /{s|^[^ ]* - | ${dispf}:$x: |;p}" "$f" > good
cat good >> all.good
diff -u x good
done
diff --git a/tests/quse/list01.good b/tests/quse/list01.good
index 5f4c985..5a2172e 100644
--- a/tests/quse/list01.good
+++ b/tests/quse/list01.good
@@ -1,2 +1,2 @@
- one.desc:abc: cow
- two.desc:abc: pig
+ one:abc: cow
+ two:abc: pig