xbps-uhelper: restore compat.
Add 'digest' and 'fetch' actions again for compatibility, but don't mention them in usage(). This way previous versions of xbps-src (that don't require xbps-0.54) still work without changes.
This commit is contained in:
parent
490cce2ff8
commit
e7738555b2
@ -2,7 +2,7 @@ TOPDIR = ../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
BIN = xbps-uhelper
|
||||
OBJS = main.o
|
||||
OBJS = main.o ../xbps-install/fetch_cb.o
|
||||
MAN =
|
||||
|
||||
include $(TOPDIR)/mk/prog.mk
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include <xbps.h>
|
||||
#include "../xbps-install/defs.h"
|
||||
|
||||
static void __attribute__((noreturn))
|
||||
usage(void)
|
||||
@ -79,13 +80,29 @@ usage(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static char *
|
||||
fname(char *url)
|
||||
{
|
||||
char *filename;
|
||||
|
||||
if ((filename = strrchr(url, '>'))) {
|
||||
*filename = '\0';
|
||||
} else {
|
||||
filename = strrchr(url, '/');
|
||||
}
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
return filename + 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
xbps_dictionary_t dict;
|
||||
struct xbps_handle xh;
|
||||
struct xferstat xfer;
|
||||
const char *version, *rootdir = NULL, *confdir = NULL;
|
||||
char *pkgname;
|
||||
char *pkgname, *filename;
|
||||
int flags = 0, c, rv = 0;
|
||||
const struct option longopts[] = {
|
||||
{ NULL, 0, NULL, 0 }
|
||||
@ -123,10 +140,13 @@ main(int argc, char **argv)
|
||||
if ((strcmp(argv[0], "version") == 0) ||
|
||||
(strcmp(argv[0], "real-version") == 0) ||
|
||||
(strcmp(argv[0], "arch") == 0) ||
|
||||
(strcmp(argv[0], "fetch") == 0) ||
|
||||
(strcmp(argv[0], "getsystemdir") == 0)) {
|
||||
/*
|
||||
* Initialize libxbps.
|
||||
*/
|
||||
xh.fetch_cb = fetch_file_progress_cb;
|
||||
xh.fetch_cb_data = &xfer;
|
||||
xh.flags = flags;
|
||||
if (rootdir)
|
||||
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
|
||||
@ -268,6 +288,39 @@ main(int argc, char **argv)
|
||||
usage();
|
||||
|
||||
printf("%s\n", XBPS_SYSDEFCONF_PATH);
|
||||
} else if (strcmp(argv[0], "digest") == 0) {
|
||||
/* Prints SHA256 hashes for specified files */
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
filename = xbps_file_hash(argv[i]);
|
||||
if (filename == NULL) {
|
||||
fprintf(stderr,
|
||||
"E: couldn't get hash for %s (%s)\n",
|
||||
argv[i], strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("%s\n", filename);
|
||||
}
|
||||
} else if (strcmp(argv[0], "fetch") == 0) {
|
||||
/* Fetch a file from specified URL */
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
filename = fname(argv[i]);
|
||||
rv = xbps_fetch_file_dest(&xh, argv[i], filename, "v");
|
||||
|
||||
if (rv == -1) {
|
||||
fprintf(stderr, "%s: %s\n", argv[i],
|
||||
xbps_fetch_error_string());
|
||||
} else if (rv == 0) {
|
||||
printf("%s: file is identical with remote.\n", argv[i]);
|
||||
} else {
|
||||
rv = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user