Simplify all code that used rootdir and flags passed via xbps-bin.

Add util funcs to get/set global values for them:
 * xbps_[gs]et_rootdir()
 * xbps_[gs]et_flags()

--HG--
extra : convert_revision : 2584b098e68a684e7b0eeac57c2b1df4aba6589d
This commit is contained in:
Juan RP 2009-03-17 00:32:26 +01:00
parent bc1e2c8dcd
commit a67374bd66
12 changed files with 114 additions and 108 deletions

View file

@ -149,7 +149,7 @@ main(int argc, char **argv)
prop_object_iterator_t iter; prop_object_iterator_t iter;
static size_t count; static size_t count;
const char *pkgname, *version; const char *pkgname, *version;
char *plist, *root = NULL; char *plist;
int c, flags = 0, rv = 0; int c, flags = 0, rv = 0;
bool chkhash = false, forcerm = false, verbose = false; bool chkhash = false, forcerm = false, verbose = false;
@ -163,12 +163,11 @@ main(int argc, char **argv)
break; break;
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
root = optarg; xbps_set_rootdir(optarg);
xbps_set_rootdir(root);
break; break;
case 'v': case 'v':
verbose = true; verbose = true;
flags |= XBPS_UNPACK_VERBOSE; flags |= XBPS_VERBOSE;
break; break;
case '?': case '?':
default: default:
@ -182,6 +181,9 @@ main(int argc, char **argv)
if (argc < 1) if (argc < 1)
usage(); usage();
if (flags != 0)
xbps_set_flags(flags);
if (strcasecmp(argv[0], "list") == 0) { if (strcasecmp(argv[0], "list") == 0) {
/* Lists packages currently registered in database. */ /* Lists packages currently registered in database. */
if (argc != 1) if (argc != 1)
@ -213,7 +215,7 @@ main(int argc, char **argv)
usage(); usage();
/* Install into root directory by default. */ /* Install into root directory by default. */
rv = xbps_install_binary_pkg(argv[1], root, flags); rv = xbps_install_binary_pkg(argv[1]);
if (rv != 0) { if (rv != 0) {
if (rv == EAGAIN) { if (rv == EAGAIN) {
printf("Unable to locate %s in " printf("Unable to locate %s in "
@ -265,7 +267,7 @@ main(int argc, char **argv)
(void)fflush(stdout); (void)fflush(stdout);
rv = xbps_remove_binary_pkg(argv[1], root, flags); rv = xbps_remove_binary_pkg(argv[1]);
if (rv != 0) { if (rv != 0) {
if (!verbose) if (!verbose)
printf("failed! (%s)\n", strerror(rv)); printf("failed! (%s)\n", strerror(rv));
@ -300,7 +302,7 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
rv = show_pkg_files_from_metadir(argv[1], root, chkhash); rv = show_pkg_files_from_metadir(argv[1], 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);
@ -364,7 +366,7 @@ main(int argc, char **argv)
(void)fflush(stdout); (void)fflush(stdout);
rv = xbps_remove_binary_pkg(pkgname, root, flags); rv = xbps_remove_binary_pkg(pkgname);
if (rv != 0) { if (rv != 0) {
if (!verbose) if (!verbose)
printf("failed! (%s)\n", strerror(rv)); printf("failed! (%s)\n", strerror(rv));

View file

@ -212,11 +212,12 @@ show_pkg_info_from_metadir(const char *pkgname)
} }
int int
show_pkg_files_from_metadir(const char *pkgname, const char *destdir, bool hash) show_pkg_files_from_metadir(const char *pkgname, bool hash)
{ {
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
struct show_files_cb sfc; struct show_files_cb sfc;
size_t len = 0; size_t len = 0;
const char *destdir = xbps_get_rootdir();
char *plist, *path; char *plist, *path;
int rv = 0; int rv = 0;

View file

@ -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 *, const char *, bool); int show_pkg_files_from_metadir(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 *);

View file

@ -27,14 +27,12 @@
#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(const char *, const char *, int); int xbps_install_pkg_deps(const char *);
int xbps_install_binary_pkg(const char *, const char *, int); int xbps_install_binary_pkg(const char *);
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 *, 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 *, int);
int xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t); int xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t);
int xbps_requiredby_pkg_remove(const char *); int xbps_requiredby_pkg_remove(const char *);
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); int xbps_remove_binary_pkg(const char *);
int xbps_unregister_pkg(const char *); int xbps_unregister_pkg(const char *);
#endif /* !_XBPS_REMOVE_H_ */ #endif /* !_XBPS_REMOVE_H_ */

View file

@ -37,6 +37,9 @@ char * xbps_get_pkg_name(const char *);
const char * xbps_get_pkg_version(const char *); const char * xbps_get_pkg_version(const char *);
bool xbps_pkg_has_rundeps(prop_dictionary_t); bool xbps_pkg_has_rundeps(prop_dictionary_t);
void xbps_set_rootdir(const char *); void xbps_set_rootdir(const char *);
const char * xbps_get_rootdir(void);
void xbps_set_flags(int);
int xbps_get_flags(void);
/* From lib/orphans.c */ /* From lib/orphans.c */
prop_array_t xbps_find_orphan_packages(void); prop_array_t xbps_find_orphan_packages(void);

View file

@ -51,8 +51,8 @@
#define XBPS_PKGPROPS "props.plist" #define XBPS_PKGPROPS "props.plist"
#define XBPS_PKGFILES "files.plist" #define XBPS_PKGFILES "files.plist"
/* Unpack flags */ /* Verbose messages */
#define XBPS_UNPACK_VERBOSE 0x00000001 #define XBPS_VERBOSE 0x00000001
#include "cmpver.h" #include "cmpver.h"
#include "fexec.h" #include "fexec.h"

View file

@ -594,7 +594,7 @@ find_pkg_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg,
} }
int int
xbps_install_pkg_deps(const char *pkgname, const char *destdir, int flags) xbps_install_pkg_deps(const char *pkgname)
{ {
prop_array_t required, missing; prop_array_t required, missing;
prop_object_t obj; prop_object_t obj;
@ -644,7 +644,7 @@ xbps_install_pkg_deps(const char *pkgname, const char *destdir, int flags)
* 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, flags); rv = xbps_install_binary_pkg_fini(NULL, obj);
if (rv != 0) if (rv != 0)
break; break;
} }

View file

@ -34,17 +34,10 @@
#include <xbps_api.h> #include <xbps_api.h>
struct cbargs {
const char *destdir;
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, int flags)
{ {
const char *pkgname, *version, *desc; const char *pkgname, *version, *desc;
int rv = 0; int rv = 0;
@ -62,7 +55,7 @@ xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg,
automatic ? "dependency " : "", pkgname, version); automatic ? "dependency " : "", pkgname, version);
(void)fflush(stdout); (void)fflush(stdout);
rv = xbps_unpack_binary_pkg(repo, pkg, destdir, flags); rv = xbps_unpack_binary_pkg(repo, pkg);
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 != 0) { if (rv != 0) {
@ -76,30 +69,17 @@ xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg,
} }
int int
xbps_install_binary_pkg(const char *pkgname, const char *destdir, int flags) xbps_install_binary_pkg(const char *pkgname)
{ {
struct cbargs cb;
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
if (destdir) {
if (chdir(destdir) == -1)
return errno;
} else {
if (chdir("/") == -1)
return errno;
destdir = "NOTSET";
}
cb.pkgname = pkgname;
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 *)pkgname);
if (rv == 0 && errno != 0) if (rv == 0 && errno != 0)
return errno; return errno;
@ -110,8 +90,7 @@ static int
install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done) install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
{ {
prop_dictionary_t repod, pkgrd; prop_dictionary_t repod, pkgrd;
struct cbargs *cb = arg; const char *repoloc, *pkgname = arg;
const char *repoloc;
char *plist; char *plist;
int rv = 0; int rv = 0;
@ -130,7 +109,7 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
* Get the package dictionary from current repository. * Get the package dictionary from current repository.
* If it's not there, pass to the next repository. * If it's not there, pass to the next repository.
*/ */
pkgrd = xbps_find_pkg_in_dict(repod, "packages", cb->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 = EAGAIN; errno = EAGAIN;
@ -172,13 +151,12 @@ 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.
*/ */
rv = xbps_install_pkg_deps(cb->pkgname, cb->destdir, cb->flags); rv = xbps_install_pkg_deps(pkgname);
if (rv != 0) if (rv != 0)
goto out; goto out;
install: install:
rv = xbps_install_binary_pkg_fini(repod, pkgrd, rv = xbps_install_binary_pkg_fini(repod, pkgrd);
cb->destdir, cb->flags);
if (rv == 0) { if (rv == 0) {
*cbloop_done = true; *cbloop_done = true;
/* Cleanup errno, just in case */ /* Cleanup errno, just in case */

View file

@ -36,11 +36,6 @@
#include <xbps_api.h> #include <xbps_api.h>
struct rm_cbarg {
const char *destdir;
int flags;
};
static int remove_pkg_files(prop_object_t, void *, bool *); static int remove_pkg_files(prop_object_t, void *, bool *);
int int
@ -64,20 +59,22 @@ xbps_unregister_pkg(const char *pkgname)
} }
static int static int
xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir, int flags) xbps_remove_binary_pkg_meta(const char *pkgname)
{ {
struct dirent *dp; struct dirent *dp;
DIR *dirp; DIR *dirp;
const char *rootdir = xbps_get_rootdir();
char metadir[PATH_MAX - 1], path[PATH_MAX - 1]; char metadir[PATH_MAX - 1], path[PATH_MAX - 1];
int rv = 0; int flags = 0, rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
rootdir = xbps_get_rootdir();
if (destdir == NULL) if (rootdir == NULL)
destdir = ""; rootdir = "";
flags = xbps_get_flags();
(void)snprintf(metadir, sizeof(metadir), "%s%s/metadata/%s", (void)snprintf(metadir, sizeof(metadir), "%s%s/metadata/%s",
destdir, XBPS_META_PATH, pkgname); rootdir, XBPS_META_PATH, pkgname);
dirp = opendir(metadir); dirp = opendir(metadir);
if (dirp == NULL) if (dirp == NULL)
@ -89,13 +86,13 @@ xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir, int flags)
continue; continue;
if (snprintf(path, sizeof(path), "%s%s/metadata/%s/%s", if (snprintf(path, sizeof(path), "%s%s/metadata/%s/%s",
destdir, XBPS_META_PATH, pkgname, dp->d_name) < 0) { rootdir, XBPS_META_PATH, pkgname, dp->d_name) < 0) {
(void)closedir(dirp); (void)closedir(dirp);
return -1; return -1;
} }
if ((rv = unlink(path)) == -1) { if ((rv = unlink(path)) == -1) {
if (flags & XBPS_UNPACK_VERBOSE) if (flags & XBPS_VERBOSE)
printf("WARNING: can't remove %s (%s)\n", printf("WARNING: can't remove %s (%s)\n",
pkgname, strerror(errno)); pkgname, strerror(errno));
} }
@ -111,17 +108,22 @@ static int
remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done) remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
{ {
prop_bool_t bobj; prop_bool_t bobj;
struct rm_cbarg *rmcb = arg; const char *file = NULL, *rootdir, *sha256, *type;
const char *file = NULL, *sha256, *type;
char *path = NULL; char *path = NULL;
int rv = 0; int flags = 0, rv = 0;
(void)arg;
(void)loop_done; (void)loop_done;
rootdir = xbps_get_rootdir();
if (rootdir == NULL)
rootdir = "";
flags = xbps_get_flags();
if (!prop_dictionary_get_cstring_nocopy(obj, "file", &file)) if (!prop_dictionary_get_cstring_nocopy(obj, "file", &file))
return EINVAL; return EINVAL;
path = xbps_append_full_path(false, rmcb->destdir, file); path = xbps_append_full_path(false, rootdir, file);
if (path == NULL) if (path == NULL)
return EINVAL; return EINVAL;
@ -150,19 +152,19 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
} }
if (rv == ERANGE) { if (rv == ERANGE) {
if (rmcb->flags & XBPS_UNPACK_VERBOSE) if (flags & XBPS_VERBOSE)
printf("WARNING: SHA256 doesn't match for " printf("WARNING: SHA256 doesn't match for "
"file %s, ignoring...\n", file); "file %s, ignoring...\n", file);
goto out; goto out;
} }
if ((rv = remove(path)) == -1) { if ((rv = remove(path)) == -1) {
if (rmcb->flags & XBPS_UNPACK_VERBOSE) if (flags & XBPS_VERBOSE)
printf("WARNING: can't remove file %s (%s)\n", printf("WARNING: can't remove file %s (%s)\n",
file, strerror(errno)); file, strerror(errno));
goto out; goto out;
} }
if (rmcb->flags & XBPS_UNPACK_VERBOSE) if (flags & XBPS_VERBOSE)
printf("Removed file: %s\n", file); printf("Removed file: %s\n", file);
goto out; goto out;
@ -176,23 +178,23 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
if (errno == ENOTEMPTY) if (errno == ENOTEMPTY)
goto out; goto out;
if (rmcb->flags & XBPS_UNPACK_VERBOSE) { if (flags & XBPS_VERBOSE) {
printf("WARNING: can't remove " printf("WARNING: can't remove "
"directory %s (%s)\n", file, "directory %s (%s)\n", file,
strerror(errno)); strerror(errno));
goto out; goto out;
} }
if (rmcb->flags & XBPS_UNPACK_VERBOSE) if (flags & XBPS_VERBOSE)
printf("Removed directory: %s\n", file); printf("Removed directory: %s\n", file);
} }
} else if (strcmp(type, "link") == 0) { } else if (strcmp(type, "link") == 0) {
if ((rv = remove(path)) == -1) { if ((rv = remove(path)) == -1) {
if (rmcb->flags & XBPS_UNPACK_VERBOSE) if (flags & XBPS_VERBOSE)
printf("WARNING: can't remove link %s (%s)\n", printf("WARNING: can't remove link %s (%s)\n",
file, strerror(errno)); file, strerror(errno));
goto out; goto out;
} }
if (rmcb->flags & XBPS_UNPACK_VERBOSE) if (flags & XBPS_VERBOSE)
printf("Removed link: %s\n", file); printf("Removed link: %s\n", file);
} }
@ -203,10 +205,10 @@ out:
} }
int int
xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags) xbps_remove_binary_pkg(const char *pkgname)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
struct rm_cbarg rmcbarg; const char *rootdir = xbps_get_rootdir();
char path[PATH_MAX - 1], *buf; char path[PATH_MAX - 1], *buf;
int fd, rv = 0; int fd, rv = 0;
size_t len = 0; size_t len = 0;
@ -214,13 +216,13 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
assert(pkgname != NULL); assert(pkgname != NULL);
if (destdir) { if (rootdir) {
if (chdir(destdir) == -1) if (chdir(rootdir) == -1)
return errno; return errno;
} else { } else {
if (chdir("/") == -1) if (chdir("/") == -1)
return errno; return errno;
destdir = ""; rootdir = "";
} }
/* Check if pkg is installed */ /* Check if pkg is installed */
@ -230,13 +232,13 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
/* /*
* This length is '%s%s/metadata/%s/REMOVE' + NULL. * This length is '%s%s/metadata/%s/REMOVE' + NULL.
*/ */
len = strlen(XBPS_META_PATH) + strlen(destdir) + strlen(pkgname) + 19; len = strlen(XBPS_META_PATH) + strlen(rootdir) + strlen(pkgname) + 19;
buf = malloc(len); buf = malloc(len);
if (buf == NULL) if (buf == NULL)
return errno; return errno;
if (snprintf(buf, len, "%s%s/metadata/%s/REMOVE", if (snprintf(buf, len, "%s%s/metadata/%s/REMOVE",
destdir, XBPS_META_PATH, pkgname) < 0) { rootdir, XBPS_META_PATH, pkgname) < 0) {
free(buf); free(buf);
return -1; return -1;
} }
@ -257,7 +259,7 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
prepostf = true; prepostf = true;
(void)printf("\n"); (void)printf("\n");
(void)fflush(stdout); (void)fflush(stdout);
rv = xbps_file_exec(buf, destdir, "pre", pkgname, NULL); rv = xbps_file_exec(buf, rootdir, "pre", pkgname, NULL);
if (rv != 0) { if (rv != 0) {
printf("%s: prerm action target error (%s)\n", pkgname, printf("%s: prerm action target error (%s)\n", pkgname,
strerror(errno)); strerror(errno));
@ -271,7 +273,7 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
* files/dirs associated. * files/dirs associated.
*/ */
(void)snprintf(path, sizeof(path), "%s%s/metadata/%s/files.plist", (void)snprintf(path, sizeof(path), "%s%s/metadata/%s/files.plist",
destdir, XBPS_META_PATH, pkgname); rootdir, XBPS_META_PATH, pkgname);
dict = prop_dictionary_internalize_from_file(path); dict = prop_dictionary_internalize_from_file(path);
if (dict == NULL) { if (dict == NULL) {
@ -279,11 +281,8 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
return errno; return errno;
} }
rmcbarg.destdir = destdir;
rmcbarg.flags = flags;
rv = xbps_callback_array_iter_in_dict(dict, "filelist", rv = xbps_callback_array_iter_in_dict(dict, "filelist",
remove_pkg_files, (void *)&rmcbarg); remove_pkg_files, NULL);
if (rv != 0) { if (rv != 0) {
free(buf); free(buf);
prop_object_release(dict); prop_object_release(dict);
@ -295,7 +294,7 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
* Run the post remove action if REMOVE file is there. * Run the post remove action if REMOVE file is there.
*/ */
if (prepostf) { if (prepostf) {
if ((rv = xbps_file_exec(buf, destdir, "post", if ((rv = xbps_file_exec(buf, rootdir, "post",
pkgname, NULL)) != 0) { pkgname, NULL)) != 0) {
printf("%s: postrm action target error (%s)\n", printf("%s: postrm action target error (%s)\n",
pkgname, strerror(errno)); pkgname, strerror(errno));
@ -322,5 +321,5 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
/* /*
* Remove pkg metadata directory. * Remove pkg metadata directory.
*/ */
return xbps_remove_binary_pkg_meta(pkgname, destdir, flags); return xbps_remove_binary_pkg_meta(pkgname);
} }

View file

@ -35,14 +35,11 @@
#include <xbps_api.h> #include <xbps_api.h>
static int unpack_archive_init(prop_dictionary_t, const char *, static int unpack_archive_init(prop_dictionary_t, const char *);
const char *, int); static int unpack_archive_fini(struct archive *, prop_dictionary_t);
static int unpack_archive_fini(struct archive *, const char *, int,
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, int flags)
{ {
prop_string_t filename, repoloc, arch; prop_string_t filename, repoloc, arch;
char *binfile, *path; char *binfile, *path;
@ -72,15 +69,14 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
} }
free(path); free(path);
rv = unpack_archive_init(pkg, destdir, binfile, flags); rv = unpack_archive_init(pkg, binfile);
free(binfile); free(binfile);
return rv; return rv;
} }
static int static int
unpack_archive_init(prop_dictionary_t pkg, const char *destdir, unpack_archive_init(prop_dictionary_t pkg, const char *binfile)
const char *binfile, int flags)
{ {
struct archive *ar; struct archive *ar;
int pkg_fd, rv; int pkg_fd, rv;
@ -108,7 +104,7 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
return rv; return rv;
} }
rv = unpack_archive_fini(ar, destdir, flags, pkg); rv = unpack_archive_fini(ar, 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).
@ -137,19 +133,29 @@ 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, int flags, unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
prop_dictionary_t pkg)
{ {
struct archive_entry *entry; struct archive_entry *entry;
size_t len; size_t len;
const char *prepost = "./INSTALL"; const char *prepost = "./INSTALL";
const char *pkgname, *version; const char *pkgname, *version, *rootdir;
char *buf; char *buf;
int rv = 0, lflags = 0; int rv = 0, flags = 0, lflags = 0;
bool actgt = false; bool actgt = false;
assert(ar != NULL); assert(ar != NULL);
assert(pkg != NULL); assert(pkg != NULL);
rootdir = xbps_get_rootdir();
flags = xbps_get_flags();
if (rootdir) {
if (chdir(rootdir) == -1)
return errno;
} else {
if (chdir("/") == -1)
return errno;
rootdir = "";
}
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkg, "version", &version); prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
@ -189,7 +195,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
break; break;
} }
if ((rv = xbps_file_exec(buf, destdir, "pre", if ((rv = xbps_file_exec(buf, rootdir, "pre",
pkgname, version, NULL)) != 0) { pkgname, version, NULL)) != 0) {
printf("%s: preinst action target error %s\n", printf("%s: preinst action target error %s\n",
pkgname, strerror(errno)); pkgname, strerror(errno));
@ -212,7 +218,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
(void)fflush(stdout); (void)fflush(stdout);
break; break;
} else if (rv == EEXIST) { } else if (rv == EEXIST) {
if (flags & XBPS_UNPACK_VERBOSE) { if (flags & XBPS_VERBOSE) {
printf("WARNING: ignoring existent " printf("WARNING: ignoring existent "
"path: %s\n", "path: %s\n",
archive_entry_pathname(entry)); archive_entry_pathname(entry));
@ -222,7 +228,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
continue; continue;
} }
} }
if (flags & XBPS_UNPACK_VERBOSE) { if (flags & XBPS_VERBOSE) {
printf(" %s\n", archive_entry_pathname(entry)); printf(" %s\n", archive_entry_pathname(entry));
(void)fflush(stdout); (void)fflush(stdout);
} }
@ -233,7 +239,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
* Run the post installaction action target, if package * Run the post installaction action target, if package
* contains the script. * contains the script.
*/ */
if ((rv = xbps_file_exec(buf, destdir, "post", if ((rv = xbps_file_exec(buf, rootdir, "post",
pkgname, version, NULL)) != 0) { pkgname, version, NULL)) != 0) {
printf("%s: postinst action target error %s\n", printf("%s: postinst action target error %s\n",
pkgname, strerror(errno)); pkgname, strerror(errno));

View file

@ -35,6 +35,7 @@
#include <xbps_api.h> #include <xbps_api.h>
static const char *rootdir; static const char *rootdir;
static int flags;
int int
xbps_check_file_hash(const char *path, const char *sha256) xbps_check_file_hash(const char *path, const char *sha256)
@ -238,6 +239,24 @@ xbps_set_rootdir(const char *dir)
rootdir = dir; rootdir = dir;
} }
const char *
xbps_get_rootdir(void)
{
return rootdir;
}
void
xbps_set_flags(int lflags)
{
flags = lflags;
}
int
xbps_get_flags(void)
{
return flags;
}
char * char *
xbps_append_full_path(bool use_rootdir, const char *basedir, const char *plist) xbps_append_full_path(bool use_rootdir, const char *basedir, const char *plist)
{ {