xbps-bin: add -v flag, used when installing/removing currently.

--HG--
extra : convert_revision : d543b52213bf3d35b17ef29ff74a879bc4342cef
This commit is contained in:
Juan RP 2009-02-17 00:08:03 +01:00
parent 8d5e1ab017
commit fb998feacf
8 changed files with 83 additions and 63 deletions

View file

@ -52,6 +52,7 @@ usage(void)
" show\t<pkgname>\n" " show\t<pkgname>\n"
" Options shared by all actions:\n" " Options shared by all actions:\n"
" -r\t\t<rootdir>\n" " -r\t\t<rootdir>\n"
" -v\t\t<verbose>\n"
"\n" "\n"
" Examples:\n" " Examples:\n"
" $ xbps-bin install klibc\n" " $ xbps-bin install klibc\n"
@ -110,15 +111,18 @@ main(int argc, char **argv)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
char *plist, *root = NULL; char *plist, *root = NULL;
int c, rv = 0; int c, flags = 0, rv = 0;
while ((c = getopt(argc, argv, "r:")) != -1) { while ((c = getopt(argc, argv, "r:v")) != -1) {
switch (c) { switch (c) {
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
root = optarg; root = optarg;
xbps_set_rootdir(root); xbps_set_rootdir(root);
break; break;
case 'v':
flags |= XBPS_UNPACK_VERBOSE;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -164,8 +168,8 @@ main(int argc, char **argv)
/* Install into root directory by default. */ /* Install into root directory by default. */
if (strcasecmp(argv[0], "install") == 0) { if (strcasecmp(argv[0], "install") == 0) {
rv = xbps_install_binary_pkg(argv[1], root); rv = xbps_install_binary_pkg(argv[1], root, flags);
if (rv) { if (rv != 0 && rv != EEXIST) {
dict = xbps_get_pkg_deps_dictionary(); dict = xbps_get_pkg_deps_dictionary();
if (dict == NULL && errno == ENOENT) if (dict == NULL && errno == ENOENT)
printf("Unable to locate %s in " printf("Unable to locate %s in "
@ -177,8 +181,8 @@ main(int argc, char **argv)
} }
printf("Package %s installed successfully.\n", argv[1]); printf("Package %s installed successfully.\n", argv[1]);
} else { } else {
rv = xbps_remove_binary_pkg(argv[1], root); rv = xbps_remove_binary_pkg(argv[1], root, flags);
if (rv) { if (rv != 0) {
if (errno == ENOENT) if (errno == ENOENT)
printf("Package %s is not installed.\n", printf("Package %s is not installed.\n",
argv[1]); argv[1]);

View file

@ -27,15 +27,14 @@
#define _XBPS_INSTALL_H_ #define _XBPS_INSTALL_H_
/* From lib/install.c, lib/depends.c and lib/unpack.c */ /* From lib/install.c, lib/depends.c and lib/unpack.c */
int xbps_install_pkg_deps(prop_dictionary_t, const char *); int xbps_install_pkg_deps(prop_dictionary_t, const char *, int);
int xbps_install_binary_pkg(const char *, const char *); int xbps_install_binary_pkg(const char *, const char *, int);
int xbps_install_binary_pkg_fini(prop_dictionary_t, prop_dictionary_t, int xbps_install_binary_pkg_fini(prop_dictionary_t, prop_dictionary_t,
const char *); const char *, int);
int xbps_register_pkg(prop_dictionary_t, const char *, const char *, int xbps_register_pkg(prop_dictionary_t, const char *, const char *,
const char *, bool); const char *, bool);
int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t, int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t,
const char *, const char *, int);
void (*cb_print)(prop_dictionary_t));
int xbps_update_pkg_requiredby(prop_array_t, prop_dictionary_t); int xbps_update_pkg_requiredby(prop_array_t, prop_dictionary_t);
int xbps_find_deps_in_pkg(prop_dictionary_t); int xbps_find_deps_in_pkg(prop_dictionary_t);

View file

@ -27,7 +27,7 @@
#define _XBPS_REMOVE_H_ #define _XBPS_REMOVE_H_
/* From lib/remove.c */ /* From lib/remove.c */
int xbps_remove_binary_pkg(const char *, const char *); int xbps_remove_binary_pkg(const char *, const char *, int);
int xbps_unregister_pkg(const char *); int xbps_unregister_pkg(const char *);
#endif /* !_XBPS_REMOVE_H_ */ #endif /* !_XBPS_REMOVE_H_ */

View file

@ -50,6 +50,9 @@
/* Filename of the package properties plist file. */ /* Filename of the package properties plist file. */
#define XBPS_PKGPROPS "props.plist" #define XBPS_PKGPROPS "props.plist"
/* Unpack flags */
#define XBPS_UNPACK_VERBOSE 0x00000001
#include "cmpver.h" #include "cmpver.h"
#include "fexec.h" #include "fexec.h"
#include "humanize_number.h" #include "humanize_number.h"

View file

@ -301,6 +301,10 @@ xbps_find_deps_in_pkg(prop_dictionary_t pkg)
assert(pkg != NULL); assert(pkg != NULL);
pkg_rdeps = prop_dictionary_get(pkg, "run_depends");
if (pkg_rdeps == NULL)
return 0;
/* /*
* Get the dictionary with the list of registered repositories. * Get the dictionary with the list of registered repositories.
*/ */
@ -330,8 +334,6 @@ xbps_find_deps_in_pkg(prop_dictionary_t pkg)
return ENOMEM; return ENOMEM;
} }
pkg_rdeps = prop_dictionary_get(pkg, "run_depends");
/* /*
* Iterate over the repository pool and find out if we have * Iterate over the repository pool and find out if we have
* all available binary packages. * all available binary packages.
@ -589,7 +591,7 @@ find_pkg_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg,
} }
int int
xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir) xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir, int flags)
{ {
prop_array_t required, missing; prop_array_t required, missing;
prop_object_t obj; prop_object_t obj;
@ -623,7 +625,7 @@ xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir)
* Install all required dependencies, previously sorted. * Install all required dependencies, previously sorted.
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
rv = xbps_install_binary_pkg_fini(NULL, obj, destdir); rv = xbps_install_binary_pkg_fini(NULL, obj, destdir, flags);
if (rv != 0) if (rv != 0)
break; break;
} }

View file

@ -37,13 +37,14 @@
struct cbargs { struct cbargs {
const char *destdir; const char *destdir;
const char *pkgname; const char *pkgname;
int flags;
}; };
static int install_binpkg_repo_cb(prop_object_t, void *, bool *); static int install_binpkg_repo_cb(prop_object_t, void *, bool *);
int int
xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg, xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg,
const char *destdir) const char *destdir, int flags)
{ {
const char *pkgname, *version, *desc; const char *pkgname, *version, *desc;
int rv = 0; int rv = 0;
@ -65,23 +66,22 @@ xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg,
(void)fflush(stdout); (void)fflush(stdout);
rv = xbps_unpack_binary_pkg(repo, pkg, destdir, NULL); rv = xbps_unpack_binary_pkg(repo, pkg, destdir, flags);
if (rv == 0) { if (rv == 0) {
rv = xbps_register_pkg(pkg, pkgname, version, desc, automatic); rv = xbps_register_pkg(pkg, pkgname, version, desc, automatic);
if (rv == EEXIST) if (rv != 0) {
rv = 0; printf("failed!\n");
return rv;
}
} }
if (rv == 0) printf("done.\n");
printf("done.\n");
else
printf("failed!\n");
return rv; return 0;
} }
int int
xbps_install_binary_pkg(const char *pkgname, const char *destdir) xbps_install_binary_pkg(const char *pkgname, const char *destdir, int flags)
{ {
struct cbargs cb; struct cbargs cb;
int rv = 0; int rv = 0;
@ -95,14 +95,15 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
cb.pkgname = pkgname; cb.pkgname = pkgname;
cb.destdir = destdir; cb.destdir = destdir;
cb.flags = flags;
/* /*
* Iterate over the repository pool and find out if we have * Iterate over the repository pool and find out if we have
* all available binary packages. * all available binary packages.
*/ */
rv = xbps_callback_array_iter_in_repolist(install_binpkg_repo_cb, rv = xbps_callback_array_iter_in_repolist(install_binpkg_repo_cb,
(void *)&cb); (void *)&cb);
if (rv == 0 && errno == ENOENT) if (rv == 0 && errno == EAGAIN)
rv = errno; return ENOENT;
return rv; return rv;
} }
@ -135,7 +136,7 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
pkgrd = xbps_find_pkg_in_dict(repod, "packages", pkgname); pkgrd = xbps_find_pkg_in_dict(repod, "packages", pkgname);
if (pkgrd == NULL) { if (pkgrd == NULL) {
prop_object_release(repod); prop_object_release(repod);
errno = ENOENT; errno = EAGAIN;
return 0; return 0;
} }
@ -144,7 +145,8 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
*/ */
if (!xbps_pkg_has_rundeps(pkgrd)) { if (!xbps_pkg_has_rundeps(pkgrd)) {
/* pkg has no deps, just install it. */ /* pkg has no deps, just install it. */
rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir); rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir,
cb->flags);
prop_object_release(repod); prop_object_release(repod);
return rv; return rv;
} }
@ -164,8 +166,9 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
/* /*
* Install all required dependencies and the package itself. * Install all required dependencies and the package itself.
*/ */
if ((rv = xbps_install_pkg_deps(pkgrd, destdir)) == 0) { if ((rv = xbps_install_pkg_deps(pkgrd, destdir, cb->flags)) == 0) {
rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir); rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir,
cb->flags);
prop_object_release(repod); prop_object_release(repod);
if (rv == 0) if (rv == 0)
*cbloop_done = true; *cbloop_done = true;

View file

@ -57,7 +57,7 @@ xbps_unregister_pkg(const char *pkgname)
} }
static int static int
xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir) xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir, int flags)
{ {
struct dirent *dp; struct dirent *dp;
DIR *dirp; DIR *dirp;
@ -88,8 +88,9 @@ xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir)
} }
if ((rv = unlink(path)) == -1) { if ((rv = unlink(path)) == -1) {
printf("WARNING: can't remove %s (%s)\n", if (flags & XBPS_UNPACK_VERBOSE)
pkgname, strerror(errno)); printf("WARNING: can't remove %s (%s)\n",
pkgname, strerror(errno));
} }
(void)memset(&path, 0, sizeof(path)); (void)memset(&path, 0, sizeof(path));
} }
@ -100,7 +101,7 @@ xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir)
} }
int int
xbps_remove_binary_pkg(const char *pkgname, const char *destdir) xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
{ {
FILE *flist; FILE *flist;
char path[PATH_MAX - 1], line[LINE_MAX - 1], *p, *buf; char path[PATH_MAX - 1], line[LINE_MAX - 1], *p, *buf;
@ -193,19 +194,23 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
rv = 0; rv = 0;
goto next; goto next;
} }
printf("WARNING: can't remove directory" if (flags & XBPS_UNPACK_VERBOSE)
" %s (%s)\n", path, strerror(errno)); printf("WARNING: can't remove "
"directory %s (%s)\n",
path, strerror(errno));
goto next; goto next;
} }
printf("Removed directory: %s\n", path); if (flags & XBPS_UNPACK_VERBOSE)
printf("Removed directory: %s\n", path);
goto next; goto next;
} }
printf("WARNING: can't remove file %s (%s)\n", path, if (flags & XBPS_UNPACK_VERBOSE)
strerror(errno)); printf("WARNING: can't remove file %s (%s)\n", path,
strerror(errno));
goto next; goto next;
} }
if (flags & XBPS_UNPACK_VERBOSE)
printf("Removed file: %s\n", path); printf("Removed file: %s\n", path);
next: next:
free(p); free(p);
p = NULL; p = NULL;
@ -226,7 +231,7 @@ next:
out: out:
free(buf); free(buf);
rv = xbps_remove_binary_pkg_meta(pkgname, destdir); rv = xbps_remove_binary_pkg_meta(pkgname, destdir, flags);
return rv; return rv;
} }

