[Midnightbsd-cvs] src: lib/libmport: Added mport_parselist().
ctriv at midnightbsd.org
ctriv at midnightbsd.org
Mon Sep 24 12:49:59 EDT 2007
Log Message:
-----------
Added mport_parselist().
Conflicts and depends are now inserted into the package file db. The schema
of this will probably change once the install end is written and we know
what we need.
Modified Files:
--------------
src/lib/libmport:
create_pkg.c (r1.2 -> r1.3)
mport.h (r1.1 -> r1.2)
util.c (r1.2 -> r1.3)
-------------- next part --------------
Index: util.c
===================================================================
RCS file: /home/cvs/src/lib/libmport/util.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Llib/libmport/util.c -Llib/libmport/util.c -u -r1.2 -r1.3
--- lib/libmport/util.c
+++ lib/libmport/util.c
@@ -64,7 +64,11 @@
free(pack);
}
-
+/*
+ *Copy fromname to toname
+ *
+ * XXX: This is needs some work. perms?
+ */
int mport_copy_file(const char *fromname, const char *toname)
{
int to;
@@ -94,6 +98,9 @@
return MPORT_OK;
}
+/*
+ * Quick test to see if a file exists.
+ */
int mport_file_exists(const char *file)
{
struct stat st;
@@ -102,3 +109,54 @@
}
+
+/*
+ * mport_parselist(input, string_array_pointer)
+ *
+ * hacks input into sub strings by whitespace. Allocates a chunk or memory
+ * for a array of those strings, and sets the pointer you pass to refernce
+ * that memory
+ *
+ * char input[] = "foo bar baz"
+ * char **list;
+ *
+ * mport_parselist(input, &list);
+ * list = {"foo", "bar", "baz"};
+ */
+void mport_parselist(char *opt, char ***list)
+{
+ int len;
+ char *input;
+ char *field;
+
+ input = (char *)malloc(strlen(opt));
+ strlcpy(input, opt, strlen(opt));
+
+ /* first we need to get the length of the depends list */
+ for (len = 0; (field = strsep(&opt, " \t\n")) != NULL;) {
+ if (*field != '\0')
+ len++;
+ }
+
+ *list = (char **)malloc((len + 1) * sizeof(char *));
+
+ if (len == 0) {
+ **list = NULL;
+ return;
+ }
+
+ /* dereference once so we don't loose our minds. */
+ char **vec = *list;
+
+ while ((field = strsep(&input, " \t\n")) != NULL) {
+ if (*field == '\0')
+ continue;
+
+ *vec = field;
+ vec++;
+ }
+
+ *vec = NULL;
+}
+
+
Index: mport.h
===================================================================
RCS file: /home/cvs/src/lib/libmport/mport.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -Llib/libmport/mport.h -Llib/libmport/mport.h -u -r1.1 -r1.2
--- lib/libmport/mport.h
+++ lib/libmport/mport.h
@@ -124,5 +124,6 @@
int mport_copy_file(const char *, const char *);
int mport_file_exists(const char *);
+void mport_parselist(char *, char ***);
#endif
Index: create_pkg.c
===================================================================
RCS file: /home/cvs/src/lib/libmport/create_pkg.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Llib/libmport/create_pkg.c -Llib/libmport/create_pkg.c -u -r1.2 -r1.3
--- lib/libmport/create_pkg.c
+++ lib/libmport/create_pkg.c
@@ -52,6 +52,8 @@
static int create_package_db(sqlite3 **);
static int create_plist(sqlite3 *, mportPlist *, mportPackageMeta *);
static int create_meta(sqlite3 *, mportPackageMeta *);
+static int insert_depends(sqlite3 *, mportPackageMeta *);
+static int insert_conflicts(sqlite3 *, mportPackageMeta *);
static int copy_metafiles(mportPackageMeta *);
static int archive_files(mportPlist *, mportPackageMeta *);
static int clean_up(const char *);
@@ -178,6 +180,7 @@
sqlite3_stmt *stmnt;
const char *rest = 0;
struct timespec now;
+ int ret;
char sql[] = "INSERT INTO package (pkg, version, lang, date) VALUES (?,?,?,?)";
@@ -211,9 +214,80 @@
sqlite3_finalize(stmnt);
+ /* insert depends and conflicts */
+ if ((ret = insert_depends(db, pack)) != MPORT_OK)
+ return ret;
+ if ((ret = insert_conflicts(db, pack)) != MPORT_OK)
+ return ret;
+
+ return MPORT_OK;
+}
+
+
+static int insert_conflicts(sqlite3 *db, mportPackageMeta *pack)
+{
+ sqlite3_stmt *stmnt;
+ char sql[] = "INSERT INTO depends (pkg, depend) VALUES (?,?)";
+ char **conflict = pack->conflicts;
+ const char *rest = 0;
+
+ if (sqlite3_prepare_v2(db, sql, -1, &stmnt, &rest) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ while (*conflict != NULL) {
+ if (sqlite3_bind_text(stmnt, 1, pack->name, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ if (sqlite3_bind_text(stmnt, 2, *conflict, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ if (sqlite3_step(stmnt) != SQLITE_DONE) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ sqlite3_reset(stmnt);
+ conflict++;
+ }
+
+ sqlite3_finalize(stmnt);
+
+ return MPORT_OK;
+}
+
+
+
+static int insert_depends(sqlite3 *db, mportPackageMeta *pack)
+{
+ sqlite3_stmt *stmnt;
+ char sql[] = "INSERT INTO depends (pkg, depend) VALUES (?,?)";
+ char **depend = pack->depends;
+ const char *rest = 0;
+
+ if (sqlite3_prepare_v2(db, sql, -1, &stmnt, &rest) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ while (*depend != NULL) {
+ if (sqlite3_bind_text(stmnt, 1, pack->name, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ if (sqlite3_bind_text(stmnt, 2, *depend, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ if (sqlite3_step(stmnt) != SQLITE_DONE) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ sqlite3_reset(stmnt);
+ depend++;
+ }
+
+ sqlite3_finalize(stmnt);
+
return MPORT_OK;
}
+
+
/* this is just to save a lot of typing. It will only work in the
copy_metafiles() function.
*/
@@ -311,9 +385,6 @@
snprintf(filename, FILENAME_MAX, "%s/%s/%s", pack->sourcedir, cwd, e->data);
- fprintf(stderr, "statting: %s\n", filename);
-
-
if (lstat(filename, &st) != 0) {
RETURN_ERROR(MPORT_ERR_SYSCALL_FAILED, strerror(errno));
}
More information about the Midnightbsd-cvs
mailing list