PERFORCE change 164478 for review
David Forsythe
dforsyth at FreeBSD.org
Tue Jun 16 03:13:28 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164478
Change 164478 by dforsyth at squirrel on 2009/06/16 03:12:57
Almost finished moving to new scheme. This code builds with a bunch
of warnings, but pkg_info spits out comments atleast. Still need to
go back and revise error codes.
Affected files ...
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#7 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#18 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#18 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb_pkgdb_sub.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb_pkgdb_sub.h#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#12 edit
Differences ...
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#7 (text+ko) ====
@@ -1,7 +1,8 @@
LIB= pkg
INCS= pkg.h
WARNS= 6
-SRCS= pkgdb.c pkg_plist.c pkg.c pkg_util.c pkg_file.c pkg_dep.c pkgdb_hierdb.c pkgdb_hierdb_pkgdb_sub.c
+SRCS= pkgdb.c pkgdb_hierdb.c pkgdb_hierdb_pkgdb_sub.c pkg.c pkg_util.c \
+ pkg_file.c pkg_dep.c pkg_plist.c
NO_MAN= yes
.include <bsd.lib.mk>
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#18 (text+ko) ====
@@ -48,14 +48,35 @@
* twice, but until I'm sure about what I'm going to do with all of the
* information, pkgs can have their own copies of the data. */
+/* Set the identity for this package (does not have to be the same as the
+ * name from plist, but it generally is. This is the name used for the
+ * directory in a hierdb. */
+
+int
+pkg_set_ident(struct pkg *p, const char *ident)
+{
+ if (p == NULL)
+ arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+ if (ident != NULL)
+ p->ident = strdup(ident);
+ else
+ p->ident = NULL;
+
+ return (OK);
+}
+
/* Set the short comment for this package */
int
pkg_set_comment(struct pkg *p, const char *comment)
{
if (p == NULL)
arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- p->comment = strdup(comment);
+
+ if (comment != NULL)
+ p->comment = strdup(comment);
+ else
+ p->comment = NULL;
return (OK);
}
@@ -67,9 +88,12 @@
{
if (p == NULL)
arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+ if (contents != NULL)
+ p->contents = strdup(contents);
+ else
+ p->contents = NULL;
- p->contents = strdup(contents);
-
return (OK);
}
@@ -79,7 +103,10 @@
if (p == NULL)
arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
- p->description = strdup(description);
+ if (description != NULL)
+ p->description = strdup(description);
+ else
+ p->description = NULL;
return (OK);
}
@@ -90,7 +117,10 @@
if (p == NULL)
arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
- p->display = strdup(display);
+ if (display != NULL)
+ p->display = strdup(display);
+ else
+ p->display = NULL;
return (OK);
}
@@ -101,7 +131,10 @@
if (p == NULL)
arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
- p->mtree_dirs = strdup(mtree_dirs);
+ if (mtree_dirs != NULL)
+ p->mtree_dirs = strdup(mtree_dirs);
+ else
+ p->mtree_dirs = NULL;
return (OK);
}
@@ -112,7 +145,10 @@
if (p == NULL)
arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
- p->required_by = strdup(required_by);
+ if (required_by != NULL)
+ p->required_by = strdup(required_by);
+ else
+ p->required_by = NULL;
return (OK);
}
@@ -221,7 +257,7 @@
p->display = NULL;
p->mtree_dirs = NULL;
p->required_by = NULL;
- pkg_plist(&p->plist);
+ pkg_plist_reset(&p->plist);
}
/* TODO: Make an note in the manual for libpkg that pkg_free should not be
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#18 (text+ko) ====
@@ -8,6 +8,8 @@
/* These error codes are no good. Switch to contextual errors/macros. */
+/* General Errors. */
+
#define OK 0x00000000
#define NOT_OK 0x00000001
#define MEMORY_ERR 0x00000002
@@ -15,6 +17,8 @@
#define RAGE_AT_CLIENT 0x00000008
#define RAGE_AT_LIBPKG 0x00000010
+/* PKGDB Errors. */
+
#define DB_BAD_ROOT 0x10000000
#define DB_NOT_OPEN 0x20000000
#define DB_OPEN 0x40000000
@@ -28,6 +32,8 @@
#define SUB_NO_FILE 0x00200000
#define SUB_EMPTY_FILE 0x00400000
+/* PKG Errors. */
+
#define NO_PKG 0x00800000
/* pkg_file */
@@ -124,8 +130,6 @@
int pkgdb_db_close(struct pkgdb *db);
-void pkgdb_db_delete(struct pkgdb *db);
-
int pkgdb_pkg_next(struct pkgdb *db, struct pkg *p);
int pkgdb_pkg_get(struct pkgdb *db, struct pkg *p, const char *ident);
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#6 (text+ko) ====
@@ -40,27 +40,25 @@
path_build(const char *prefix, const char *suffix)
{
size_t l;
- int slash;
char *new_path;
- slash = 0;
l = strlen(prefix);
- if (prefix[l - 1] != '/')
- slash = 1;
- l += strlen(suffix) + slash;
- new_path = malloc(l + 1);
- if (new_path == NULL)
- return (NULL);
- strcpy(new_path, prefix);
- if (slash)
- strcat(new_path, '/');
- strcat(new_path, suffix);
+ if (prefix[l - 1] == '/') {
+ new_path = malloc(l + strlen(suffix) + 1);
+ strcpy(new_path, prefix);
+ strcat(new_path, suffix);
+ } else {
+ new_path = malloc(l + strlen(suffix) + 2);
+ strcpy(new_path, prefix);
+ strcat(new_path, "/");
+ strcat(new_path, suffix);
+ }
return (new_path);
}
void
-argument_rage_quit(const char *function, const char *message, int ret)
+arg_rage_quit(const char *function, const char *message, int ret)
{
fprintf(stderr, "Bad argument in %s: %s\n", function, message);
exit(ret);
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb.c#6 (text+ko) ====
@@ -7,6 +7,7 @@
#include <dirent.h>
#include "pkg_util.h"
+#include "pkg_private.h"
#include "pkg.h"
#include "pkgdb.h"
#include "pkgdb_private.h"
@@ -33,11 +34,11 @@
s = lstat(db_root, &sb);
if (s < 0 || !S_ISDIR(sb.st_mode) || S_ISLNK(sb.st_mode))
- return (DB_INVALID_ROOT);
+ return (DB_BAD_ROOT);
db->db_root = strdup(db_root);
if (db->db_root == NULL)
- return (DB_MEMORY_ERR);
+ return (MEMORY_ERR);
db->dirty = 1;
db->open = 1;
@@ -45,7 +46,7 @@
db->sub_count = 0;
- return (DB_OK);
+ return (OK);
}
int
@@ -60,33 +61,34 @@
#if 0
if (!VALID_DB(db))
#endif
- if (db == NULL);
+ if (db == NULL)
arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
/* TODO: Add dirty check. */
c = scandir(db->db_root, &ents, subdir_sel, alphasort);
if (c < 1)
- return (DB_NO_READ | DB_MEMORY_ERR);
+ return (NOT_OK | MEMORY_ERR);
+ pkgdb_pkgdb_sub_list_init(db);
for (i = 0, cnt = 0; i < c; ++i) {
sub = pkgdb_sub_new();
status = pkgdb_hierdb_read_pkgdb_sub(db, sub, ents[i]->d_name);
- if (SUB_MEMORY_ERR & status) {
+ if (MEMORY_ERR & status) {
/* Ruh roh Shaggy! */
pkgdb_pkgdb_sub_list_free(db);
for (; i < c; ++i)
free(ents[i]);
free(ents);
- return (DB_MEMORY_ERR);
- } else if ((SUB_NO_CONTENTS & status) || (SUB_BAD_IDENT & status))
+ return (MEMORY_ERR);
+ } else if ((SUB_NO_CONTENTS & status) || (BAD_IDENT & status))
/*
* This is a directory that is of no use to us. I am
* enforcing strict rules on what is and isn't a package. If
* there is no plist, or the plist is empty, this is not a
* package, and we don't care about it.
*/
- pkg_delete(p);
+ pkgdb_sub_delete(sub);
else {
pkgdb_pkgdb_sub_list_append(db, sub);
cnt++;
@@ -99,7 +101,7 @@
db->sub_count = cnt;
db->dirty = 0;
- return (DB_OK);
+ return (OK);
}
/* This function will properly initialize a pkgdb_sub for a pkgdb to use.
@@ -118,28 +120,28 @@
arg_rage_quit(__func__, "Not a valid identification string.",
RAGE_AT_CLIENT);
#endif
- pkg_reset(sub);
- status = SUB_OK;
- status |= pkgdb_sub_set_ident(ident);
+ pkgdb_sub_reset(sub);
+ status = OK;
+ status |= pkgdb_sub_set_ident(sub, ident);
status |= pkgdb_sub_set_assign_db(db, sub);
- if ((SUB_MEMORY_ERR & status) || (SUB_BAD_IDENT & status))
+ if ((MEMORY_ERR & status) || (BAD_IDENT & status))
return (status);
/* Hope you have your reading glasses on... */
- status = SUB_OK;
- status |= pkgdb_sub_reat_file_to_text(db, sub, COMMENT_FILE) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_COMMENT : SUB_OK;
- status |= pkgdb_sub_read_file_to_text(db, sub, CONTENTS_FILE) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_CONTENTS : SUB_OK;
- status |= pkgdb_sub_read_file_to_text(db, sub, DESC_FILE) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_DESC : SUB_OK;
- status |= pkgdb_sub_read_file_to_text(db, sub, DISPLAY_FILE) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_DISPLAY : SUB_OK;
- status |= pkgdb_sub_read_file_to_text(db, sub, MTREE_DIRS_FILE) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_MTREE_DIRS : SUB_OK;
- status |= pkgdb_sub_read_file_to_text(db, sub, REQUIRED_BY_FILE:) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_REQUIRED_BY : SUB_OK;
+ status = OK;
+ status |= pkgdb_sub_read_file_to_text(sub, COMMENT_FILE) &
+ (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_COMMENT : OK;
+ status |= pkgdb_sub_read_file_to_text(sub, CONTENTS_FILE) &
+ (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_CONTENTS : OK;
+ status |= pkgdb_sub_read_file_to_text(sub, DESC_FILE) &
+ (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_DESC : OK;
+ status |= pkgdb_sub_read_file_to_text(sub, DISPLAY_FILE) &
+ (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_DISPLAY : OK;
+ status |= pkgdb_sub_read_file_to_text(sub, MTREE_DIRS_FILE) &
+ (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_MTREE_DIRS : OK;
+ status |= pkgdb_sub_read_file_to_text(sub, REQUIRED_BY_FILE) &
+ (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_REQUIRED_BY : OK;
return (status);
}
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb.h#4 (text+ko) ====
@@ -10,6 +10,8 @@
int pkgdb_hierdb_read_pkgdb_sub(struct pkgdb *db, struct pkgdb_sub *dbs,
const char *ident);
-int pkgdb_hierdb_db_close(struct pkgdb *db);
+/* int pkgdb_hierdb_db_close(struct pkgdb *db); */
+
+int pkgdb_hierdb_db_sync(struct pkgdb *db);
#endif
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb_pkgdb_sub.c#6 (text+ko) ====
@@ -1,7 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "pkg_util.h"
#include "pkgdb_hierdb_pkgdb_sub.h"
+#include "pkg_private.h"
#include "pkg.h"
#define BAD_ARG_RAGE arg_rage_quit(__func__, "Not a valid pkgdb_sub.", RAGE_AT_LIBPKG);
@@ -24,8 +32,8 @@
free(dbs->ident);
dbs->ident = strdup(ident);
if (dbs->ident == NULL)
- return (SUB_MEMORY_ERR);
- return (SUB_OK);
+ return (MEMORY_ERR);
+ return (OK);
}
int
@@ -38,30 +46,30 @@
#if 0
if (!VALID_DB(owner))
#endif
- if (db == NULL)
+ if (owner == NULL)
arg_rage_quit(__func__, "Owner must be a valid database.",
- RAGE_AT_LIB);
+ RAGE_AT_LIBPKG);
if (dbs == NULL)
arg_rage_quit(__func__, "dbs must be a valid sub structure.",
- RAGE_AT_LIB);
+ RAGE_AT_LIBPKG);
- dbs->owner_db = db;
+ dbs->owner_db = owner;
dbs->path = path_build(pkgdb_db_root(dbs->owner_db), dbs->ident);
- if (path == NULL)
- return (SUB_MEMORY_ERR);
+ if (dbs->path == NULL)
+ return (MEMORY_ERR);
- s = lstat(path, &sb);
+ s = lstat(dbs->path, &sb);
/* Also, we don't handle links (yet). */
- if (s < 0 || !S_ISDIR(sb.st_mode) || S_ISLINK(sb.st_mode)) {
+ if (s < 0 || !S_ISDIR(sb.st_mode) || S_ISLNK(sb.st_mode)) {
free(dbs->path);
- return (SUB_BAD_IDENT);
+ return (BAD_IDENT);
}
- return (SUB_OK);
+ return (OK);
}
int
-pkgdb_sub_read_file_to_text(struct pkgdb *dbs, const char *filename)
+pkgdb_sub_read_file_to_text(struct pkgdb_sub *sub, const char *filename)
{
int s;
struct stat sb;
@@ -69,7 +77,7 @@
char *text;
char *path_to_file;
- path_to_file = path_build(dbs->path, filename);
+ path_to_file = path_build(sub->path, filename);
s = lstat(path_to_file, &sb);
if (s < 0 || !S_ISREG(sb.st_mode)) {
free(path_to_file);
@@ -80,7 +88,7 @@
return (SUB_EMPTY_FILE);
}
- text = pkgdb_sub_get_field(text, dbs, filename);
+ /* text = pkgdb_sub_get_field(text, sub, filename); */
fd = open(path_to_file, O_RDONLY);
free(path_to_file);
@@ -90,7 +98,7 @@
text = malloc(sb.st_size + 1);
if (text == NULL) {
close(fd);
- return (SUB_MEMORY_ERR);
+ return (MEMORY_ERR);
}
s = read(fd, text, sb.st_size);
close(fd);
@@ -98,27 +106,29 @@
free(text);
return (SUB_NO_FILE); /* Could be a lie, maybe check errno? */
}
+ text[sb.st_size] = '\0';
+
/* This is dumb. But I forgot how computers work and wrote this
* function like a moron. So I'm stuck with it until I feel like
* coming back to it. */
if (strcmp(filename, COMMENT_FILE) == 0)
- dbs->comment_text = text;
+ sub->comment_text = text;
else if (strcmp(filename, CONTENTS_FILE) == 0)
- dbs->contents_text = text;
+ sub->contents_text = text;
else if (strcmp(filename, DESC_FILE) == 0)
- dbs->desc_text = text;
+ sub->desc_text = text;
else if (strcmp(filename, DISPLAY_FILE) == 0)
- dbs->display_text = text;
+ sub->display_text = text;
else if (strcmp(filename, MTREE_DIRS_FILE) == 0)
- dbs->mtree_dirs_text = text;
+ sub->mtree_dirs_text = text;
else if (strcmp(filename, REQUIRED_BY_FILE) == 0)
- dbs->required_by_text = text;
+ sub->required_by_text = text;
else {
free(text);
return (SUB_NO_FILE); /* No where to put it. */
}
- return (SUB_OK);
+ return (OK);
}
char *
@@ -176,7 +186,7 @@
}
char *
-pkgdb_sub_required_by(struct pkgdb_sub *dbs);
+pkgdb_sub_required_by(struct pkgdb_sub *dbs)
{
if (dbs == NULL)
BAD_ARG_RAGE;
@@ -209,7 +219,7 @@
}
void
-pkgdb_sub_free(struct pkgdb_sub *dbs)
+pkgdb_sub_delete(struct pkgdb_sub *dbs)
{
if (dbs == NULL)
return;
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb_pkgdb_sub.h#5 (text+ko) ====
@@ -27,7 +27,7 @@
int pkgdb_sub_set_assign_db(struct pkgdb *owner, struct pkgdb_sub *dbs);
-int pkgdb_sub_read_file_to_text(struct pkgdb_sub *dbs, const char *filename);
+int pkgdb_sub_read_file_to_text(struct pkgdb_sub *sub, const char *filename);
char *pkgdb_sub_ident(struct pkgdb_sub *dbs);
@@ -47,6 +47,6 @@
void pkgdb_sub_reset(struct pkgdb_sub *dbs);
-void pkgdb_sub_free(struct pkgdb_sub *dbs);
+void pkgdb_sub_delete(struct pkgdb_sub *dbs);
#endif
==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#12 (text+ko) ====
@@ -59,7 +59,7 @@
perform_on_db(db);
- pkgdb_db_delete(db);
+ pkgdb_delete(db);
return (EXIT_SUCCESS);
}
@@ -144,8 +144,8 @@
printf("\tcwd: %s\n", cwd);
printf("\torigin: %s\n", origin);
printf("\tfiles:\n");
- pkg_file_list_init(p);
- while ((pf = pkg_file_list_next(p)) != NULL) {
+ pkg_pkg_file_list_init(p);
+ while ((pf = pkg_pkg_file_list_next(p)) != NULL) {
path =
((path = pkg_file_path(pf)) == NULL ? BAD_OR_UNKNOWN_VALUE : path);
md5 =
More information about the p4-projects
mailing list