View file

@ -35,14 +35,14 @@
#include <xbps_api.h> #include <xbps_api.h>
static int unpack_archive_init(prop_dictionary_t, const char *, const char *); static int unpack_archive_init(prop_dictionary_t, const char *,
static int unpack_archive_fini(struct archive *, const char *, const char *, int);
static int unpack_archive_fini(struct archive *, const char *, int,
prop_dictionary_t); prop_dictionary_t);
int int
xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg, xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
const char *destdir, const char *destdir, int flags)
void (*cb_print)(prop_dictionary_t))
{ {
prop_string_t filename, repoloc, arch; prop_string_t filename, repoloc, arch;
char *binfile, *path; char *binfile, *path;
@ -72,10 +72,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
} }
free(path); free(path);
if (cb_print) rv = unpack_archive_init(pkg, destdir, binfile, flags);
(*cb_print)(pkg);
rv = unpack_archive_init(pkg, destdir, binfile);
free(binfile); free(binfile);
return rv; return rv;
} }
@ -83,7 +80,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
static int static int
unpack_archive_init(prop_dictionary_t pkg, const char *destdir, unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
const char *binfile) const char *binfile, int flags)
{ {
struct archive *ar; struct archive *ar;
int pkg_fd, rv; int pkg_fd, rv;
@ -111,7 +108,7 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
return rv; return rv;
} }
rv = unpack_archive_fini(ar, destdir, pkg); rv = unpack_archive_fini(ar, destdir, flags, pkg);
/* /*
* If installation of package was successful, make sure the package * If installation of package was successful, make sure the package
* is really on storage (if possible). * is really on storage (if possible).
@ -139,7 +136,7 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
* the consumer. * the consumer.
*/ */
static int static int
unpack_archive_fini(struct archive *ar, const char *destdir, unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
prop_dictionary_t pkg) prop_dictionary_t pkg)
{ {
struct archive_entry *entry; struct archive_entry *entry;
@ -148,7 +145,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
const char *prepost = "./XBPS_PREPOST_INSTALL"; const char *prepost = "./XBPS_PREPOST_INSTALL";
const char *pkgname, *version; const char *pkgname, *version;
char *buf, *path; char *buf, *path;
int rv = 0, flags = 0; int rv = 0, lflags = 0;
bool actgt = false; bool actgt = false;
assert(ar != NULL); assert(ar != NULL);
@ -158,9 +155,9 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
prop_dictionary_get_cstring_nocopy(pkg, "version", &version); prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
if (getuid() == 0) if (getuid() == 0)
flags = FEXTRACT_FLAGS; lflags = FEXTRACT_FLAGS;
else else
flags = EXTRACT_FLAGS; lflags = EXTRACT_FLAGS;
/* /*
* This length is '.%s/metadata/%s/prepost-inst' not * This length is '.%s/metadata/%s/prepost-inst' not
@ -205,7 +202,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
archive_entry_set_pathname(entry, buf); archive_entry_set_pathname(entry, buf);
rv = archive_read_extract(ar, entry, flags); rv = archive_read_extract(ar, entry, lflags);
if (rv != 0 && rv != EEXIST) if (rv != 0 && rv != EEXIST)
break; break;
@ -223,18 +220,25 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
/* /*
* Extract all data from the archive now. * Extract all data from the archive now.
*/ */
rv = archive_read_extract(ar, entry, flags); rv = archive_read_extract(ar, entry, lflags);
if (rv != 0 && rv != EEXIST) { if (rv != 0 && rv != EEXIST) {
printf("\ncouldn't unpack %s (%s), exiting!\n", printf("\ncouldn't unpack %s (%s), exiting!\n",
archive_entry_pathname(entry), strerror(errno)); archive_entry_pathname(entry), strerror(errno));
(void)fflush(stdout); (void)fflush(stdout);
break; break;
} else if (rv == EEXIST) { } else if (rv == EEXIST) {
printf("\nignoring existent component %s.\n", if (flags & XBPS_UNPACK_VERBOSE) {
archive_entry_pathname(entry)); printf("\nignoring existent component %s.\n",
(void)fflush(stdout); archive_entry_pathname(entry));
(void)fflush(stdout);
}
continue; continue;
} }
if (flags & XBPS_UNPACK_VERBOSE) {
printf(" %s\n", archive_entry_pathname(entry));
(void)fflush(stdout);
}
} }
if (rv == 0 && actgt) { if (rv == 0 && actgt) {