Skip to content

Commit cb81082

Browse files
committed
lib: introduce xbps_verbose_printf
like xbps_dbg_printf, but for verbose-only prints to stderr
1 parent 8b9d10f commit cb81082

File tree

7 files changed

+51
-38
lines changed

7 files changed

+51
-38
lines changed

bin/xbps-pkgdb/check.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ check_cb(struct xbps_handle *xhp UNUSED,
5353
int rv;
5454

5555
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
56-
if (xhp->flags & XBPS_FLAG_VERBOSE)
57-
printf("Checking %s ...\n", pkgver);
56+
xbps_verbose_printf("Checking %s ...\n", pkgver);
5857

5958
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
6059
abort();

bin/xbps-rindex/remove-obsoletes.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ index_match_pkgver(xbps_dictionary_t index, const char *pkgname, const char *pkg
101101
}
102102

103103
static int
104-
cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key UNUSED, void *arg, bool *done UNUSED)
104+
cleaner_cb(struct xbps_handle *xhp UNUSED, xbps_object_t obj, const char *key UNUSED, void *arg, bool *done UNUSED)
105105
{
106106
char pkgname[XBPS_NAME_SIZE];
107107
struct xbps_repo *repo = arg;
@@ -115,8 +115,7 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key UNUSED, v
115115
return 0;
116116
}
117117

118-
if (xhp->flags & XBPS_FLAG_VERBOSE)
119-
printf("checking %s (%s)\n", pkgver, binpkg);
118+
xbps_verbose_printf("checking %s (%s)\n", pkgver, binpkg);
120119

