PERFORCE change 164836 for review
David Forsythe
dforsyth at FreeBSD.org
Mon Jun 22 04:19:44 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164836
Change 164836 by dforsyth at squirrel on 2009/06/22 04:18:50
Added a few fields to pkg_plist.
Affected files ...
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#23 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#22 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#15 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#12 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#16 edit
Differences ...
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#23 (text+ko) ====
@@ -237,6 +237,44 @@
return (pkg_plist_mtree_file(&p->plist));
}
+/* Other properties. */
+
+int
+pkg_extract_in_place(struct pkg *p)
+{
+ if (p == NULL)
+ arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+ if (pkg_parse_plist(p) != OK)
+ return (PKG_PARSE_NOT_OK);
+
+ return (pkg_plist_extract_in_place(&p->plist));
+}
+
+int
+pkg_preserve(struct pkg *p)
+{
+ if (p == NULL)
+ arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+ if (pkg_parse_plist(p) != OK)
+ return (PKG_PARSE_NOT_OK);
+
+ return (pkg_plist_preserve(&p->plist));
+}
+
+int
+pkg_complete(struct pkg *p)
+{
+ if (p == NULL)
+ arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+ if (pkg_parse_plist(p) != OK)
+ return (PKG_PARSE_NOT_OK);
+
+ return (pkg_plist_complete(&p->plist));
+}
+
/* These need to be renamed. */
void
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#22 (text+ko) ====
@@ -67,6 +67,8 @@
const char *pkg_file_group(struct pkg_file *pf);
+const char *pkg_file_mode(struct pkg_file *pf);
+
int pkg_file_set_path(struct pkg_file *pf, const char *path);
int pkg_file_set_md5(struct pkg_file *pf, const char *md5);
@@ -75,6 +77,8 @@
int pkg_file_set_group(struct pkg_file *pf, const char *group);
+int pkg_file_set_mode(struct pkg_file *pf, const char *mode);
+
/* pkg_dep */
struct pkg_dep;
@@ -115,6 +119,12 @@
char *pkg_mtree_file(struct pkg *p);
+int pkg_extract_in_place(struct pkg *p);
+
+int pkg_preserve(struct pkg *p);
+
+int pkg_complete(struct pkg *p);
+
int pkg_set_ident(struct pkg *p, const char *ident);
int pkg_set_name(struct pkg *p, const char *name);
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#5 (text+ko) ====
@@ -4,6 +4,9 @@
#include "pkg_file.h"
#include "pkg.h"
+/* TODO: Evolve these functions to check for the actual existance of
+ * users, groups, mode validity. Add md5 comparison functions, etc... */
+
struct pkg_file *
pkg_file_new()
{
@@ -32,6 +35,15 @@
return (pf->md5);
}
+const char *
+pkg_file_mode(struct pkg_file *pf)
+{
+ if (pf == NULL)
+ return (NULL);
+
+ return (pf->mode);
+}
+
/* If NULL is returned from pkg_file_owner or pkg_file_group, assume the
* default owner and group. */
@@ -92,3 +104,13 @@
pf->group = group;
return (OK);
}
+
+int
+pkg_file_set_mode(struct pkg_file *pf, const char *mode)
+{
+ if (pf == NULL)
+ return (NOT_OK);
+
+ pf->mode = mode;
+ return (OK);
+}
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#4 (text+ko) ====
@@ -10,6 +10,7 @@
const char *md5;
const char *owner;
const char *group;
+ const char *mode;
TAILQ_ENTRY(pkg_file) next;
};
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#15 (text+ko) ====
@@ -16,10 +16,13 @@
#include "pkgdb.h"
#include "pkg.h"
+/* TODO: Create plist setter functions for building packages. */
+
struct parse_state {
enum plist_elem last_elem;
char *owner;
char *group;
+ char *mode;
};
void
@@ -31,6 +34,7 @@
st->last_elem = PLIST_UNKNOWN;
st->owner = NULL;
st->group = NULL;
+ st->mode = NULL;
}
struct pkg_plist *
@@ -71,6 +75,10 @@
/* TODO: Write this. */
+ pl->extract_in_place = 0;
+ pl->preserve = 0;
+ pl->complete = 0;
+
pl->parsed = 0;
}
@@ -101,6 +109,8 @@
if (pl == NULL)
return (NOT_OK);
+
+ pkg_plist_reset(pl);
/* Not sure if this is how I still want to do this, but for now, hold
* a copy of the text. */
@@ -109,8 +119,10 @@
return (MEMORY_ERR);
pl->text = textp;
-
- /* XXX: Use fgets(), dummy. */
+
+ /* TODO: Use fgets(), and have the different lists have their own copy
+ * of information so that packages can be freely manipulated without
+ * worrying about ruining other instances of a package. */
pkg_plist_pkg_file_list_init(pl);
pkg_plist_pkg_dep_list_init(pl);
set_parse_state_default(&st);
@@ -128,7 +140,7 @@
/* Consider a dirty flag for these lists? */
#if 0
- if (s != 0) {
+ if (s != PARSE_OK) {
/* bad parse. */
/* free a bunch of stuff. */
return (NOT_OK);
@@ -183,13 +195,24 @@
ent = pl_entry_new(PLIST_EXEC, argument, NULL);
else if (strcmp(command, PLIST_CMD_UNEXEC) == 0)
ent = pl_entry_new(PLIST_UNEXEC, argument, NULL);
- else if (strcmp(command, PLIST_CMD_MODE) == 0)
- ent = pl_entry_new(PLIST_MODE, argument, NULL);
- else if (strcmp(command, PLIST_CMD_OPTION) == 0)
- ent = pl_entry_new(PLIST_OPTION, argument, NULL);
#endif
- else if (strcmp(command, PLIST_CMD_OWNER) == 0) {
- if (line_len == strlen(PLIST_CMD_OWNER) + 1)
+ else if (strcmp(command, PLIST_CMD_OPTION) == 0) {
+ if (strcmp(argument, PLIST_OPTION_EXTRACT_IN_PLACE) == 0) {
+ pl->extract_in_place = 1;
+ } else if (strcmp(argument, PLIST_OPTION_PRESERVE) == 0) {
+ pl->preserve = 1;
+ } else if (strcmp(argument, PLIST_OPTION_COMPLETE) == 0) {
+ pl->complete = 1;
+ } else
+ return (PARSE_FAIL); /* Strict. */
+ st->last_elem = PLIST_OPTION;
+ } else if (strcmp(command, PLIST_CMD_MODE) == 0) {
+ if (line_len == strlen(PLIST_CMD_MODE) + 1)
+ st->mode = NULL;
+ else
+ st->mode = argument;
+ } else if (strcmp(command, PLIST_CMD_OWNER) == 0) {
+ if (line_len == strlen(PLIST_CMD_OWNER) + 1)
/* Empty owner line, reset to NULL. */
st->owner = NULL;
else
@@ -208,8 +231,6 @@
/* Lots more stuff needs to go in here... what a terrible file
* format... */
- /* mmm... should probably pull this out into a different
- * function. */
if (line_len == strlen(PLIST_CMD_COMMENT) + 1) {
/* Empty comment. */
}
@@ -230,6 +251,8 @@
} else if (strcmp(argument, PLIST_COMMENT_ORIGIN) == 0) {
pl->origin = sep + 1;
} else if (strcmp(argument, PLIST_COMMENT_DEPORIGIN) == 0) {
+ /* NOTE: I'm going to have to adjust the parse so it can
+ * deal with package versioning in dependencies. */
if (st->last_elem != PLIST_PKGDEP)
return (PARSE_FAIL);
/* add the the dependency list. */
@@ -294,6 +317,7 @@
pkg_file_set_md5(pf, NULL);
pkg_file_set_owner(pf, st->owner);
pkg_file_set_group(pf, st->group);
+ pkg_file_set_mode(pf, st->mode);
pkg_plist_pkg_file_list_append(pl, pf);
st->last_elem = PLIST_FILE;
}
@@ -301,6 +325,8 @@
return (s);
}
+/* pkg_file list manipulation and access. */
+
char *
pkg_plist_name(struct pkg_plist *pl)
{
@@ -337,7 +363,32 @@
return (pl->mtree_file);
}
-/* pkg_file list manipulation and access. */
+int
+pkg_plist_extract_in_place(struct pkg_plist *pl)
+{
+ if (pl == NULL)
+ arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+
+ return (pl->extract_in_place);
+}
+
+int
+pkg_plist_preserve(struct pkg_plist *pl)
+{
+ if (pl == NULL)
+ arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+
+ return (pl->preserve);
+}
+
+int
+pkg_plist_complete(struct pkg_plist *pl)
+{
+ if (pl == NULL)
+ arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
+
+ return (pl->complete);
+}
/* I should really just write a set of generic routine to handle this
* whole mess. */
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#12 (text+ko) ====
@@ -56,6 +56,13 @@
#define PLIST_COMMENT_DEPORIGIN "DEPORIGIN"
#define PLIST_COMMENT_MD5 "MD5"
+/* Options */
+
+#define PLIST_OPTION_EXTRACT_IN_PLACE "extract-in-place"
+#define PLIST_OPTION_PRESERVE "preserve"
+/* For dependency inclusive packages. */
+#define PLIST_OPTION_COMPLETE "complete"
+
struct parse_state;
struct pkg_plist {
@@ -66,7 +73,10 @@
char *origin;
char *display;
char *mtree_file;
-
+ short extract_in_place;
+ short preserve;
+ short complete;
+
char *text; /* The entire plist */
struct pkg_file *pf_curr;
@@ -103,6 +113,10 @@
char *pkg_plist_origin(struct pkg_plist *pl);
char *pkg_plist_mtree_file(struct pkg_plist *pl);
+int pkg_plist_extract_in_place(struct pkg_plist *pl);
+int pkg_plist_preserve(struct pkg_plist *pl);
+int pkg_plist_complete(struct pkg_plist *pl);
+
void pkg_plist_pkg_file_list_init(struct pkg_plist *pl);
struct pkg_file *pkg_plist_pkg_file_list_first(struct pkg_plist *pl);
struct pkg_file *pkg_plist_pkg_file_list_last(struct pkg_plist *pl);
@@ -124,4 +138,5 @@
void pkg_plist_pkg_dep_list_reset(struct pkg_plist *pl);
struct pkg_dep *pkg_plist_pkg_dep_list_next(struct pkg_plist *pl);
struct pkg_dep *pkg_plist_pkg_dep_list_first(struct pkg_plist *pl);
+
#endif
==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#16 (text+ko) ====
@@ -14,13 +14,11 @@
/* TODO: Write common error handling functions for pkg_tools. */
-#if 0
-static char opts[] = "a";
+static char opts[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX";
static struct option lopts[] = {
- {"all", no_argument, NULL, 'a'},
- {NULL, 0, NULL, 0}, // <-- something that pkg_add in 7.2 forgot...
+ { "all", no_argument, NULL, 'a'},
+ {NULL, 0, NULL, 0},
};
-#endif
/* Mock pkg_info for testing, */
@@ -73,15 +71,17 @@
void
parse_opts(int argc, char **argv)
{
- /* pointlessly set this. */
- opt_all = 1;
- char **a;
+ int a;
- if (argc == 1)
+ if (argc == 1) {
+ opt_all = 1;
+ opt_show_comment = 1;
return;
-
- a = argv; /* give argv something to do. */
- opt_show_all_info = 1;
+ }
+ while ((a = getopt_long(argc, argv, opts, lopts, NULL)) != -1) {
+ /* ... */
+ opt_show_all_info = 1;
+ }
}
void
@@ -130,6 +130,7 @@
const char *md5;
const char *owner;
const char *group;
+ const char *mode;
/* Just print the basic PKGNAME COMMENT scheme right now. Other
* information isn't collected by the library yet. */
@@ -155,6 +156,12 @@
(origin != NULL ? origin : BAD_OR_UNKNOWN_VALUE));
printf("\tmtree file: %s\n",
(mtree_file != NULL ? mtree_file : BAD_OR_UNKNOWN_VALUE));
+ printf("\textract in place: %s\n",
+ (pkg_extract_in_place(p) ? "YES" : "NO"));
+ printf("\tpreserve: %s\n",
+ (pkg_preserve(p) ? "YES" : "NO"));
+ printf("\tcomplete: %s\n",
+ (pkg_complete(p) ? "YES" : "NO"));
printf("\tfiles:\n");
pkg_ent_list_init(pkg_file, p);
while ((pf = pkg_ent_list_next(pkg_file, p)) != NULL) {
@@ -162,6 +169,7 @@
md5 = pkg_file_md5(pf);
owner = pkg_file_owner(pf);
group = pkg_file_group(pf);
+ mode = pkg_file_mode(pf);
printf("\t\t%s\n",
(path != NULL ? path : BAD_OR_UNKNOWN_VALUE));
printf("\t\t\tMD5: %s\n",
@@ -170,6 +178,8 @@
(owner != NULL ? owner : BAD_OR_UNKNOWN_VALUE));
printf("\t\t\tGROUP: %s\n",
(group != NULL ? group : BAD_OR_UNKNOWN_VALUE));
+ printf("\t\t\tMODE: %s\n",
+ (mode != NULL ? mode : BAD_OR_UNKNOWN_VALUE));
}
printf("\tdepends:\n");
More information about the p4-projects
mailing list