pkgtools

morpheus pkg tools
git clone git://git.2f30.org/pkgtools
Log | Files | Refs | README | LICENSE

commit 70161c217480b17010068cb7050d5441d487d166
parent a481a96a344e1d9ea76c4e76fefd3846eac142cf
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 20 Jun 2014 14:50:38 +0200

rejmatch: match on file from package, allow comments

rejmatch:
  - match on file from package, skip "." if "./" prefix.
  - allow comments (start with #).
  - ignore empty lines.

also some style consistencies.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Mdb.c | 12+++++++++---
Meprintf.c | 2+-
Minstallpkg.c | 3+--
Mremovepkg.c | 3+--
4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/db.c b/db.c @@ -47,7 +47,7 @@ dbinit(const char *prefix) db = emalloc(sizeof(*db)); db->head = NULL; - if(!realpath(prefix, db->prefix)) { + if (!realpath(prefix, db->prefix)) { weprintf("realpath %s:", prefix); free(db); return NULL; @@ -680,6 +680,10 @@ rejmatch(struct db *db, const char *file) int match = 0, r; regex_t preg; + /* Skip initial '.' of "./" */ + if (strncmp(file, "./", 2) == 0) + file++; + estrlcpy(rejpath, db->prefix, sizeof(rejpath)); estrlcat(rejpath, "/etc/pkgtools/reject.conf", sizeof(rejpath)); @@ -687,10 +691,12 @@ rejmatch(struct db *db, const char *file) return -1; while ((len = getline(&buf, &sz, fp)) != -1) { + if (!len || buf[0] == '#' || buf[0] == '\n') + continue; /* skip empty lines and comments. */ if (len > 0 && buf[len - 1] == '\n') buf[len - 1] = '\0'; - /* Skip initial './' */ - r = regcomp(&preg, buf + 2, REG_NOSUB | REG_EXTENDED); + + r = regcomp(&preg, buf, REG_NOSUB | REG_EXTENDED); if (r != 0) { regerror(r, &preg, buf, len); weprintf("invalid pattern: %s\n", buf); diff --git a/eprintf.c b/eprintf.c @@ -34,7 +34,7 @@ venprintf(int status, const char *fmt, va_list ap) { vfprintf(stderr, fmt, ap); - if(fmt[0] && fmt[strlen(fmt)-1] == ':') { + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { fputc(' ', stderr); perror(NULL); } diff --git a/installpkg.c b/installpkg.c @@ -24,8 +24,7 @@ main(int argc, char *argv[]) struct db *db; char path[PATH_MAX]; char *prefix = "/"; - int r; - int i; + int i, r; ARGBEGIN { case 'v': diff --git a/removepkg.c b/removepkg.c @@ -24,8 +24,7 @@ main(int argc, char *argv[]) { struct db *db; char *prefix = "/"; - int r; - int i; + int i, r; ARGBEGIN { case 'v':