poldek: poldek/pkgiter.c (NEW), poldek/pkg.h, poldek/split.c, pold...
mis
mis at pld-linux.org
Tue Jan 22 12:40:34 CET 2008
Author: mis Date: Tue Jan 22 11:40:34 2008 GMT
Module: poldek Tag: HEAD
---- Log message:
- pkg.c: pkg_{required,owned}_dirs()
- pkgiter.c: package caps and reqs iterators
- restricted visibility to PKG_COLOR* macros
---- Files affected:
poldek/poldek:
pkgiter.c (NONE -> 1.1) (NEW), pkg.h (1.80 -> 1.81) , split.c (1.24 -> 1.25) , pkgset-order.c (1.32 -> 1.33) , pkg.c (1.119 -> 1.120)
---- Diffs:
================================================================
Index: poldek/poldek/pkgiter.c
diff -u /dev/null poldek/poldek/pkgiter.c:1.1
--- /dev/null Tue Jan 22 12:40:34 2008
+++ poldek/poldek/pkgiter.c Tue Jan 22 12:40:29 2008
@@ -0,0 +1,196 @@
+/*
+ Copyright (C) 2000 - 2005 Pawel A. Gajda <mis at pld-linux.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License, version 2 as
+ published by the Free Software Foundation (see file COPYING for details).
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ $Id$
+*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <trurl/nstr.h>
+#include <trurl/nassert.h>
+
+#define ENABLE_TRACE 0
+#include "i18n.h"
+#include "log.h"
+#include "capreq.h"
+#include "pkg.h"
+#include "pkgfl.h"
+
+/* caps, mean caps + owned files iterator */
+struct pkg_cap_iter {
+ struct pkg *pkg;
+ struct capreq *cap;
+ int ncap;
+ struct pkgfl_it fit;
+ int fit_initialized;
+};
+
+
+struct pkg_cap_iter *pkg_cap_iter_new(struct pkg *pkg)
+{
+ struct pkg_cap_iter *it = n_calloc(sizeof(*it), 1);
+ it->pkg = pkg;
+ it->ncap = 0;
+ it->cap = NULL;
+ it->fit_initialized = 0;
+ return it;
+}
+
+void pkg_cap_iter_free(struct pkg_cap_iter *it)
+{
+ if (it->cap)
+ capreq_free(it->cap);
+ memset(it, 0, sizeof(*it));
+}
+
+const struct capreq *pkg_cap_iter_get(struct pkg_cap_iter *it)
+{
+ struct capreq *cap;
+ const char *path;
+ struct flfile *flfile = NULL;
+
+ if (it->pkg->caps && it->ncap < n_array_size(it->pkg->caps)) {
+ cap = n_array_nth(it->pkg->caps, it->ncap);
+ it->ncap++;
+ return cap;
+ }
+
+ if (it->cap) {
+ capreq_free(it->cap);
+ it->cap = NULL;
+ }
+
+ if (it->pkg->fl == NULL)
+ return NULL;
+
+ if (!it->fit_initialized) {
+ pkgfl_it_init(&it->fit, it->pkg->fl);
+ it->fit_initialized = 1;
+ }
+
+ path = pkgfl_it_get(&it->fit, &flfile);
+ if (path) {
+ unsigned flags = CAPREQ_BASTARD;
+ if (S_ISDIR(flfile->mode))
+ flags |= CAPREQ_ISDIR;
+
+ it->cap = capreq_new(NULL, path, 0, NULL, NULL, 0, flags);
+ }
+ return it->cap;
+}
+
+
+/* requirements iterator */
+struct pkg_req_iter {
+ const struct pkg *pkg;
+ unsigned flags;
+
+ int nreq;
+ int nsug;
+
+ tn_array *requiredirs;
+ struct capreq *req;
+ int ndir;
+};
+
+struct pkg_req_iter *pkg_req_iter_new(const struct pkg *pkg, unsigned flags)
+{
+ struct pkg_req_iter *it = n_calloc(sizeof(*it), 1);
+ it->pkg = pkg;
+
+ if (flags == 0)
+ flags = PKG_ITER_REQIN;
+
+ it->flags = flags;
+ it->req = NULL;
+ it->requiredirs = NULL;
+ return it;
+}
+
+void pkg_req_iter_free(struct pkg_req_iter *it)
+{
+ if (it->req)
+ capreq_free(it->req);
+ n_array_cfree(&it->requiredirs);
+ memset(it, 0, sizeof(*it));
+}
+
+const struct capreq *pkg_req_iter_get(struct pkg_req_iter *it)
+{
+ struct capreq *req;
+
+ if (it->pkg->reqs && it->nreq < n_array_size(it->pkg->reqs)) {
+ req = n_array_nth(it->pkg->reqs, it->nreq);
+ it->nreq++;
+
+ if ((it->flags & PKG_ITER_REQUN) && !capreq_is_prereq_un(req))
+ return pkg_req_iter_get(it);
+
+ else if ((it->flags & PKG_ITER_REQUN) == 0 && capreq_is_prereq_un(req))
+ return pkg_req_iter_get(it);
+
+ return req;
+ }
+
+ if ((it->flags & PKG_ITER_REQSUG)) {
+ if (it->pkg->sugs && it->nsug < n_array_size(it->pkg->sugs)) {
+ req = n_array_nth(it->pkg->sugs, it->nsug);
+ it->nsug++;
+
+ return req;
+ }
+ }
+
+ if ((it->flags & PKG_ITER_REQDIR) == 0) /* without required directories */
+ return NULL;
+
+ /* already got dirs in pkg->reqs */
+ if (it->pkg->flags & PKG_INCLUDED_DIRREQS)
+ return NULL;
+
+ if (it->req) {
+ capreq_free(it->req);
+ it->req = NULL;
+ }
+
+ if (it->requiredirs == NULL) {
+ it->requiredirs = pkg_required_dirs(it->pkg);
+ if (it->requiredirs == NULL)
+ return NULL;
+ it->ndir = 0;
+ }
+
+ if (it->ndir < n_array_size(it->requiredirs)) {
+ const char *path = n_array_nth(it->requiredirs, it->ndir);
+ char tmp[PATH_MAX];
+
+ n_snprintf(tmp, sizeof(tmp), "/%s", path);
+
+ it->ndir++;
+ it->req = capreq_new(NULL, tmp, 0, NULL, NULL, 0,
+ CAPREQ_BASTARD | CAPREQ_ISDIR);
+ return it->req;
+ }
+
+ return NULL;
+}
+
================================================================
Index: poldek/poldek/pkg.h
diff -u poldek/poldek/pkg.h:1.80 poldek/poldek/pkg.h:1.81
--- poldek/poldek/pkg.h:1.80 Sun Jul 8 18:50:58 2007
+++ poldek/poldek/pkg.h Tue Jan 22 12:40:29 2008
@@ -16,28 +16,32 @@
struct pkgdir; /* defined in pkgdir/pkgdir.h */
-#define PKG_HAS_PKGUINF (1 << 5)
-#define PKG_HAS_SELFCAP (1 << 6)
+#define PKG_HAS_PKGUINF (1 << 5) /* user-level info (pkgu.c) */
+#define PKG_HAS_SELFCAP (1 << 6) /* name = e:v-r cap */
#define PKG_HELD (1 << 12) /* non upgradable */
#define PKG_IGNORED (1 << 13) /* invisible */
#define PKG_IGNORED_UNIQ (1 << 14) /* uniqued */
#define PKG_ORDER_PREREQ (1 << 15) /* see pkgset-order.c */
+
#define PKG_DBPKG (1 << 16) /* loaded from database, i.e. installed */
+#define PKG_INCLUDED_DIRREQS (1 << 17) /* auto-dir-reqs added directly to reqs */
-/* DAG node colours */
-#define PKG_COLOR_WHITE (1 << 20)
-#define PKG_COLOR_GRAY (1 << 21)
-#define PKG_COLOR_BLACK (1 << 22)
-#define PKG_ALL_COLORS PKG_COLOR_WHITE | PKG_COLOR_GRAY | PKG_COLOR_BLACK
+#ifdef POLDEK_PKG_DAG_COLOURS
+/* DAG node colours (pkgset-order.c, split.c) */
+# define PKG_COLOR_WHITE (1 << 20)
+# define PKG_COLOR_GRAY (1 << 21)
+# define PKG_COLOR_BLACK (1 << 22)
+# define PKG_ALL_COLORS PKG_COLOR_WHITE | PKG_COLOR_GRAY | PKG_COLOR_BLACK
/* colours */
-#define pkg_set_color(pkg, color) \
+# define pkg_set_color(pkg, color) \
((pkg)->flags &= ~(PKG_ALL_COLORS), (pkg)->flags |= (color))
-#define pkg_is_color(pkg, color) \
+# define pkg_is_color(pkg, color) \
((pkg)->flags & color)
+#endif /* POLDEK_PKG_DAG_COLOURS */
#define pkg_set_prereqed(pkg) ((pkg)->flags |= PKG_ORDER_PREREQ)
#define pkg_clr_prereqed(pkg) ((pkg)->flags &= ~PKG_ORDER_PREREQ)
@@ -270,12 +274,23 @@
tn_buf *pkgs_array_join(tn_array *pkgs, tn_buf *nbuf, const char *sep);
+/* caps & reqs iterators */
struct pkg_cap_iter *pkg_cap_iter_new(struct pkg *pkg);
void pkg_cap_iter_free(struct pkg_cap_iter *it);
const struct capreq *pkg_cap_iter_get(struct pkg_cap_iter *it);
+#define PKG_ITER_REQIN (1 << 0) /* Requires + Requires(pre) */
+#define PKG_ITER_REQUN (1 << 1) /* Requires(un) */
+#define PKG_ITER_REQDIR (1 << 2) /* Requires(dir) */
+#define PKG_ITER_REQSUG (1 << 3) /* Suggests */
+
+struct pkg_req_iter *pkg_req_iter_new(const struct pkg *pkg, unsigned flags);
+void pkg_req_iter_free(struct pkg_req_iter *it);
+const struct capreq *pkg_req_iter_get(struct pkg_req_iter *it);
+
+
#endif
#endif /* POLDEK_PKG_H */
================================================================
Index: poldek/poldek/split.c
diff -u poldek/poldek/split.c:1.24 poldek/poldek/split.c:1.25
--- poldek/poldek/split.c:1.24 Sun Aug 20 20:14:58 2006
+++ poldek/poldek/split.c Tue Jan 22 12:40:29 2008
@@ -29,6 +29,7 @@
#include <vfile/vfile.h>
+#define POLDEK_PKG_DAG_COLOURS 1 /* for pkg_*color */
#include "i18n.h"
#include "pkgset.h"
#include "pkgset-req.h"
================================================================
Index: poldek/poldek/pkgset-order.c
diff -u poldek/poldek/pkgset-order.c:1.32 poldek/poldek/pkgset-order.c:1.33
--- poldek/poldek/pkgset-order.c:1.32 Sun Dec 17 18:33:25 2006
+++ poldek/poldek/pkgset-order.c Tue Jan 22 12:40:29 2008
@@ -22,6 +22,7 @@
#include "i18n.h"
#include "log.h"
+#define POLDEK_PKG_DAG_COLOURS 1 /* for pkg_*color */
#include "pkg.h"
#include "pkgset.h"
#include "misc.h"
================================================================
Index: poldek/poldek/pkg.c
diff -u poldek/poldek/pkg.c:1.119 poldek/poldek/pkg.c:1.120
--- poldek/poldek/pkg.c:1.119 Thu Jul 12 23:29:26 2007
+++ poldek/poldek/pkg.c Tue Jan 22 12:40:29 2008
@@ -230,7 +230,6 @@
DBGF("+%p %p %d\n", na, &na->_refcnt, na->_refcnt);
}
- pkg->flags |= PKG_COLOR_WHITE;
pkg->epoch = epoch;
pkg->size = size;
pkg->fsize = fsize;
@@ -309,7 +308,7 @@
return pkg;
}
-#if 0 /* nfy */
+#if 0 /* XXX: NFY */
static tn_array *clone_array(tn_array *arr, unsigned flags)
{
flags = flags;
@@ -566,72 +565,6 @@
return cap_xmatch_req(cap, req, strict ? 0 : POLDEK_MA_PROMOTE_VERSION);
}
-#if 0
-static inline
-int OLDdo_pkg_evr_match_req(const struct pkg *pkg, const struct capreq *req,
- int promote_epoch)
-{
- register int cmprc = 0, evr = 0;
-
-
- n_assert(strcmp(pkg->name, capreq_name(req)) == 0);
-
- if (!capreq_versioned(req))
- return 1;
-
- if (promote_epoch == -1)
- promote_epoch = poldek_conf_PROMOTE_EPOCH;
-
- if (pkg->epoch || capreq_has_epoch(req)) {
- int promote = 0;
- if (!capreq_has_epoch(req) && promote_epoch) {
- promote_epoch_warn(1, "req", capreq_snprintf_s(req),
- pkg_evr_snprintf_s(pkg));
- promote = 1;
- }
-
- if (!pkg->epoch && capreq_epoch(req) > 0 && promote_epoch) {
- promote_epoch_warn(1, "package", pkg_evr_snprintf_s(pkg),
- capreq_snprintf_s(req));
- promote = 1;
- }
-
- if (promote) {
- cmprc = 0;
-
- } else {
- cmprc = pkg->epoch - capreq_epoch(req);
- if (cmprc != 0)
- return rel_match(cmprc, req);
- }
- evr = 1;
-
- }
-#if 0 /* disabled autopromotion */
- else if (capreq_epoch(req) > 0) { /* always promote package's epoch */
- cmprc = 0;
- evr = 1;
- }
-#endif
-
- if (capreq_has_ver(req)) {
- cmprc = pkg_version_compare(pkg->ver, capreq_ver(req));
- if (cmprc != 0)
- return rel_match(cmprc, req);
- evr = 1;
- }
-
- if (capreq_has_rel(req)) {
- n_assert(capreq_has_ver(req));
- cmprc = pkg_version_compare(pkg->rel, capreq_rel(req));
- if (cmprc != 0)
- return rel_match(cmprc, req);
- evr = 1;
- }
-
- return evr ? rel_match(cmprc, req) : 1;
-}
-#endif
static inline
int do_pkg_evr_match_req(const struct capreq *pkgcap, const struct capreq *req,
@@ -766,6 +699,7 @@
return rc;
}
+
int pkg_xmatch_req(const struct pkg *pkg, const struct capreq *req, unsigned flags)
{
if (n_str_eq(pkg->name, capreq_name(req))) {
@@ -797,9 +731,14 @@
char *dirname, *basename, path[PATH_MAX];
strncpy(path, capreq_name(req), sizeof(path));
+
path[PATH_MAX - 1] = '\0';
n_basedirnam(path, &dirname, &basename);
n_assert(dirname);
+
+ if (*dirname == '\0') /* path = "/foo" */
+ dirname = "/";
+
n_assert(*dirname);
if (*dirname == '/' && *(dirname + 1) != '\0')
dirname++;
@@ -971,12 +910,33 @@
tn_array *pkg_required_dirs(const struct pkg *pkg)
{
if (pkg->pkgdir && pkg->pkgdir->dirindex)
- return pkgdir_dirindex_get_reqdirs(pkg->pkgdir, pkg);
+ return pkgdir_dirindex_get_required(pkg->pkgdir, pkg);
+
+ if (pkg->fl) {
+ tn_array *owned = NULL, *required = NULL;
+ pkgfl_owned_and_required_dirs(pkg->fl, &owned, &required);
+ n_array_cfree(&owned);
+ return required;
+ }
+
return NULL;
}
-static
-tn_tuple *do_pkg_other_fl(tn_alloc *na, const struct pkg *pkg)
+tn_array *pkg_owned_dirs(const struct pkg *pkg)
+{
+ if (pkg->pkgdir && pkg->pkgdir->dirindex)
+ return pkgdir_dirindex_get_provided(pkg->pkgdir, pkg);
+
+ if (pkg->fl) {
+ tn_array *owned = NULL, *required = NULL;
+ pkgfl_owned_and_required_dirs(pkg->fl, &owned, &required);
+ n_array_cfree(&required);
+ return owned;
+ }
+ return NULL;
+}
+
+static tn_tuple *do_pkg_other_fl(tn_alloc *na, const struct pkg *pkg)
{
tn_tuple *fl = NULL;
@@ -1327,9 +1287,10 @@
if (prefix == NULL)
prefix = "array";
- msg(0, "%s = [", prefix);
+ msg(0, "%s = [ ", prefix);
for (i=0; i<n_array_size(pkgs); i++)
- msg(0, "%s, ", pkg_id(n_array_nth(pkgs, i)));
+ msg(0, "%s%s", pkg_id(n_array_nth(pkgs, i)),
+ i + 1 == n_array_size(pkgs) ? " ":", ");
msgn(0, "]");
}
@@ -1437,59 +1398,3 @@
pkg_arch(pkg));
}
-/* caps, mean caps + files iterator */
-struct pkg_cap_iter {
- struct pkg *pkg;
- struct capreq *cap;
- int ncap;
- struct pkgfl_it fit;
- int fit_initialized;
-};
-
-const struct capreq *pkg_cap_iter_get(struct pkg_cap_iter *it)
-{
- struct capreq *cap;
- const char *path;
-
- if (it->pkg->caps && it->ncap < n_array_size(it->pkg->caps)) {
- cap = n_array_nth(it->pkg->caps, it->ncap);
- it->ncap++;
- return cap;
- }
-
- if (it->cap) {
- capreq_free(it->cap);
- it->cap = NULL;
- }
-
- if (it->pkg->fl == NULL)
- return NULL;
-
- if (!it->fit_initialized) {
- pkgfl_it_init(&it->fit, it->pkg->fl);
- it->fit_initialized = 1;
- }
-
- path = pkgfl_it_get(&it->fit, NULL);
- if (path)
- it->cap = capreq_new(NULL, path, 0, NULL, NULL, 0, 0);
-
- return it->cap;
-}
-
-struct pkg_cap_iter *pkg_cap_iter_new(struct pkg *pkg)
-{
- struct pkg_cap_iter *it = n_calloc(sizeof(*it), 1);
- it->pkg = pkg;
- it->ncap = 0;
- it->cap = NULL;
- it->fit_initialized = 0;
- return it;
-}
-
-void pkg_cap_iter_free(struct pkg_cap_iter *it)
-{
- if (it->cap)
- capreq_free(it->cap);
- memset(it, 0, sizeof(*it));
-}
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/pkg.h?r1=1.80&r2=1.81&f=u
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/split.c?r1=1.24&r2=1.25&f=u
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/pkgset-order.c?r1=1.32&r2=1.33&f=u
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/pkg.c?r1=1.119&r2=1.120&f=u
More information about the pld-cvs-commit
mailing list