121120
if (index_match_pkgver(repo->stage, pkgname, pkgver) ||
122121
index_match_pkgver(repo->index, pkgname, pkgver)) {

bin/xbps-rindex/sign.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ sign_repo(struct xbps_handle *xhp, const char *repodir,
252252
}
253253

254254
static int
255-
sign_pkg(struct xbps_handle *xhp, const char *binpkg, const char *privkey, bool force)
255+
sign_pkg(struct xbps_handle *xhp UNUSED, const char *binpkg, const char *privkey, bool force)
256256
{
257257
RSA *rsa = NULL;
258258
unsigned char *sig = NULL;
@@ -265,8 +265,7 @@ sign_pkg(struct xbps_handle *xhp, const char *binpkg, const char *privkey, bool
265265
* Skip pkg if file signature exists
266266
*/
267267
if (!force && ((sigfile_fd = access(sigfile, R_OK)) == 0)) {
268-
if (xhp->flags & XBPS_FLAG_VERBOSE)
269-
fprintf(stderr, "skipping %s, file signature found.\n", binpkg);
268+
xbps_verbose_printf("skipping %s, file signature found.\n", binpkg);
270269

271270
sigfile_fd = -1;
272271
goto out;

bin/xbps-uhelper/main.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,13 @@ main(int argc, char **argv)
355355
/* NOTREACHED */
356356
}
357357
rv = xbps_pkgpattern_match(argv[1], argv[2]);
358-
if (flags & XBPS_FLAG_VERBOSE) {
359-
if (rv >= 0)
360-
fprintf(stderr, "%s %s %s\n",
361-
argv[1],
362-
(rv == 1) ? "matches" : "does not match",
363-
argv[2]);
364-
else
365-
xbps_error_printf("%s: not a pattern\n", argv[2]);
366-
}
358+
if (rv >= 0)
359+
xbps_verbose_printf("%s %s %s\n",
360+
argv[1],
361+
(rv == 1) ? "matches" : "does not match",
362+
argv[2]);
363+
else if (flags & XBPS_FLAG_VERBOSE)
364+
xbps_error_printf("%s: not a pattern\n", argv[2]);
367365
exit(rv);
368366
} else if (strcmp(argv[0], "cmpver") == 0) {
369367
/* Compare two version strings, installed vs required */
@@ -373,11 +371,10 @@ main(int argc, char **argv)
373371
}
374372

375373
rv = xbps_cmpver(argv[1], argv[2]);
376-
if (flags & XBPS_FLAG_VERBOSE)
377-
fprintf(stderr, "%s %s %s\n",
378-
argv[1],
379-
(rv == 1) ? ">" : ((rv == 0) ? "=" : "<"),
380-
argv[2]);
374+
xbps_verbose_printf("%s %s %s\n",
375+
argv[1],
376+
(rv == 1) ? ">" : ((rv == 0) ? "=" : "<"),
377+
argv[2]);
381378
exit(rv);
382379
} else if (strcmp(argv[0], "arch") == 0) {
383380
/* returns the xbps native arch */

include/xbps.h.in

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@
7777
# define XBPS_SYSDEFCONF_PATH "/usr/share" XBPS_SYSDIR
7878
#endif
7979

80-
/**
80+
/**
8181
* @def XBPS_META_PATH
8282
* Default root PATH to store metadata info.
8383
*/
8484
#ifndef XBPS_META_PATH
8585
#define XBPS_META_PATH "var/db/xbps"
8686
#endif
8787

88-
/**
88+
/**
8989
* @def XBPS_CACHE_PATH
9090
* Default cache PATH to store downloaded binpkgs.
9191
*/
@@ -109,7 +109,7 @@
109109
*/
110110
#define XBPS_PKGFILES "files.plist"
111111

112-
/**
112+
/**
113113
* @def XBPS_REPODATA_INDEX
114114
* Filename for the repository index property list.
115115
*/
@@ -285,7 +285,7 @@
285285
extern "C" {
286286
#endif
287287

288-
/** @addtogroup initend */
288+
/** @addtogroup initend */
289289
/**@{*/
290290

291291
/**
@@ -689,9 +689,11 @@ struct xbps_handle {
689689
};
690690

691691
extern int xbps_debug_level;
692+
extern int xbps_verbose_level;
692693

693694
void xbps_dbg_printf(const char *, ...) __attribute__ ((format (printf, 1, 2)));
694695
void xbps_dbg_printf_append(const char *, ...)__attribute__ ((format (printf, 1, 2)));
696+
void xbps_verbose_printf(const char *, ...) __attribute__ ((format (printf, 1, 2)));
695697
void xbps_error_printf(const char *, ...)__attribute__ ((format (printf, 1, 2)));
696698
void xbps_warn_printf(const char *, ...)__attribute__ ((format (printf, 1, 2)));
697699

@@ -752,11 +754,11 @@ int xbps_configure_packages(struct xbps_handle *xhp, xbps_array_t ignpkgs);
752754

753755
/**
754756
* Download a file from a remote URL to current working directory.
755-
*
757+
*
756758
* @param[in] xhp Pointer to an xbps_handle struct.
757759
* @param[in] uri Remote URI string.
758760
* @param[in] flags Flags passed to libfetch's fetchXget().
759-
*
761+
*
760762
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime
761763
* do not match) and 1 if downloaded successfully.
762764
**/
@@ -765,14 +767,14 @@ int xbps_fetch_file(struct xbps_handle *xhp, const char *uri,
765767

766768
/**
767769
* Download and digest a file from a remote URL to current working directory.
768-
*
770+
*
769771
* @param[in] xhp Pointer to an xbps_handle struct.
770772
* @param[in] uri Remote URI string.
771773
* @param[in] flags Flags passed to libfetch's fetchXget().
772774
* @param[out] digest SHA256 digest buffer for the downloaded file or NULL.
773775
* @param[in] digestlen Size of \a digest if specified; must be at least
774776
* XBPS_SHA256_DIGEST_SIZE.
775-
*
777+
*
776778
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime
777779
* do not match) and 1 if downloaded successfully.
778780
**/
@@ -783,12 +785,12 @@ int xbps_fetch_file_sha256(struct xbps_handle *xhp, const char *uri,
783785
/**
784786
* Download a file from a remote URL to current working directory,
785787
* and writing file to \a filename.
786-
*
788+
*
787789
* @param[in] xhp Pointer to an xbps_handle struct.
788790
* @param[in] uri Remote URI string.
789791
* @param[in] filename Local filename to safe the file
790792
* @param[in] flags Flags passed to libfetch's fetchXget().
791-
*
793+
*
792794
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime
793795
* do not match) and 1 if downloaded successfully.
794796
**/
@@ -798,15 +800,15 @@ int xbps_fetch_file_dest(struct xbps_handle *xhp, const char *uri,
798800
/**
799801
* Download and digest a file from a remote URL to current working directory,
800802
* and writing file to \a filename.
801-
*
803+
*
802804
* @param[in] xhp Pointer to an xbps_handle struct.
803805
* @param[in] uri Remote URI string.
804806
* @param[in] filename Local filename to safe the file
805807
* @param[in] flags Flags passed to libfetch's fetchXget().
806808
* @param[out] digest SHA256 digest buffer of the downloaded file or NULL.
807809
* @param[in] digestlen Size of \a digest if specified; must be at least
808810
* XBPS_SHA256_DIGEST_SIZE.
809-
*
811+
*
810812
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime
811813
* do not match) and 1 if downloaded successfully.
812814
**/
@@ -1460,7 +1462,7 @@ struct xbps_repo {
14601462
xbps_dictionary_t idxmeta;
14611463
/**
14621464
* @var uri
1463-
*
1465+
*
14641466
* URI string associated with repository.
14651467
*/
14661468
const char *uri;
@@ -1768,7 +1770,7 @@ typedef enum pkg_state {
17681770
/**
17691771
* Gets package state from package \a pkgname, and sets its state
17701772
* into \a state.
1771-
*
1773+
*
17721774
* @param[in] xhp The pointer to an xbps_handle struct.
17731775
* @param[in] pkgname Package name.
17741776
* @param[out] state Package state returned.
@@ -1985,7 +1987,7 @@ bool xbps_remote_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd);
19851987
* Checks if the URI specified by \a uri is remote or local.
19861988
*
19871989
* @param[in] uri URI string.
1988-
*
1990+
*
19891991
* @return true if URI is remote, false if local.
19901992
*/
19911993
bool xbps_repository_is_remote(const char *uri);
@@ -2092,7 +2094,7 @@ bool xbps_pkgpattern_name(char *dst, size_t len, const char *pattern);
20922094

20932095
/**
20942096
* Gets the package version in a package string, i.e `foo-2.0`.
2095-
*
2097+
*
20962098
* @param[in] pkg Package string.
20972099
*
20982100
* @return A string with the version string, NULL if it couldn't

lib/initend.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ xbps_init(struct xbps_handle *xhp)
5353
if (xhp->flags & XBPS_FLAG_DEBUG)
5454
xbps_debug_level = 1;
5555

56+
if (xhp->flags & XBPS_FLAG_VERBOSE)
57+
xbps_verbose_level = 1;
58+
5659
xbps_dbg_printf("%s\n", XBPS_RELVER);
5760

5861
/* Set rootdir */

lib/log.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#endif
3636

3737
int xbps_debug_level = 0;
38+
int xbps_verbose_level = 0;
3839

3940
/**
4041
* @file lib/log.c
@@ -79,6 +80,19 @@ xbps_dbg_printf(const char *fmt, ...)
7980
va_end(ap);
8081
}
8182

83+
void
84+
xbps_verbose_printf(const char *fmt, ...)
85+
{
86+
va_list ap;
87+
88+
if (xbps_verbose_level == 0)
89+
return;
90+
91+
va_start(ap, fmt);
92+
common_printf(stderr, NULL, fmt, ap);
93+
va_end(ap);
94+
}
95+
8296
void
8397
xbps_error_printf(const char *fmt, ...)
8498
{

0 commit comments

Comments
 (0)