PERFORCE change 167231 for review
David Forsythe
dforsyth at FreeBSD.org
Wed Aug 12 08:44:21 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=167231
Change 167231 by dforsyth at squirrel on 2009/08/12 08:43:44
Fix required_by read.
Affected files ...
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#43 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#38 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#10 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#8 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.h#7 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_read.c#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_error.h#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest.c#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest_plist.c#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#17 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#29 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/pkg_info.h#9 edit
Differences ...
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#43 (text+ko) ====
@@ -49,6 +49,7 @@
p->comment = NULL;
p->description = NULL;
p->display = NULL;
+ p->reqd_by_count = 0;
p->required_by = NULL;
p->mtree_dirs = NULL;
p->pm = NULL;
@@ -115,16 +116,6 @@
return (pkg_manifest_name(p->pm));
}
-const char *
-pkg_cwd(struct pkg *p)
-{
- pkg_check_magic(p, __func__);
- if (pkg_parse_manifest(p) != PKG_OK)
- return (NULL);
-
- return ((const char *)pkg_manifest_cwd(p->pm));
-}
-
/* Retrieve pkg origin. @origin in plist. The directory of the port that
* this pkg was create from. */
@@ -236,13 +227,13 @@
return (p->mtree_dirs);
}
-const char *
+const char *const *
pkg_required_by(struct pkg *p)
{
if (p->in_db != NULL)
pkg_read_pkg_element_from_db(p, PKG_ELEM_REQUIRED_BY);
- return ((const char *)p->required_by);
+ return ((const char *const *)p->required_by);
}
const char *
@@ -340,7 +331,7 @@
if (p->pm == NULL)
pkg_parse_manifest(p);
- return (pkg_manifest_pkg_file_list(p->pm));
+ return (pkg_manifest_file_list(p->pm));
}
/* Retrieve a list of dependencies for this package (by name). Return a
@@ -353,7 +344,7 @@
if (p->pm == NULL && p->in_db != NULL)
pkg_parse_manifest(p);
- return (pkg_manifest_pkg_depend_list(p->pm));
+ return (pkg_manifest_depend_list(p->pm));
}
/* Retrieve a list of conflicts for this package (by name). Return a list
@@ -366,7 +357,7 @@
if (p->pm == NULL && p->in_db != NULL)
pkg_parse_manifest(p);
- return (pkg_manifest_pkg_conflict_list(p->pm));
+ return (pkg_manifest_conflict_list(p->pm));
}
const char *const *
@@ -376,7 +367,7 @@
if (p->pm == NULL && p->in_db != NULL)
pkg_parse_manifest(p);
- return (pkg_manifest_install_pkg_command_list(p->pm));
+ return (pkg_manifest_exec_cmd_list(p->pm));
}
const char *const *
@@ -386,14 +377,14 @@
if (p->pm == NULL && p->in_db != NULL)
pkg_parse_manifest(p);
- return (pkg_manifest_deinstall_pkg_command_list(p->pm));
+ return (pkg_manifest_unexec_cmd_list(p->pm));
}
/* Add a file to a package. This is fairly useless at this point
* because... well, there the hell is the file coming from? */
int
-pkg_insert_pkg_file(struct pkg *p, const char *path, const char *cwd, const char *md5,
+pkg_add_pkg_file(struct pkg *p, const char *path, const char *cwd, const char *md5,
const char *mode, const char *owner, const char *group)
{
int status;
@@ -404,17 +395,37 @@
status = PKG_OK;
pkg_parse_manifest(p);
- status |= pkg_manifest_insert_pkg_file(p->pm, path, md5, cwd, mode, owner, group);
+ status |= pkg_manifest_add_file(p->pm, path, md5, cwd, mode, owner, group);
return (status);
}
+int
+pkg_remove_pkg_file(struct pkg *p, const char *path)
+{
+ struct pkg_file *pf;
+ pkg_check_magic(p, __func__);
+ if ((pf = pkg_manifest_select_file(p->pm, path)) == NULL)
+ return (-1);
+ return (pkg_file_ignored(pf));
+}
+
+int
+pkg_pkg_file_ignored(struct pkg *p, const char *path)
+{
+ struct pkg_file *pf;
+ pkg_check_magic(p, __func__);
+ if ((pf = pkg_manifest_select_file(p->pm, path)) == NULL)
+ return (NULL);
+ return ((const char *)pkg_file_ignored(pf));
+}
+
const char *
pkg_pkg_file_cwd(struct pkg *p, const char *path)
{
struct pkg_file *pf;
pkg_check_magic(p, __func__);
- if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
+ if ((pf = pkg_manifest_select_file(p->pm, path)) == NULL)
return (NULL);
return ((const char *)pkg_file_cwd(pf));
}
@@ -424,7 +435,7 @@
{
struct pkg_file *pf;
pkg_check_magic(p, __func__);
- if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
+ if ((pf = pkg_manifest_select_file(p->pm, path)) == NULL)
return (NULL);
return ((const char *)pkg_file_group(pf));
}
@@ -434,7 +445,7 @@
{
struct pkg_file *pf;
pkg_check_magic(p, __func__);
- if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
+ if ((pf = pkg_manifest_select_file(p->pm, path)) == NULL)
return (NULL);
return ((const char *)pkg_file_md5(pf));
}
@@ -444,7 +455,7 @@
{
struct pkg_file *pf;
pkg_check_magic(p, __func__);
- if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
+ if ((pf = pkg_manifest_select_file(p->pm, path)) == NULL)
return (NULL);
return ((const char *)pkg_file_mode(pf));
}
@@ -454,17 +465,32 @@
{
struct pkg_file *pf;
pkg_check_magic(p, __func__);
- if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
+ if ((pf = pkg_manifest_select_file(p->pm, path)) == NULL)
return (NULL);
return ((const char *)pkg_file_owner(pf));
}
+int
+pkg_add_pkg_depend(struct pkg *p, const char *name, const char *origin,
+ const char *version)
+{
+ pkg_check_magic(p, __func__);
+ pkg_parse_manifest(p);
+ return (pkg_manifest_add_depend(name, origin, version));
+}
+
+int
+pkg_remove_pkg_depend(struct pkg *p, const char *name)
+{
+ return (0);
+}
+
const char *
pkg_pkg_depend_origin(struct pkg *p, const char *name)
{
struct pkg_depend *pd;
pkg_check_magic(p, __func__);
- if ((pd = pkg_manifest_select_pkg_depend(p->pm, name)) == NULL)
+ if ((pd = pkg_manifest_select_depend(p->pm, name)) == NULL)
return (NULL);
return ((const char *)pkg_depend_origin(pd));
}
@@ -589,7 +615,7 @@
}
int
-__pkg_set_required_by_ptr(struct pkg *p, char *required_by_ptr)
+__pkg_set_required_by_ptr(struct pkg *p, char **required_by_ptr)
{
pkg_check_magic(p, __func__);
p->required_by = required_by_ptr;
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#38 (text+ko) ====
@@ -29,12 +29,10 @@
const char *pkg_ident(struct pkg *p);
const char *pkg_name(struct pkg *p);
-const char *pkg_cwd(struct pkg *p);
const char *pkg_origin(struct pkg *p);
int pkg_set_ident(struct pkg *p, const char *ident);
int pkg_set_name(struct pkg *p, const char *name);
-int pkg_set_cwd(struct pkg *p, const char *cwd);
int pkg_set_origin(struct pkg *p, const char *origin);
int pkg_set_comment(struct pkg *p, const char *comment);
@@ -61,18 +59,20 @@
const char *const *pkg_execs(struct pkg *p);
const char *const *pkg_unexecs(struct pkg *p);
-int pkg_insert_pkg_file(struct pkg *p, const char *path, const char *cwd,
+int pkg_add_pkg_file(struct pkg *p, const char *path, const char *cwd,
const char *group, const char *md5, const char *mode,
const char *owner);
-int pkg_delete_pkg_file(struct pkg *p, const char *path);
+int pkg_remove_pkg_file(struct pkg *p, const char *path);
+int pkg_pkg_file_ignored(struct pkg *p, const char *path);
const char *pkg_pkg_file_cwd(struct pkg *p, const char *path);
const char *pkg_pkg_file_group(struct pkg *p, const char *path);
const char *pkg_pkg_file_md5(struct pkg *p, const char *path);
const char *pkg_pkg_file_mode(struct pkg *p, const char *path);
const char *pkg_pkg_file_owner(struct pkg *p, const char *path);
-int pkg_add_depend(struct pkg *p, const char *name, const char *origin, int version);
-int pkg_remove_depend(struct pkg *p, const char *name);
+int pkg_add_pkg_depend(struct pkg *p, const char *name, const char *origin,
+ const char *version);
+int pkg_remove_pkg_depend(struct pkg *p, const char *name);
const char *pkg_pkg_depend_origin(struct pkg *p, const char *name);
int pkg_pkg_depend_version(struct pkg *p, const char *name);
@@ -87,7 +87,7 @@
int pkg_preserve(struct pkg *p);
int pkg_complete(struct pkg *p);
-const char *pkg_required_by(struct pkg *p);
+const char *const *pkg_required_by(struct pkg *p);
/* pkg_db */
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#10 (text+ko) ====
@@ -79,7 +79,7 @@
{
pkg_db_check_magic(db, __func__);
- pkg_db_clear_pkg_list(db); /* Should set sub_count to 0. */
+ pkg_db_clear_pkg_entries(db); /* Should set sub_count to 0. */
free(db->db_root);
db->open = 0;
@@ -170,14 +170,6 @@
return;
}
-void
-pkg_db_clear_pkg_list(struct pkg_db *db)
-{
- if (db)
- return;
- return;
-}
-
int
pkg_db_pkg_count(struct pkg_db *db)
{
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#8 (text+ko) ====
@@ -78,46 +78,16 @@
int
pkg_db_hierdb_file_exists(struct pkg_db *db, struct pkg *p, const char *filename)
{
- return (1);
-}
-
-#if 0
-int
-pkg_db_hierdb_read_pkg_from_db(struct pkg_db *db, struct pkg *p)
-{
- char *ident;
+ int status;
+ struct stat sb;
+ char *dir;
char *path;
- int status;
- status = PKG_OK;
- ident = pkg_ident(p);
- if (ident == NULL)
- return (PKG_NOT_OK);
-
- path = path_build(ident, COMMENT_FILE);
- status |= pkg_set_comment(p,pkg_db_hierdb_read_file_to_text(db, path));
+ dir = path_build(pkg_db_db_root(db), pkg_ident(p));
+ path = path_build(dir, filename);
+ free(dir);
+ status = access(path, R_OK);
free(path);
-
- path = path_build(ident, DESC_FILE);
- status |= pkg_set_description(p, pkg_db_hierdb_read_file_to_text(db, path));
- free(path);
-
- path = path_build(ident, CONTENTS_FILE);
- status |= pkg_set_contents(p, pkg_db_hierdb_read_file_to_text(db, path));
- free(path);
-
- path = path_build(ident, DISPLAY_FILE);
- status |= pkg_set_display(p, pkg_db_hierdb_read_file_to_text(db, path));
- free(path);
-
- path = path_build(ident, MTREE_DIRS_FILE);
- status |= pkg_set_mtree_dirs(p, pkg_db_hierdb_read_file_to_text(db, path));
- free(path);
-
- path = path_build(ident, REQUIRED_BY_FILE);
- status |= pkg_set_required_by(p, pkg_db_hierdb_read_file_to_text(db, path));
- free(path);
+ return (!status);
+}
- return (status);
-}
-#endif
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.h#7 (text+ko) ====
@@ -19,6 +19,4 @@
int pkg_db_hierdb_file_exists(struct pkg_db *db, struct pkg *p, const char *filename);
-// int pkg_db_hierdb_read_pkg_element(struct pkg_db *db, struct pkg *p, int element);
-
#endif
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_read.c#4 (text+ko) ====
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <limits.h>
#include "pkg_util.h"
#include "pkg_error.h"
@@ -82,7 +83,7 @@
dir = path_build(db->db_root, p->ident);
path = path_build(dir, filename);
-
+ free(dir);
file = fopen(path, "r");
return (file);
@@ -139,6 +140,8 @@
/* These will not be staying this way. For now, assume that all files are where we
* want them to be, and assume a PLIST manifest. */
+/* XXX: I'd like to move a few of these elements into the manifest later on. */
+
static int
pkg_db_hierdb_read_comment_to_pkg(struct pkg_db *db, struct pkg *p)
{
@@ -214,17 +217,32 @@
static int
pkg_db_hierdb_read_required_by_to_pkg(struct pkg_db *db, struct pkg *p)
{
- char *text;
+ int count;
+ char line[LINE_MAX];
+ char **reqdby;
+ char **list;
+ FILE *reqdby_stream;
if (!pkg_db_hierdb_file_exists(db, p, REQUIRED_BY_FILE))
- return (PKG_NOT_OK);
+ return (PKG_OK); /* REQUIRED_BY doesn't have to exist. */
- text = pkg_db_hierdb_read_file_to_text(db, p, REQUIRED_BY_FILE);
- if (text == NULL)
- return (PKG_MEMORY_ERR | PKG_NOT_OK);
+ reqdby_stream = pkg_db_hierdb_open_file_stream_read(db, p, REQUIRED_BY_FILE);
+ for (count = 0, reqdby = NULL; fgets(line, FILENAME_MAX, reqdby_stream) != NULL; count++) {
+ if (count % 10 == 0) {
+ list = reqdby;
+ reqdby = realloc(list, sizeof(*list) * (count + 11));
+ if (reqdby == NULL) {
+ reqdby = list;
+ return (PKG_MEMORY_ERR | PKG_NOT_OK);
+ }
+ }
+ pkg_util_trim_newline(line);
+ reqdby[count] = strdup(line);
+ }
+ reqdby[count] = NULL;
- pkg_util_trim_newline(text);
- __pkg_set_required_by_ptr(p, text);
+ fclose(reqdby_stream);
+ __pkg_set_required_by_ptr(p, reqdby);
return (PKG_OK);
}
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_error.h#5 (text+ko) ====
@@ -5,6 +5,17 @@
#define PKG_NOT_OK 0x00000001
#define PKG_MEMORY_ERR 0x00000002
+#define pkg_error_null_argument(what, where, actual) \
+ if (actual == NULL) { \
+ pkg_error_msg("NULL "); \
+ pkg_error_msg(what); \
+ pkg_error_msg(" passed to "); \
+ pkg_error_msg(where); \
+ pkg_error_msg("\n"); \
+ rage_quit(); \
+ }
+
+
void pkg_error_msg(const char *errmsg);
void bad_magic_quit(const char *type, const char *where);
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest.c#4 (text+ko) ====
@@ -9,11 +9,11 @@
#include "pkg_file.h"
#include "pkg_manifest.h"
-static void pkg_manifest_clear_pkg_conflict_entries(struct pkg_manifest *pm);
-static void pkg_manifest_clear_pkg_depend_entries(struct pkg_manifest *pm);
-static void pkg_manifest_clear_pkg_file_entries(struct pkg_manifest *pm);
-static void pkg_manifest_clear_install_pkg_commands(struct pkg_manifest *pm);
-static void pkg_manifest_clear_deinstall_pkg_commands(struct pkg_manifest *pm);
+static void pkg_manifest_clear_conflict_entries(struct pkg_manifest *pm);
+static void pkg_manifest_clear_depend_entries(struct pkg_manifest *pm);
+static void pkg_manifest_clear_file_entries(struct pkg_manifest *pm);
+static void pkg_manifest_clear_exec_list(struct pkg_manifest *pm);
+static void pkg_manifest_clear_unexec_list(struct pkg_manifest *pm);
static void pkg_manifest_init(struct pkg_manifest *pm);
void
@@ -49,14 +49,23 @@
pm->mtree_file = NULL;
pm->display_file = NULL;
- pm->pkg_conflict_list = NULL;
- pm->pkg_conflict_entries = NULL;
+ pm->conflict_list = NULL;
+ pm->conflict_entries = NULL;
- pm->pkg_depend_list = NULL;
- pm->pkg_depend_entries = NULL;
+ pm->depend_list = NULL;
+ pm->depend_entries = NULL;
+
+ pm->file_list = NULL;
+ pm->file_entries = NULL;
+
+ pm->exec_count = 0;
+ pm->exec_list = NULL;
+
+ pm->unexec_count = 0;
+ pm->unexec_list = NULL;
- pm->pkg_file_list = NULL;
- pm->pkg_file_entries = NULL;
+ pm->dirrm_count = 0;
+ pm->dirrm_list = NULL;
pm->complete = 0;
pm->dirty = 0;
@@ -76,11 +85,11 @@
free(pm->srcdir);
free(pm->mtree_file);
free(pm->display_file);
- pkg_manifest_clear_pkg_conflict_entries(pm);
- pkg_manifest_clear_pkg_depend_entries(pm);
- pkg_manifest_clear_pkg_file_entries(pm);
- pkg_manifest_clear_install_pkg_commands(pm);
- pkg_manifest_clear_deinstall_pkg_commands(pm);
+ pkg_manifest_clear_conflict_entries(pm);
+ pkg_manifest_clear_depend_entries(pm);
+ pkg_manifest_clear_file_entries(pm);
+ pkg_manifest_clear_exec_list(pm);
+ pkg_manifest_clear_unexec_list(pm);
pkg_manifest_init(pm);
}
@@ -95,12 +104,6 @@
}
const char *
-pkg_manifest_cwd(struct pkg_manifest *pm)
-{
- return ((const char *)pm->cwd);
-}
-
-const char *
pkg_manifest_revision(struct pkg_manifest *pm)
{
return ((const char *)pm->rev);
@@ -149,13 +152,6 @@
}
int
-pkg_manifest_set_cwd(struct pkg_manifest *pm, const char *cwd)
-{
- pkg_manifest_check_magic(pm, __func__);
- return (pkg_util_strdup(cwd, &pm->cwd));
-}
-
-int
pkg_manifest_set_revision(struct pkg_manifest *pm, const char *revision)
{
pkg_manifest_check_magic(pm, __func__);
@@ -191,37 +187,43 @@
}
const char *const *
-pkg_manifest_pkg_conflict_list(struct pkg_manifest *pm)
+pkg_manifest_conflict_list(struct pkg_manifest *pm)
+{
+ return ((const char *const *)pm->conflict_list);
+}
+
+const char *const *
+pkg_manifest_depend_list(struct pkg_manifest *pm)
{
- return ((const char *const *)pm->pkg_conflict_list);
+ return ((const char *const *)pm->depend_list);
}
const char *const *
-pkg_manifest_pkg_depend_list(struct pkg_manifest *pm)
+pkg_manifest_file_list(struct pkg_manifest *pm)
{
- return ((const char *const *)pm->pkg_depend_list);
+ return ((const char *const *)pm->file_list);
}
const char *const *
-pkg_manifest_pkg_file_list(struct pkg_manifest *pm)
+pkg_manifest_exec_cmd_list(struct pkg_manifest *pm)
{
- return ((const char *const *)pm->pkg_file_list);
+ return ((const char *const *)pm->exec_list);
}
const char *const *
-pkg_manifest_install_pkg_command_list(struct pkg_manifest *pm)
+pkg_manifest_unexec_cmd_list(struct pkg_manifest *pm)
{
- return ((const char *const *)pm->pkg_install_list);
+ return ((const char *const *)pm->unexec_list);
}
const char *const *
-pkg_manifest_deinstall_pkg_command_list(struct pkg_manifest *pm)
+pkg_manifest_dirrm_cmd_list(struct pkg_manifest *pm)
{
- return ((const char *const *)pm->pkg_deinstall_list);
+ return ((const char *const *)pm->dirrm_list);
}
int
-pkg_manifest_insert_pkg_conflict(struct pkg_manifest *pm, const char *name,
+pkg_manifest_add_conflict(struct pkg_manifest *pm, const char *name,
const char *version)
{
int status;
@@ -234,33 +236,33 @@
rage_quit();
}
- if (pm->pkg_conflict_count % 5 == 0) {
- list = pm->pkg_conflict_list;
- conflicts = pm->pkg_conflict_entries;
- pm->pkg_conflict_list = realloc(list, sizeof(*list) * (pm->pkg_conflict_count + 6));
- pm->pkg_conflict_entries = realloc(conflicts, sizeof(*conflicts) * (pm->pkg_conflict_count + 6));
- if (pm->pkg_conflict_list == NULL || pm->pkg_conflict_entries == NULL) {
- pm->pkg_conflict_list = list;
- pm->pkg_conflict_entries = conflicts;
+ if (pm->conflict_count % 5 == 0) {
+ list = pm->conflict_list;
+ conflicts = pm->conflict_entries;
+ pm->conflict_list = realloc(list, sizeof(*list) * (pm->conflict_count + 6));
+ pm->conflict_entries = realloc(conflicts, sizeof(*conflicts) * (pm->conflict_count + 6));
+ if (pm->conflict_list == NULL || pm->conflict_entries == NULL) {
+ pm->conflict_list = list;
+ pm->conflict_entries = conflicts;
return (PKG_MEMORY_ERR | PKG_NOT_OK);
}
}
status = PKG_OK;
- pc = &pm->pkg_conflict_entries[pm->pkg_conflict_count];
+ pc = &pm->conflict_entries[pm->conflict_count];
pkg_conflict_init(pc);
status |= pkg_conflict_set_name(pc, name);
status |= pkg_conflict_set_version(pc, version);
- pm->pkg_conflict_list[pm->pkg_conflict_count++] = pkg_conflict_name(pc);
- pm->pkg_conflict_list[pm->pkg_conflict_count] = NULL;
+ pm->conflict_list[pm->conflict_count++] = pkg_conflict_name(pc);
+ pm->conflict_list[pm->conflict_count] = NULL;
return (status);
}
int
-pkg_manifest_insert_pkg_depend(struct pkg_manifest *pm, const char *name,
+pkg_manifest_add_depend(struct pkg_manifest *pm, const char *name,
const char *origin)
{
int status;
@@ -273,28 +275,27 @@
rage_quit();
}
- if (pm->pkg_depend_count % 5 == 0) {
- list = pm->pkg_depend_list;
- depends = pm->pkg_depend_entries;
- pm->pkg_depend_list = realloc(list, sizeof(*list) * (pm->pkg_depend_count + 6));
- pm->pkg_depend_entries = realloc(depends, sizeof(*depends) * (pm->pkg_depend_count + 6));
- if (pm->pkg_depend_list == NULL || pm->pkg_depend_entries == NULL) {
- pm->pkg_depend_list = list;
- pm->pkg_depend_entries = depends;
+ if (pm->depend_count % 10 == 0) {
+ list = pm->depend_list;
+ depends = pm->depend_entries;
+ pm->depend_list = realloc(list, sizeof(*list) * (pm->depend_count + 11));
+ pm->depend_entries = realloc(depends, sizeof(*depends) * (pm->depend_count + 11));
+ if (pm->depend_list == NULL || pm->depend_entries == NULL) {
+ pm->depend_list = list;
+ pm->depend_entries = depends;
return (PKG_MEMORY_ERR | PKG_NOT_OK);
}
}
status = PKG_OK;
-
- pd = &pm->pkg_depend_entries[pm->pkg_depend_count];
+ pd = &pm->depend_entries[pm->depend_count];
pkg_depend_init(pd);
status |= pkg_depend_set_name(pd, name);
status |= pkg_depend_set_origin(pd, origin);
- pm->pkg_depend_list[pm->pkg_depend_count++] = pkg_depend_name(pd);
- pm->pkg_depend_list[pm->pkg_depend_count] = NULL;
+ pm->depend_list[pm->depend_count++] = pkg_depend_name(pd);
+ pm->depend_list[pm->depend_count] = NULL;
return (status);
}
@@ -302,7 +303,7 @@
/* Add a file to a manifest. */
int
-pkg_manifest_insert_pkg_file(struct pkg_manifest *pm, const char *path, const char *md5,
+pkg_manifest_add_file(struct pkg_manifest *pm, const char *path, const char *md5,
const char *cwd, const char *mode, const char *owner, const char *group)
{
int status;
@@ -316,21 +317,21 @@
rage_quit();
}
- if (pm->pkg_file_count % 10 == 0) {
- list = pm->pkg_file_list;
- files = pm->pkg_file_entries;
- pm->pkg_file_list = realloc(list, sizeof(*list) * (pm->pkg_file_count + 11));
- pm->pkg_file_entries = realloc(files, sizeof(*files) * (pm->pkg_file_count + 11));
- if (pm->pkg_file_list == NULL || pm->pkg_file_entries == NULL) {
- pm->pkg_file_list = list;
- pm->pkg_file_entries = files;
+ if (pm->file_count % 10 == 0) {
+ list = pm->file_list;
+ files = pm->file_entries;
+ pm->file_list = realloc(list, sizeof(*list) * (pm->file_count + 11));
+ pm->file_entries = realloc(files, sizeof(*files) * (pm->file_count + 11));
+ if (pm->file_list == NULL || pm->file_entries == NULL) {
+ pm->file_list = list;
+ pm->file_entries = files;
return (PKG_MEMORY_ERR | PKG_NOT_OK);
}
}
status = PKG_OK;
- pf = &pm->pkg_file_entries[pm->pkg_file_count];
+ pf = &pm->file_entries[pm->file_count];
pkg_file_init(pf);
status |= pkg_file_set_path(pf, path);
status |= pkg_file_set_md5(pf, md5);
@@ -339,205 +340,206 @@
status |= pkg_file_set_owner(pf, owner);
status |= pkg_file_set_group(pf, group);
- pm->pkg_file_list[pm->pkg_file_count++] = pkg_file_path(pf);
- pm->pkg_file_list[pm->pkg_file_count] = NULL;
-
+ pm->file_list[pm->file_count++] = pkg_file_path(pf);
+ pm->file_list[pm->file_count] = NULL;
+
return (status);
}
-/* XXX: This method of storing commands is pretty much unacceptable. Take a look at
- * previous attempts at a package library or try to devise a new way of storing this
- * information. */
+
+/* Add command strings to a package. Do not sort. */
+
+/* Add an exec command to a manifest, which will be run at install time. Returns the
+ * status of the operation. */
int
-pkg_manifest_insert_install_pkg_command(struct pkg_manifest *pm, int type,
- const char *argument) {
+pkg_manifest_add_exec_cmd(struct pkg_manifest *pm, const char *cmd)
+{
int status;
char **list;
- struct pkg_command *commands;
- struct pkg_command *pe;
- if (argument == NULL) {
- pkg_error_msg("");
- rage_quit();
- }
+ pkg_error_null_argument("command", cmd, __func__);
- if (pm->pkg_install_count % 10 == 0) {
- list = pm->pkg_install_list;
- commands = pm->pkg_install_entries;
- pm->pkg_install_list = realloc(list, sizeof(*list) * (pm->pkg_install_count + 11));
- pm->pkg_install_entries = realloc(commands, sizeof(*commands) * (pm->pkg_install_count + 11));
- if (pm->pkg_install_list == NULL || pm->pkg_install_entries == NULL) {
- pm->pkg_install_list = list;
- pm->pkg_install_entries = commands;
+ if (pm->exec_count % 10 == 0) {
+ list = pm->exec_list;
+ pm->exec_list = realloc(list, sizeof(*list) * (pm->exec_count + 11));
+ if (pm->exec_list == NULL) {
+ pm->exec_list = list;
return (PKG_MEMORY_ERR | PKG_NOT_OK);
}
}
+
+ status = pkg_util_strdup(cmd, &pm->exec_list[pm->exec_count++]);
+ pm->exec_list[pm->exec_count] = NULL;
+
+ return (status);
+}
+
+/* Add an unexec command to a manifest, which will be executed at deinstall time.
+ * Returns the status of the operation. */
+
+int
+pkg_manifest_add_unexec_cmd(struct pkg_manifest *pm, const char *cmd)
+{
+ int status;
+ char **list;
- status = PKG_OK;
+ pkg_error_null_argument("command", cmd, __func__);
- pe = &pm->pkg_install_entries[pm->pkg_install_count];
- pkg_command_init(pe);
- status |= pkg_command_set_type(pe, type);
- status |= pkg_command_set_argument(pe, argument);
+ if (pm->unexec_count % 10 == 0) {
+ list = pm->unexec_list;
+ pm->unexec_list = realloc(list, sizeof(*list) * (pm->unexec_count + 11));
+ if (pm->unexec_list == NULL) {
+ pm->unexec_list = list;
+ return (PKG_MEMORY_ERR | PKG_NOT_OK);
+ }
+ }
- pm->pkg_install_list[pm->pkg_install_count++] = pkg_command_argument(pe);
- pm->pkg_install_list[pm->pkg_install_count] = NULL;
+ status = pkg_util_strdup(cmd, &pm->unexec_list[pm->unexec_count++]);
+ pm->unexec_list[pm->unexec_count] = NULL;
return (status);
}
+/* Add a dirrm command to a manifest that will remove the directory dir at deinstall
+ * time. Returns the status of the operation. */
+
int
-pkg_manifest_insert_deinstall_pkg_command(struct pkg_manifest *pm, int type,
- const char *argument) {
+pkg_manifest_add_dirrm_cmd(struct pkg_manifest *pm, const char *dir)
+{
int status;
char **list;
- struct pkg_command *commands;
- struct pkg_command *pe;
- if (argument == NULL) {
- pkg_error_msg("");
- rage_quit();
- }
+ pkg_error_null_argument("directory", dir, __func__);
- if (pm->pkg_deinstall_count % 10 == 0) {
- list = pm->pkg_deinstall_list;
- commands = pm->pkg_deinstall_entries;
- pm->pkg_deinstall_list = realloc(list, sizeof(*list) * (pm->pkg_deinstall_count + 11));
- pm->pkg_deinstall_entries = realloc(commands, sizeof(*commands) * (pm->pkg_deinstall_count + 11));
- if (pm->pkg_deinstall_list == NULL || pm->pkg_deinstall_entries == NULL) {
- pm->pkg_deinstall_list = list;
- pm->pkg_deinstall_entries = commands;
+ if (pm->dirrm_count % 10 == 0) {
+ list = pm->dirrm_list;
+ pm->dirrm_list = realloc(list, sizeof(*list) * (pm->dirrm_count + 11));
+ if (pm->dirrm_list == NULL) {
+ pm->dirrm_list = list;
return (PKG_MEMORY_ERR | PKG_NOT_OK);
}
}
- status = PKG_OK;
-
- pe = &pm->pkg_deinstall_entries[pm->pkg_deinstall_count];
- pkg_command_init(pe);
- status |= pkg_command_set_type(pe, type);
- status |= pkg_command_set_argument(pe, argument);
-
- pm->pkg_deinstall_list[pm->pkg_deinstall_count++] = pkg_command_argument(pe);
- pm->pkg_deinstall_list[pm->pkg_deinstall_count] = NULL;
+ status = pkg_util_strdup(dir, &pm->dirrm_list[pm->dirrm_count++]);
+ pm->dirrm_list[pm->dirrm_count] = NULL;
return (status);
}
void
-pkg_manifest_remove_pkg_conflict(struct pkg_manifest *pm, const char *name)
+pkg_manifest_remove_conflict(struct pkg_manifest *pm, const char *name)
{
pkg_manifest_check_magic(pm, __func__);
return;
}
void
-pkg_manifest_remove_pkg_depend(struct pkg_manifest *pm, const char *name)
+pkg_manifest_remove_depend(struct pkg_manifest *pm, const char *name)
{
pkg_manifest_check_magic(pm, __func__);
return;
}
void
-pkg_manifest_remove_pkg_file(struct pkg_manifest *pm, const char *path)
+pkg_manifest_remove_file(struct pkg_manifest *pm, const char *path)
{
pkg_manifest_check_magic(pm, __func__);
return;
}
void
-pkg_manifest_remove_install_pkg_command(struct pkg_manifest *pm, const char *argument)
+pkg_manifest_remove_exec_cmd(struct pkg_manifest *pm, int cmdidx)
{
pkg_manifest_check_magic(pm, __func__);
return;
}
void
-pkg_manifest_remove_deinstall_pkg_command(struct pkg_manifest *pm, const char *argument)
+pkg_manifest_remove_unexec_cmd(struct pkg_manifest *pm, int cmdidx)
{
pkg_manifest_check_magic(pm, __func__);
return;
}
static void
-pkg_manifest_clear_pkg_conflict_entries(struct pkg_manifest *pm)
+pkg_manifest_clear_conflict_entries(struct pkg_manifest *pm)
{
pkg_manifest_check_magic(pm, __func__);
- while (pm->pkg_conflict_count > 0)
- pkg_manifest_remove_pkg_conflict(pm, pm->pkg_conflict_entries[0].name);
+ while (pm->conflict_count > 0)
+ pkg_manifest_remove_conflict(pm, pm->conflict_entries[0].name);
}
static void
-pkg_manifest_clear_pkg_depend_entries(struct pkg_manifest *pm)
+pkg_manifest_clear_depend_entries(struct pkg_manifest *pm)
{
pkg_manifest_check_magic(pm, __func__);
- while (pm->pkg_depend_count > 0)
- pkg_manifest_remove_pkg_depend(pm, pm->pkg_depend_entries[0].name);
+ while (pm->depend_count > 0)
+ pkg_manifest_remove_depend(pm, pm->depend_entries[0].name);
}
static void
-pkg_manifest_clear_pkg_file_entries(struct pkg_manifest *pm)
+pkg_manifest_clear_file_entries(struct pkg_manifest *pm)
{
pkg_manifest_check_magic(pm, __func__);
- while (pm->pkg_file_count > 0)
- pkg_manifest_remove_pkg_file(pm, pm->pkg_file_entries[0].path);
+ while (pm->file_count > 0)
+ pkg_manifest_remove_file(pm, pm->file_entries[0].path);
}
static void
-pkg_manifest_clear_install_pkg_commands(struct pkg_manifest *pm)
+pkg_manifest_clear_exec_list(struct pkg_manifest *pm)
{
pkg_manifest_check_magic(pm, __func__);
- while(pm->pkg_install_count > 0)
- pkg_manifest_remove_install_pkg_command(pm, pm->pkg_install_entries[0].argument);
+ while (pm->exec_count > 0)
+ pkg_manifest_remove_exec_cmd(pm, pm->exec_count);
}
static void
-pkg_manifest_clear_deinstall_pkg_commands(struct pkg_manifest *pm)
+pkg_manifest_clear_unexec_list(struct pkg_manifest *pm)
{
pkg_manifest_check_magic(pm, __func__);
- while(pm->pkg_deinstall_count > 0)
- pkg_manifest_remove_deinstall_pkg_command(pm, pm->pkg_deinstall_entries[0].argument);
+ while (pm->unexec_count > 0)
+ pkg_manifest_remove_unexec_cmd(pm, pm->unexec_count);
}
struct pkg_conflict *
-pkg_manifest_select_pkg_conflict(struct pkg_manifest *pm, const char *name)
+pkg_manifest_select_conflict(struct pkg_manifest *pm, const char *name)
{
int i;
pkg_manifest_check_magic(pm, __func__);
- for (i = 0; i < pm->pkg_conflict_count; ++i)
- if (strcmp(pm->pkg_conflict_entries[i].name, name) == 0)
- return (&pm->pkg_conflict_entries[i]);
+ for (i = 0; i < pm->conflict_count; ++i)
+ if (strcmp(pm->conflict_entries[i].name, name) == 0)
+ return (&pm->conflict_entries[i]);
return (NULL);
}
struct pkg_depend *
-pkg_manifest_select_pkg_depend(struct pkg_manifest *pm, const char *name)
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list