Am Samstag, den 24.04.2010, 23:34 +1000 schrieb Allan McRae:
> On 24/04/10 23:15, Allan McRae wrote:
> > On 23/04/10 22:50, Marc - A. Dahlhaus [ Administration | Westermann GmbH
> > ] wrote:
> >> Am Freitag, den 23.04.2010, 19:32 +1000 schrieb Allan McRae:
> >>> On 23/04/10 18:02, Marc - A. Dahlhaus [ Administration | Westermann GmbH
> >>> ] wrote:
> >>>> The include globbing patch. :)
> >>>
> >>> Any chance of a flyspray/mailing list link to the patch?
> >>
> >> Patch:
> >> http://mailman.archlinux.org/pipermail/pacman-dev/2010-March/010550.html
> >>
> >> Original thread:
> >> http://mailman.archlinux.org/pipermail/pacman-dev/2009-September/009355.html
> >>
> >>
> >> Discussion:
> >> http://mailman.archlinux.org/pipermail/pacman-dev/2009-October/009711.html
> >>
> >> http://mailman.archlinux.org/pipermail/pacman-dev/2009-November/010158.html
> >>
> >> http://mailman.archlinux.org/pipermail/pacman-dev/2010-March/010551.html
> >>
> >
> > Thanks. I think I have no objection to this patch... The code is fine, I
> > am just unsure about the use cases. Mind you, with pacman hooks in the
> > future, we might want to have "Include /etc/pacman/hooks/*".
> >
> > One query, does this handle the case where there is nothing in the
> > globbed folder? Is that the GLOB_ABORTED case?
> 
> In fact, it looks like it does not handle that case and it is probably 
> not a good thing if that is struck.  A case GLOB_NOMATCH with just a 
> debug message should be fine.

It handled the GLOB_NOMATCH case silently in the default handler.
But a debug print would help alot eg. on typos in include rules.
You can find an altered version attached.

Thanks for the feadback,

Marc
This patch adds the ability to use Include filenames
containing wildcards.

Added a headercheck for glob.h to configure.ac.
Added a globfree call to clean up the struct properly.
Removed tilde expanding.
Added a GLOB_NOMATCH debug output.

Signed-off-by: Marc-A. Dahlhaus <m...@wol.de>
---

--- pacman-3.3.0.orig/configure.ac
+++ pacman-3.3.0/configure.ac
@@ -150,7 +150,7 @@ fi
 AM_CONDITIONAL(INTERNAL_DOWNLOAD, test "x$internaldownload" = "xyes")
 
 # Checks for header files.
-AC_CHECK_HEADERS([fcntl.h libintl.h limits.h locale.h string.h strings.h sys/ioctl.h sys/param.h sys/statvfs.h sys/syslimits.h sys/time.h syslog.h wchar.h])
+AC_CHECK_HEADERS([fcntl.h glob.h libintl.h limits.h locale.h string.h strings.h sys/ioctl.h sys/param.h sys/statvfs.h sys/syslimits.h sys/time.h syslog.h wchar.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_INLINE
--- pacman-3.3.0.orig/src/pacman/pacman.c
+++ pacman-3.3.0/src/pacman/pacman.c
@@ -38,6 +38,7 @@
 #include <locale.h> /* setlocale */
 #include <time.h> /* time_t */
 #include <errno.h>
+#include <glob.h>
 #if defined(PACMAN_DEBUG) && defined(HAVE_MCHECK_H)
 #include <mcheck.h> /* debug tracing (mtrace) */
 #endif
@@ -814,8 +815,27 @@ static int _parseconfig(const char *file
 			} else {
 				/* directives with settings */
 				if(strcmp(key, "Include") == 0) {
-					pm_printf(PM_LOG_DEBUG, "config: including %s\n", ptr);
-					_parseconfig(ptr, section, db);
+					int globret;
+					glob_t globbuf;
+					globret = glob(ptr, GLOB_NOCHECK, NULL, &globbuf);
+					switch(globret) {
+						case GLOB_NOSPACE:
+							pm_printf(PM_LOG_DEBUG, "config: include globing out of space\n");
+						break;
+						case GLOB_ABORTED:
+							pm_printf(PM_LOG_DEBUG, "config: include globing read error for %s\n", ptr);
+						break;
+						case GLOB_NOMATCH:
+							pm_printf(PM_LOG_DEBUG, "config: include globing found nothing for %s\n", ptr);
+						break;
+						default:
+							for(int gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
+								pm_printf(PM_LOG_DEBUG, "config: including %s\n", globbuf.gl_pathv[gindex]);
+								_parseconfig(globbuf.gl_pathv[gindex], section, db);
+							}
+						break;
+					}
+					globfree(&globbuf);
 					/* Ignore include failures... assume non-critical */
 				} else if(strcmp(section, "options") == 0) {
 					if(strcmp(key, "NoUpgrade") == 0) {


Reply via email to