ZPKGBIN=zpm-addfile zpm-extract zpm-init zpm-vercmp zpm-stat zpm-hash \
zpm-findpkg zpm-shell zpm-soneed zpm-foreach-path zpm-parse \
zpm-script zpm-soname zpm-syncfs zpm-packagehash zpm-verify \
- zpm-elftype zpm-quote zpm-note zpm-search
+ zpm-elftype zpm-quote zpm-note zpm-search zpm-add
SCRIPTS=zpm zpm-install zpm-merge zpm-list zpm-preserve zpm-test zpm-log \
zpm-contents zpm-uninstall zpm-pathmod zpm-rmpackage zpm-newpackage \
- zpm-pkg zpm-add zpm-pkgfile zpm-gc zpm-repo zpm-update zpm-confgit
+ zpm-pkg zpm-pkgfile zpm-gc zpm-repo zpm-update zpm-confgit
+
MANPAGES=doc/zpm.8 $(addprefix doc/zpm-, list.8 contents.8 hash.8 quote.8 pathmod.8 note.8 vercmp.8 repo.8)
COMPILED=$(ZPKGBIN)
PROGRAMS=$(SCRIPTS) $(COMPILED)
zpm-parse: zpm-parse.o lib/parse.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
+zpm-add: zpm-add.o lib/parse.o libzpm.a
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ -lzpm -lelf
+
zpm-quote: zpm-quote.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
-#define _POSIX_C_SOURCE 2
+#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "sqlite3.h"
#include "zpm.h"
+void zpm_file_init(struct zpm_file *file) {
+ file->package = 0;
+ file->version = 0;
+ file->release = 0;
+ file->path = 0;
+ file->owner = 0;
+ file->group = 0;
+ file->target = 0;
+ file->status = 0;
+ file->hash[0] = 0;
+ file->confhash[0] = 0;
+ file->configuration = 0;
+ file->type = 0;
+ file->mode = 0;
+ file->device = 0;
+}
+
+void zpm_file_free(struct zpm_file *file) {
+ free(file->package);
+ free(file->version);
+ free(file->path);
+ free(file->owner);
+ free(file->group);
+ free(file->target);
+ free(file->status);
+ zpm_file_init(file);
+}
+
+#define getstring(x,n) ((const char *)sqlite3_column_text(x,n))
+
+int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
+int (*callback)(struct zpm *, struct zpm_file *, void *),
+void *data) {
+ char *sql;
+ sqlite3_str *s;
+ sqlite3_stmt *st;
+ struct zpm_file file = { 0 };
+ int rv;
+
+ zpm_file_init(&file);
+
+ if (!zpm || zpm->error || !callback) return 0;
+
+ s = sqlite3_str_new(zpm->db);
+ sqlite3_str_appendall(s, "select package,version,release,path,filetype,mode,username,groupname,configuration,target,device,hash,confhash,status from packagefiles_status where ");
+
+ if (where) {
+ sqlite3_str_appendf(s, "%s", where);
+ } else {
+ sqlite3_str_appendall(s, "true");
+ }
+
+ if (pkgid) {
+ sqlite3_str_appendf(s, " and printf('%%s-%%s-%%s', package, version, release) = %Q", pkgid);
+ }
+
+ sql = sqlite3_str_value(s);
+ if (!sql) {
+ sqlite3_str_finish(s);
+ zpm->error = 1;
+ return 0;
+ }
+
+ st = zpm_dbquery(zpm, sql);
+ sqlite3_str_finish(s);
+
+ while (sqlite3_step(st) == SQLITE_ROW) {
+ const char *val;
+
+ val = getstring(st, 0);
+ file.package = val ? strdup(val) : 0;
+
+ val = getstring(st, 1);
+ file.version = val ? strdup(val) : 0;
+
+ file.release = sqlite3_column_int(st, 2);
+
+ val = getstring(st, 3);
+ file.path = val ? strdup(val) : 0;
+
+ val = getstring(st, 4);
+ file.type = val ? *val : 0;
+
+ val = getstring(st, 5);
+ file.mode = val ? strtol(val, NULL, 8) : 0;
+
+ val = getstring(st, 6);
+ file.owner = val ? strdup(val) : 0;
+
+ val = getstring(st, 7);
+ file.group = val ? strdup(val) : 0;
+
+ file.configuration = sqlite3_column_int(st, 8);
+
+ val = getstring(st, 9);
+ file.target = val ? strdup(val) : 0;
+
+ val = getstring(st, 10);
+ file.device = val ? strtol(val, NULL, 10) : 0;
+
+ val = getstring(st, 11);
+ if (val) {
+ strncpy(file.hash, val, ZPM_HASH_STRLEN);
+ file.hash[ZPM_HASH_STRLEN] = 0;
+ }
+
+ val = getstring(st, 12);
+ if (val) {
+ strncpy(file.hash, val, ZPM_HASH_STRLEN);
+ file.confhash[ZPM_HASH_STRLEN] = 0;
+ }
+
+ val = getstring(st, 13);
+ file.status = val ? strdup(val) : 0;
+
+ rv = callback(zpm, &file, data);
+ zpm_file_free(&file);
+
+ if (rv != 0) {
+ break;
+ }
+ }
+
+ zpm->dbresult = sqlite3_finalize(st);
+
+ if (rv != 0) {
+ zpm->error = rv;
+ return 0;
+ }
+
+ if (zpm->dbresult != SQLITE_OK) {
+ free(zpm->dberrmsg);
+ zpm->dberrmsg = strdup(sqlite3_errmsg(zpm->db));
+ return 0;
+ }
+
+ zpm->error = 0;
+
+ return 1;
+}
+
int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
int (*callback)(void *f, int ncols, char **vals, char **cols),
void *data, char **errmsg) {
pkgid=zpmtest-1.0-1
PF=zpmtest-1.0-1.zpm
-require zpm newpackage -C $pkgid
-require zpm add $pkgid foo
+require -v zpm newpackage -C $pkgid
+require -v zpm add -vvv -f $PF $pkgid foo
h=$(zpm hash foo)
-require zpm extract -f zpmtest-1.0-1.zpm $h foo2
+require -v zpm extract -f zpmtest-1.0-1.zpm $h foo2
h2=$(zpm hash foo2)
okstreq "$h" "$h2" "foo and foo2 hash match"
mkdir subdir
touch subdir/foo
require zpm newpackage -f $PF -C $pkgid
-require zpm add -f $PF -S subdir zpmtest subdir/foo
+require -v zpm add -f $PF -S subdir zpmtest subdir/foo
fn=$(zpm showpkg $PF | awk '{print $4}')
okstreq "$fn" "/foo" file foo in package prefix striped
rm -f $PF
where PL.pkgid = %Q\
";
+static int afind_strcmp(const void *a, const void *b) {
+ return strcmp(a, b);
+}
+
void checklibs(struct search_ctl *opts,
jsw_hash_t *check, jsw_hash_t *forlibs, jsw_hash_t *nfound) {
char *pkgid = 0, *pkgfile = 0;
jsw_atrav_t *i;
char *soname;
- checked = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free);
- checked_libs = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free);
+ checked = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free);
+ checked_libs = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free);
while (jsw_hsize(check) > 0) {
free(pkgid);
if (jsw_afind(checked, pkgid)) {
/* already checked this one */
+ /* fprintf(stderr, "already checked %s\n", pkgid); */
continue;
}
+ fprintf(stderr, "checking libs for %s\n", pkgid);
/* we do this now so we catch self deps */
- jsw_ainsert(checked, pkgid);
+ if (!jsw_ainsert(checked, pkgid)) {
+ fprintf(stderr, "checked insert failed\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (!jsw_afind(checked, pkgid)) {
+ /* already checked this one */
+ fprintf(stderr, "checked find failed\n");
+ exit(EXIT_FAILURE);
+ }
/* get the libraries needed by this package */
if (!zpm_open(&src, pkgfile)) {
}
if (needed) jsw_adelete(needed);
- needed = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free);
+ needed = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free);
libs = zpm_libraries_needed(&src, pkgid, needed);
zpm_close(&src);
int found;
struct pkgloc pkginfo;
- if (opts->verbose > 1) {
- fprintf(stderr, "checking for %s\n", soname);
- }
/* if it's in checked_libs, we've already looked at this one */
if (jsw_afind(checked_libs, soname)) {
if (opts->verbose > 1) {
- fprintf(stderr, "already checked for %s\n", soname);
+ fprintf(stderr, "already checked %s\n", soname);
}
continue;
}
+#if 0
+ if (opts->verbose > 1) {
+ fprintf(stderr, "checking for %s\n", soname);
+ }
+#endif
/* haven't found this soname */
jsw_ainsert(checked_libs, soname);
fprintf(stderr, "\n");
}
- packages = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup,
+ /* direct packages asked for */
+ packages = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup,
(itemdup_f)strdup,free,free);
- check = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup,
+
+ /* packages we need to check for libs */
+ check = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup,
(itemdup_f)strdup,free,free);
- forlibs = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup,
+
+ /* packages we will also need for library dependences */
+ forlibs = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup,
(itemdup_f)strdup,free,free);
- nolib = jsw_hnew(ac,NULL,(cmp_f)strcmp,(keydup_f)strdup,
+
+ /* libraries we didn't find */
+ nolib = jsw_hnew(ac,NULL,afind_strcmp,(keydup_f)strdup,
(itemdup_f)strdup,free,free);
- nfound = jsw_anew((cmp_f)strcmp, (dup_f)strdup, (rel_f)free);
+
+ /* packages asked for that we can't find */
+ nfound = jsw_anew(afind_strcmp, (dup_f)strdup, (rel_f)free);
int arg;
for (arg = argn; arg < ac; arg++) {
} else {
jsw_ainsert(nfound, av[arg]);
}
-
}
if (findlibs) {
int zpm_quote(char *value, char *dest, size_t n);
struct zpm_file {
- char path[ZPM_PATH_MAX];
- int mode;
+ char *package;
+ char *version;
+ int release;
+
+ char *status;
+ char *path;
+ char *target;
+
+ mode_t mode;
+
//struct zpm_tree *tags;
- char owner[32];
- char group[32];
+
+ char *owner;
+ char *group;
+ gid_t gid;
+ uid_t uid;
+
+ int configuration;
time_t mtime;
+ char type;
+ dev_t device;
char hash[ZPM_HASH_STRLEN+1];
+ char confhash[ZPM_HASH_STRLEN+1];
+ void *data; /* hook for applications to attach data */
struct zpm_file *next; /* so you can make a linked list */
};
int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
int (*callback)(void *f, int ncols, char **vals, char **cols),
void *data, char **errmsg);
+
+int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
+int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd);
+
int zpm_foreach_package(struct zpm *zpm, char *where,
int (*callback)(void *cbdata, int ncols, char **vals, char **cols),
void *data, char **errmsg);