man-db/man-db-2.6.1-wildcards.patch

275 lines
7.4 KiB
Diff
Raw Normal View History

diff -upr man-db-2.6.3.orig/src/globbing.c man-db-2.6.3/src/globbing.c
--- man-db-2.6.3.orig/src/globbing.c 2010-09-26 23:08:14.000000000 +0200
+++ man-db-2.6.3/src/globbing.c 2013-03-13 18:18:52.615033484 +0100
@@ -427,3 +427,30 @@ char **look_for_file (const char *hier,
else
return gbuf.gl_pathv;
}
+
+char **expand_path (const char *path)
+{
+ int res = 0;
+ char **result = NULL;
+ glob_t globbuf;
+
+ res = glob (path, 0, NULL, &globbuf);
+ /* if glob failed, return the given path */
+ if (res != 0) {
+ result = (char **) xmalloc (2 * sizeof(char *));
+ result[0] = xstrndup (path, strlen(path));
+ result[1] = NULL;
+ return result;
+ }
+
+ result = (char **) xmalloc ((globbuf.gl_pathc + 1) * sizeof(char *));
+ size_t i;
+ for (i = 0; i < globbuf.gl_pathc; i++) {
+ result[i] = xstrndup (globbuf.gl_pathv[i], strlen (globbuf.gl_pathv[i]));
+ }
+ result[globbuf.gl_pathc] = NULL;
+
+ globfree (&globbuf);
+
+ return result;
+}
diff -upr man-db-2.6.3.orig/src/globbing.h man-db-2.6.3/src/globbing.h
--- man-db-2.6.3.orig/src/globbing.h 2008-12-11 00:06:18.000000000 +0100
+++ man-db-2.6.3/src/globbing.h 2013-03-13 18:18:52.615033484 +0100
@@ -29,3 +29,6 @@ enum look_for_file_opts {
/* globbing.c */
extern char **look_for_file (const char *hier, const char *sec,
const char *unesc_name, int cat, int opts);
+
+/* Expand path with wildcards into list of all existing directories. */
+extern char **expand_path (const char *path);
diff -upr man-db-2.6.3.orig/src/Makefile.am man-db-2.6.3/src/Makefile.am
--- man-db-2.6.3.orig/src/Makefile.am 2012-02-05 14:25:20.000000000 +0100
+++ man-db-2.6.3/src/Makefile.am 2013-03-13 18:18:52.617033454 +0100
@@ -72,6 +72,8 @@ zsoelim_LDADD = $(LIBMAN) $(libpipeline_
accessdb_SOURCES = \
accessdb.c
catman_SOURCES = \
+ globbing.c \
+ globbing.h \
catman.c \
manp.c \
manp.h
@@ -140,10 +142,14 @@ mandb_SOURCES = \
ult_src.c \
ult_src.h
manpath_SOURCES = \
+ globbing.c \
+ globbing.h \
manp.c \
manp.h \
manpath.c
whatis_SOURCES = \
+ globbing.c \
+ globbing.h \
manconv.c \
manconv.h \
manp.c \
diff -upr man-db-2.6.3.orig/src/Makefile.in man-db-2.6.3/src/Makefile.in
--- man-db-2.6.3.orig/src/Makefile.in 2012-09-18 00:34:03.000000000 +0200
+++ man-db-2.6.3/src/Makefile.in 2013-03-13 18:20:57.097203869 +0100
@@ -251,7 +251,7 @@ accessdb_DEPENDENCIES = $(am__DEPENDENCI
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
-am_catman_OBJECTS = catman.$(OBJEXT) manp.$(OBJEXT)
+am_catman_OBJECTS = globbing.$(OBJEXT) catman.$(OBJEXT) manp.$(OBJEXT)
catman_OBJECTS = $(am_catman_OBJECTS)
catman_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_2)
am_globbing_OBJECTS = globbing.$(OBJEXT) globbing_test.$(OBJEXT)
@@ -282,10 +282,10 @@ am_mandb_OBJECTS = check_mandirs.$(OBJEX
mandb_OBJECTS = $(am_mandb_OBJECTS)
mandb_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_2)
-am_manpath_OBJECTS = manp.$(OBJEXT) manpath.$(OBJEXT)
+am_manpath_OBJECTS = globbing.$(OBJEXT) manp.$(OBJEXT) manpath.$(OBJEXT)
manpath_OBJECTS = $(am_manpath_OBJECTS)
manpath_DEPENDENCIES = $(am__DEPENDENCIES_1)
-am_whatis_OBJECTS = manconv.$(OBJEXT) manp.$(OBJEXT) whatis.$(OBJEXT)
+am_whatis_OBJECTS = globbing.$(OBJEXT) manconv.$(OBJEXT) manp.$(OBJEXT) whatis.$(OBJEXT)
whatis_OBJECTS = $(am_whatis_OBJECTS)
whatis_DEPENDENCIES = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_2)
@@ -1339,6 +1339,8 @@ accessdb_SOURCES = \
catman_SOURCES = \
catman.c \
+ globbing.c \
+ globbing.h \
manp.c \
manp.h
@@ -1412,11 +1414,15 @@ mandb_SOURCES = \
ult_src.h
manpath_SOURCES = \
+ globbing.c \
+ globbing.h \
manp.c \
manp.h \
manpath.c
whatis_SOURCES = \
+ globbing.c \
+ globbing.h \
manconv.c \
manconv.h \
manp.c \
diff -upr man-db-2.6.3.orig/src/manp.c man-db-2.6.3/src/manp.c
--- man-db-2.6.3.orig/src/manp.c 2012-02-05 14:18:59.000000000 +0100
+++ man-db-2.6.3/src/manp.c 2013-03-13 18:18:52.652032940 +0100
@@ -75,6 +75,7 @@
#endif
#include "manp.h"
+#include "globbing.h"
struct list {
char *key;
@@ -1035,32 +1036,45 @@ char *get_manpath_from_path (const char
static void add_dir_to_list (char **lp, const char *dir)
{
int status;
- int pos = 0;
-
- while (*lp != NULL) {
- if (pos > MAXDIRS - 1)
- gripe_overlong_list ();
- if (!strcmp (*lp, dir)) {
- debug ("%s is already in the manpath\n", dir);
- return;
+ int pos = 0, i = 0;
+ char *d = NULL;
+ char **expanded_dirs = NULL;
+
+ expanded_dirs = expand_path (dir);
+ for (i = 0; expanded_dirs[i] != NULL; i++) {
+ d = expanded_dirs[i];
+
+ while (*lp != NULL) {
+ if (pos > MAXDIRS - 1)
+ gripe_overlong_list ();
+ if (!strcmp (*lp, d)) {
+ debug ("%s is already in the manpath\n", d);
+ goto done;
+ }
+ lp++;
+ pos++;
}
- lp++;
- pos++;
- }
- /* Not found -- add it. */
+ /* Not found -- add it. */
- status = is_directory (dir);
+ status = is_directory (d);
- if (status < 0)
- gripe_stat_file (dir);
- else if (status == 0)
- gripe_not_directory (dir);
- else if (status == 1) {
- debug ("adding %s to manpath\n", dir);
+ if (status < 0)
+ gripe_stat_file (d);
+ else if (status == 0)
+ gripe_not_directory (d);
+ else if (status == 1) {
+ debug ("adding %s to manpath\n", d);
- *lp = xstrdup (dir);
+ *lp = xstrdup (d);
+ }
}
+
+done:
+ for (i = 0; expanded_dirs[i] != NULL; i++) {
+ free (expanded_dirs[i]);
+ }
+ free (expanded_dirs);
}
/* path does not exist in config file: check to see if path/../man,
@@ -1104,33 +1118,44 @@ static inline char *has_mandir (const ch
static char **add_dir_to_path_list (char **mphead, char **mp, const char *p)
{
- int status;
+ int status, i = 0;
char *cwd;
+ char *d = NULL;
+ char **expanded_dirs = NULL;
if (mp - mphead > MAXDIRS - 1)
gripe_overlong_list ();
- status = is_directory (p);
-
- if (status < 0)
- gripe_stat_file (p);
- else if (status == 0)
- gripe_not_directory (p);
- else {
- /* deal with relative paths */
+ expanded_dirs = expand_path (p);
+ for (i = 0; expanded_dirs[i] != NULL; i++) {
+ d = expanded_dirs[i];
+
+ status = is_directory (d);
+
+ if (status < 0)
+ gripe_stat_file (d);
+ else if (status == 0)
+ gripe_not_directory (d);
+ else {
+ /* deal with relative paths */
+
+ if (*d != '/') {
+ cwd = xgetcwd ();
+ if (!cwd)
+ error (FATAL, errno,
+ _("can't determine current directory"));
+ *mp = appendstr (cwd, "/", d, NULL);
+ } else
+ *mp = xstrdup (d);
- if (*p != '/') {
- cwd = xgetcwd ();
- if (!cwd)
- error (FATAL, errno,
- _("can't determine current directory"));
- *mp = appendstr (cwd, "/", p, NULL);
- } else
- *mp = xstrdup (p);
+ debug ("adding %s to manpathlist\n", *mp);
+ mp++;
+ }
- debug ("adding %s to manpathlist\n", *mp);
- mp++;
+ free (d);
}
+ free (expanded_dirs);
+
return mp;
}
diff -up man-db-2.6.3/src/tests/mandb-3.wildcards man-db-2.6.3/src/tests/mandb-3
--- man-db-2.6.3/src/tests/mandb-3.wildcards 2010-11-14 23:11:27.000000000 +0100
+++ man-db-2.6.3/src/tests/mandb-3 2013-03-18 13:39:23.822367377 +0100
@@ -33,7 +33,7 @@ MANPATH="$tmpdir/usr/share/man" run $MAN
"$tmpdir/usr/share/man"
cat >"$tmpdir/2.exp" <<EOF
test -> "- 1 1 MTIME A - - gz test page"
-testlink -> "- 1 1 MTIME C test - gz "
+testlink -> "- 1 1 MTIME A - - gz link to test page"
EOF
accessdb_filter "$tmpdir/usr/share/man/index$db_ext" >"$tmpdir/2.out"
expect_pass 'broken whatis' 'diff -u "$tmpdir/2.exp" "$tmpdir/2.out"'