pkgsrc-Changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
CVS commit: pkgsrc/pkgtools/pkg_install/files/admin
Module Name: pkgsrc
Committed By: wiz
Date: Tue Feb 18 12:04:31 UTC 2025
Modified Files:
pkgsrc/pkgtools/pkg_install/files/admin: admin.h check.c main.c
Log Message:
pkg_install: Improve "pkg_admin check" output.
>From Jonathan Perkin <jperkin%smartos.org@localhost>
via drecklypkg commit $593bfda6864a76d5e8eb4774c27d9babee38d425
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 pkgsrc/pkgtools/pkg_install/files/admin/admin.h
cvs rdiff -u -r1.12 -r1.13 pkgsrc/pkgtools/pkg_install/files/admin/check.c
cvs rdiff -u -r1.71 -r1.72 pkgsrc/pkgtools/pkg_install/files/admin/main.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: pkgsrc/pkgtools/pkg_install/files/admin/admin.h
diff -u pkgsrc/pkgtools/pkg_install/files/admin/admin.h:1.6 pkgsrc/pkgtools/pkg_install/files/admin/admin.h:1.7
--- pkgsrc/pkgtools/pkg_install/files/admin/admin.h:1.6 Mon Feb 2 12:35:00 2009
+++ pkgsrc/pkgtools/pkg_install/files/admin/admin.h Tue Feb 18 12:04:31 2025
@@ -27,7 +27,7 @@
extern int quiet;
extern int verbose;
-void check(char **);
+int check(char **);
void audit_pkgdb(int, char **);
void audit_pkg(int, char **);
Index: pkgsrc/pkgtools/pkg_install/files/admin/check.c
diff -u pkgsrc/pkgtools/pkg_install/files/admin/check.c:1.12 pkgsrc/pkgtools/pkg_install/files/admin/check.c:1.13
--- pkgsrc/pkgtools/pkg_install/files/admin/check.c:1.12 Wed Dec 2 10:45:47 2020
+++ pkgsrc/pkgtools/pkg_install/files/admin/check.c Tue Feb 18 12:04:31 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: check.c,v 1.12 2020/12/02 10:45:47 wiz Exp $ */
+/* $NetBSD: check.c,v 1.13 2025/02/18 12:04:31 wiz Exp $ */
#ifdef HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
@@ -11,7 +11,7 @@
#include <sys/cdefs.h>
#endif
#endif
-__RCSID("$NetBSD: check.c,v 1.12 2020/12/02 10:45:47 wiz Exp $");
+__RCSID("$NetBSD: check.c,v 1.13 2025/02/18 12:04:31 wiz Exp $");
/*-
* Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
@@ -83,12 +83,13 @@ static int checkpattern_fn(const char *,
/*
* Assumes CWD is in the database directory ($PREFIX/pkgdb/<pkg>)!
*/
-static void
+static int
check1pkg(const char *pkgdir, int *filecnt, int *pkgcnt)
{
FILE *f;
plist_t *p;
package_t Plist;
+ int rv = 0;
char *PkgName, *dirp = NULL, *md5file;
char file[MaxPathSize];
char *content;
@@ -120,8 +121,10 @@ check1pkg(const char *pkgdir, int *filec
if (strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) {
if ((md5file = MD5File(file, NULL)) != NULL) {
/* Mismatch? */
- if (strcmp(md5file, p->next->name + ChecksumHeaderLen) != 0)
- printf("%s fails MD5 checksum\n", file);
+ if (strcmp(md5file, p->next->name + ChecksumHeaderLen) != 0) {
+ fprintf(stderr, "%s fails MD5 checksum\n", file);
+ rv = 1;
+ }
free(md5file);
}
@@ -133,11 +136,13 @@ check1pkg(const char *pkgdir, int *filec
if ((cc = readlink(file, &buf[SymlinkHeaderLen],
sizeof(buf) - SymlinkHeaderLen - 1)) < 0) {
warnx("can't readlink `%s'", file);
+ rv = 1;
} else {
buf[SymlinkHeaderLen + cc] = 0x0;
if (strcmp(buf, p->next->name) != 0) {
- printf("symlink (%s) is not same as recorded value, %s: %s\n",
+ fprintf(stderr, "symlink (%s) is not same as recorded value, %s: %s\n",
file, buf, p->next->name);
+ rv = 1;
}
}
}
@@ -146,8 +151,10 @@ check1pkg(const char *pkgdir, int *filec
(*filecnt)++;
} else if (isbrokenlink(file)) {
warnx("%s: Symlink `%s' exists and is in %s but target does not exist!", PkgName, file, CONTENTS_FNAME);
+ rv = 1;
} else {
warnx("%s: File `%s' is in %s but not on filesystem!", PkgName, file, CONTENTS_FNAME);
+ rv = 1;
}
break;
case PLIST_CWD:
@@ -181,11 +188,14 @@ check1pkg(const char *pkgdir, int *filec
free_plist(&Plist);
fclose(f);
(*pkgcnt)++;
+
+ return rv;
}
struct checkpattern_arg {
int filecnt;
int pkgcnt;
+ int errcnt;
int got_match;
};
@@ -194,16 +204,15 @@ checkpattern_fn(const char *pkg, void *v
{
struct checkpattern_arg *arg = vp;
- check1pkg(pkg, &arg->filecnt, &arg->pkgcnt);
- if (!quiet)
- printf(".");
+ if (check1pkg(pkg, &arg->filecnt, &arg->pkgcnt) != 0)
+ arg->errcnt++;
arg->got_match = 1;
return 0;
}
-static void
+static int
check_pkg(const char *pkg, int *filecnt, int *pkgcnt, int allow_unmatched)
{
struct checkpattern_arg arg;
@@ -211,6 +220,7 @@ check_pkg(const char *pkg, int *filecnt,
arg.filecnt = *filecnt;
arg.pkgcnt = *pkgcnt;
+ arg.errcnt = 0;
arg.got_match = 0;
if (match_installed_pkgs(pkg, checkpattern_fn, &arg) == -1)
@@ -218,12 +228,12 @@ check_pkg(const char *pkg, int *filecnt,
if (arg.got_match != 0) {
*filecnt = arg.filecnt;
*pkgcnt = arg.pkgcnt;
- return;
+ return (arg.errcnt) ? 1 : 0;
}
if (ispkgpattern(pkg)) {
if (allow_unmatched)
- return;
+ return 0;
errx(EXIT_FAILURE, "No matching pkg for %s.", pkg);
}
@@ -238,26 +248,31 @@ check_pkg(const char *pkg, int *filecnt,
*filecnt = arg.filecnt;
*pkgcnt = arg.pkgcnt;
+
+ return (arg.errcnt) ? 1 : 0;
}
-void
+int
check(char **argv)
{
- int filecnt, pkgcnt;
+ int filecnt, pkgcnt, errcnt = 0;
filecnt = 0;
pkgcnt = 0;
setbuf(stdout, NULL);
if (*argv == NULL) {
- check_pkg("*", &filecnt, &pkgcnt, 1);
+ errcnt += check_pkg("*", &filecnt, &pkgcnt, 1);
} else {
for (; *argv != NULL; ++argv)
- check_pkg(*argv, &filecnt, &pkgcnt, 0);
+ errcnt += check_pkg(*argv, &filecnt, &pkgcnt, 0);
+ }
+
+ if (!quiet) {
+ printf("Checked %d file%s from %d package%s.\n",
+ filecnt, (filecnt == 1) ? "" : "s",
+ pkgcnt, (pkgcnt == 1) ? "" : "s");
}
- printf("\n");
- printf("Checked %d file%s from %d package%s.\n",
- filecnt, (filecnt == 1) ? "" : "s",
- pkgcnt, (pkgcnt == 1) ? "" : "s");
+ return (errcnt) ? 1: 0;
}
Index: pkgsrc/pkgtools/pkg_install/files/admin/main.c
diff -u pkgsrc/pkgtools/pkg_install/files/admin/main.c:1.71 pkgsrc/pkgtools/pkg_install/files/admin/main.c:1.72
--- pkgsrc/pkgtools/pkg_install/files/admin/main.c:1.71 Thu Mar 7 12:25:43 2024
+++ pkgsrc/pkgtools/pkg_install/files/admin/main.c Tue Feb 18 12:04:31 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.71 2024/03/07 12:25:43 jperkin Exp $ */
+/* $NetBSD: main.c,v 1.72 2025/02/18 12:04:31 wiz Exp $ */
#ifdef HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
@@ -11,7 +11,7 @@
#include <sys/cdefs.h>
#endif
#endif
-__RCSID("$NetBSD: main.c,v 1.71 2024/03/07 12:25:43 jperkin Exp $");
+__RCSID("$NetBSD: main.c,v 1.72 2025/02/18 12:04:31 wiz Exp $");
/*-
* Copyright (c) 1999-2019 The NetBSD Foundation, Inc.
@@ -512,7 +512,7 @@ main(int argc, char *argv[])
char lsdir[MaxPathSize];
char sfx[MaxPathSize];
char *lsdirp = NULL;
- int ch;
+ int ch, rv;
setprogname(argv[0]);
@@ -621,12 +621,14 @@ main(int argc, char *argv[])
argv++; /* "check" */
check_pkgdb();
- check(argv);
+ rv = check(argv);
if (!quiet) {
printf("Done.\n");
}
+ return rv;
+
} else if (strcasecmp(argv[0], "lsall") == 0) {
argv++; /* "lsall" */
Home |
Main Index |
Thread Index |
Old Index