xbps-bin: added -C flag for 'files' target, to check SHA256 hash in files.
--HG-- extra : convert_revision : 28fffd3047de8d8a4b9401618017a880cbf03008
This commit is contained in:
parent
d9cc1d6b8f
commit
48a5933756
3 changed files with 70 additions and 14 deletions
|
@ -43,22 +43,24 @@ static int list_pkgs_in_dict(prop_object_t, void *, bool *);
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
printf("Usage: xbps-bin [options] [action] [arguments]\n\n"
|
printf("Usage: xbps-bin [options] [target] [arguments]\n\n"
|
||||||
" Available actions:\n"
|
" Available targets:\n"
|
||||||
" install, list, remove, show, files\n"
|
" autoremove, install, list, remove, show, files\n"
|
||||||
" Actions with arguments:\n"
|
" Targets with arguments:\n"
|
||||||
" install\t<pkgname>\n"
|
" install\t<pkgname>\n"
|
||||||
" files\t<pkgname>\n"
|
" files\t<pkgname>\n"
|
||||||
" remove\t<pkgname>\n"
|
" remove\t<pkgname>\n"
|
||||||
" show\t<pkgname>\n"
|
" show\t<pkgname>\n"
|
||||||
" Options shared by all actions:\n"
|
" Options shared by all targets:\n"
|
||||||
" -r\t\t<rootdir>\n"
|
" -r\t\t<rootdir>\n"
|
||||||
" -v\t\t<verbose>\n"
|
" -v\t\t<verbose>\n"
|
||||||
|
" Option used by the files target:\n"
|
||||||
|
" -C\t\tTo check the SHA256 hash for any listed file.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Examples:\n"
|
" Examples:\n"
|
||||||
" $ xbps-bin install klibc\n"
|
" $ xbps-bin install klibc\n"
|
||||||
" $ xbps-bin -r /path/to/root install klibc\n"
|
" $ xbps-bin -r /path/to/root install klibc\n"
|
||||||
" $ xbps-bin files klibc\n"
|
" $ xbps-bin -C files klibc\n"
|
||||||
" $ xbps-bin list\n"
|
" $ xbps-bin list\n"
|
||||||
" $ xbps-bin remove klibc\n"
|
" $ xbps-bin remove klibc\n"
|
||||||
" $ xbps-bin show klibc\n");
|
" $ xbps-bin show klibc\n");
|
||||||
|
@ -118,9 +120,13 @@ main(int argc, char **argv)
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
char *plist, *root = NULL;
|
char *plist, *root = NULL;
|
||||||
int c, flags = 0, rv = 0;
|
int c, flags = 0, rv = 0;
|
||||||
|
bool chkhash = false;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "r:v")) != -1) {
|
while ((c = getopt(argc, argv, "Cr:v")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 'C':
|
||||||
|
chkhash = true;
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
/* To specify the root directory */
|
/* To specify the root directory */
|
||||||
root = optarg;
|
root = optarg;
|
||||||
|
@ -212,16 +218,35 @@ main(int argc, char **argv)
|
||||||
printf("Package %s not installed.\n", argv[1]);
|
printf("Package %s not installed.\n", argv[1]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "files") == 0) {
|
} else if (strcasecmp(argv[0], "files") == 0) {
|
||||||
/* Shows files installed by a binary package. */
|
/* Shows files installed by a binary package. */
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
rv = show_pkg_files_from_metadir(argv[1]);
|
rv = show_pkg_files_from_metadir(argv[1], root, chkhash);
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
printf("Package %s not installed.\n", argv[1]);
|
printf("Package %s not installed.\n", argv[1]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (strcasecmp(argv[0], "autoremove") == 0) {
|
||||||
|
/*
|
||||||
|
* Removes orphaned pkgs. These packages were installed
|
||||||
|
* as dependency and any installed package does not depend
|
||||||
|
* on it.
|
||||||
|
*/
|
||||||
|
if (argc != 1)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
rv = xbps_auto_remove_packages();
|
||||||
|
if (rv != 0) {
|
||||||
|
printf("There was an error! (%s)\n", strerror(rv));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,11 @@
|
||||||
#include <xbps_api.h>
|
#include <xbps_api.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
struct show_files_cb {
|
||||||
|
const char *destdir;
|
||||||
|
bool check_hash;
|
||||||
|
};
|
||||||
|
|
||||||
static void show_pkg_info(prop_dictionary_t);
|
static void show_pkg_info(prop_dictionary_t);
|
||||||
static int show_pkg_files(prop_object_t, void *, bool *);
|
static int show_pkg_files(prop_object_t, void *, bool *);
|
||||||
static int show_pkg_namedesc(prop_object_t, void *, bool *);
|
static int show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||||
|
@ -194,9 +199,10 @@ show_pkg_info_from_metadir(const char *pkgname)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
show_pkg_files_from_metadir(const char *pkgname)
|
show_pkg_files_from_metadir(const char *pkgname, const char *destdir, bool hash)
|
||||||
{
|
{
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
|
struct show_files_cb sf_cb;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
char *plist, *path;
|
char *plist, *path;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
@ -223,8 +229,10 @@ show_pkg_files_from_metadir(const char *pkgname)
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf_cb.destdir = destdir;
|
||||||
|
sf_cb.check_hash = hash;
|
||||||
rv = xbps_callback_array_iter_in_dict(pkgd, "filelist",
|
rv = xbps_callback_array_iter_in_dict(pkgd, "filelist",
|
||||||
show_pkg_files, NULL);
|
show_pkg_files, (void *)&sf_cb);
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
free(plist);
|
free(plist);
|
||||||
|
|
||||||
|
@ -234,14 +242,37 @@ show_pkg_files_from_metadir(const char *pkgname)
|
||||||
static int
|
static int
|
||||||
show_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
show_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
{
|
{
|
||||||
const char *file = NULL;
|
struct show_files_cb *sfc = arg;
|
||||||
|
const char *file = NULL, *sha256;
|
||||||
|
char *path;
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
(void)arg;
|
|
||||||
(void)loop_done;
|
(void)loop_done;
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||||
if (file != NULL)
|
if (sfc->check_hash == false && file != NULL) {
|
||||||
printf("%s\n", file);
|
printf("%s\n", file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sfc->check_hash && file != NULL) {
|
||||||
|
path = xbps_append_full_path(false, sfc->destdir, file);
|
||||||
|
if (path == NULL)
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
printf("%s", file);
|
||||||
|
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256);
|
||||||
|
rv = xbps_check_file_hash(path, sha256);
|
||||||
|
if (rv != 0 && rv != ERANGE) {
|
||||||
|
free(path);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
if (rv == ERANGE)
|
||||||
|
printf(" WARNING! SHA256 HASH MISMATCH!");
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
int search_string_in_pkgs(prop_object_t, void *, bool *);
|
int search_string_in_pkgs(prop_object_t, void *, bool *);
|
||||||
int show_pkg_info_from_metadir(const char *);
|
int show_pkg_info_from_metadir(const char *);
|
||||||
int show_pkg_files_from_metadir(const char *);
|
int show_pkg_files_from_metadir(const char *, const char *, bool);
|
||||||
int show_pkg_info_from_repolist(prop_object_t, void *, bool *);
|
int show_pkg_info_from_repolist(prop_object_t, void *, bool *);
|
||||||
int list_strings_in_array(prop_object_t, void *, bool *);
|
int list_strings_in_array(prop_object_t, void *, bool *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue