[70448] branches/gsoc10-configfiles/base/src
and.damore at macports.org
and.damore at macports.org
Mon Aug 9 13:21:19 PDT 2010
Revision: 70448
http://trac.macports.org/changeset/70448
Author: and.damore at macports.org
Date: 2010-08-09 13:21:19 -0700 (Mon, 09 Aug 2010)
Log Message:
-----------
added to entry.o and entryobj.o functions to read out paths with md5 checksums
Modified Paths:
--------------
branches/gsoc10-configfiles/base/src/cregistry/entry.c
branches/gsoc10-configfiles/base/src/cregistry/entry.h
branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c
Modified: branches/gsoc10-configfiles/base/src/cregistry/entry.c
===================================================================
--- branches/gsoc10-configfiles/base/src/cregistry/entry.c 2010-08-09 19:33:55 UTC (rev 70447)
+++ branches/gsoc10-configfiles/base/src/cregistry/entry.c 2010-08-09 20:21:19 UTC (rev 70448)
@@ -904,8 +904,8 @@
printf("GSOCDBG: \t\t\tinside first if branch\n");
if (sqlite3_bind_text(stmt, 3, md5sums[i], -1, SQLITE_STATIC)
== SQLITE_OK) {
+ int r;
printf("GSOCDBG: \t\t\tinside second if branch\n");
- int r;
do {
r = sqlite3_step(stmt);
switch (r) {
@@ -1063,6 +1063,94 @@
}
/**
+ * Gets a list of files provided by the given port. These files are in the port
+ * image and do not necessarily correspond to active files on the filesystem.
+ *
+ * TODO: check that the port's installtype is image
+ *
+ * @param [in] entry entry to get the list for
+ * @param [out] files a list of files provided by the port
+ * @param [out] md5sums a list of files provided by the port
+ * @param [out] errPtr on error, a description of the error that occurred
+ * @return the number of files if success; negative if failure
+ */
+int reg_entry_imagefiles_with_md5(reg_entry* entry, char*** files,
+ char*** md5sums, reg_error* errPtr) {
+ reg_registry* reg = entry->reg;
+ sqlite3_stmt* stmt = NULL;
+ char* query = "SELECT path,md5sum FROM registry.files WHERE id=? ORDER BY path";
+ if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+ && (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)) {
+ char** result_files = malloc(10*sizeof(char*));
+ int result_count_files = 0;
+ int result_space_files = 10;
+ char** result_md5sums = malloc(10*sizeof(char*));
+ int result_count_md5sums = 0;
+ int result_space_md5sums = 10;
+ int r;
+ const char *text_file;
+ const char *text_md5sum;
+ char* element;
+
+ if (!result_files || !result_md5sums) {
+ return -1;
+ }
+ do {
+ r = sqlite3_step(stmt);
+ switch (r) {
+ case SQLITE_ROW:
+ /* here we're accessing the SQL statement data */
+ text_file = (const char*)sqlite3_column_text(stmt, 0);
+ if (text_file) {
+ element = strdup(text_file);
+ if (!element || !reg_listcat((void***)&result_files, &result_count_files, &result_space_files, element)) {
+ r = SQLITE_ERROR;
+ }
+ }
+ text_md5sum = (const char*)sqlite3_column_text(stmt, 1);
+ if (text_md5sum) {
+ element = strdup(text_md5sum);
+ if (!element || !reg_listcat((void***)&result_md5sums, &result_count_md5sums, &result_space_md5sums, element)) {
+ r = SQLITE_ERROR;
+ }
+ }
+ break;
+ case SQLITE_DONE:
+ case SQLITE_BUSY:
+ break;
+ default:
+ reg_sqlite_error(reg->db, errPtr, query);
+ break;
+ }
+ } while (r == SQLITE_ROW || r == SQLITE_BUSY);
+ sqlite3_finalize(stmt);
+ if (r == SQLITE_DONE) {
+ *files = result_files;
+ *md5sums = result_md5sums;
+ /* this is lacking result_count_md5sums, shouldn't be necessary */
+ return result_count_files;
+ } else {
+ int i;
+ for (i=0; i<result_count_files; i++) {
+ free(result_files[i]);
+ }
+ for (i=0; i<result_count_md5sums; i++) {
+ free(result_md5sums[i]);
+ }
+ free(result_files);
+ free(result_md5sums);
+ return -1;
+ }
+ } else {
+ reg_sqlite_error(reg->db, errPtr, query);
+ if (stmt) {
+ sqlite3_finalize(stmt);
+ }
+ return -1;
+ }
+}
+
+/**
* Gets a list of files owned by the given port. These files are active in the
* filesystem and could be different from the port's imagefiles.
*
@@ -1131,6 +1219,95 @@
}
/**
+ * Gets a list of files owned by the given port. These files are active in the
+ * filesystem and could be different from the port's imagefiles.
+ *
+ * TODO: check that the port is active
+ *
+ * @param [in] entry entry to get the list for
+ * @param [out] files a list of files owned by the port
+ * @param [out] md5sums a list of files provided by the port
+ * @param [out] errPtr on error, a description of the error that occurred
+ * @return the number of files if success; negative if failure
+ */
+int reg_entry_files_with_md5(reg_entry* entry, char*** files, char*** md5sums,
+ reg_error* errPtr) {
+ reg_registry* reg = entry->reg;
+ sqlite3_stmt* stmt = NULL;
+ char* query = "SELECT actual_path,md5sum FROM registry.files WHERE id=? "
+ "AND active ORDER BY actual_path";
+ if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+ && (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)) {
+ char** result_files = malloc(10*sizeof(char*));
+ int result_count_files = 0;
+ int result_space_files = 10;
+ char** result_md5sums = malloc(10*sizeof(char*));
+ int result_count_md5sums = 0;
+ int result_space_md5sums = 10;
+ int r;
+ const char *text_file;
+ const char *text_md5sum;
+ char* element;
+
+ if (!result_files || !result_md5sums) {
+ return -1;
+ }
+ do {
+ r = sqlite3_step(stmt);
+ switch (r) {
+ case SQLITE_ROW:
+ /* here we're accessing the SQL statement data */
+ text_file = (const char*)sqlite3_column_text(stmt, 0);
+ if (text_file) {
+ element = strdup(text_file);
+ if (!element || !reg_listcat((void***)&result_files, &result_count_files, &result_space_files, element)) {
+ r = SQLITE_ERROR;
+ }
+ }
+ text_md5sum = (const char*)sqlite3_column_text(stmt, 1);
+ if (text_md5sum) {
+ element = strdup(text_md5sum);
+ if (!element || !reg_listcat((void***)&result_md5sums, &result_count_md5sums, &result_space_md5sums, element)) {
+ r = SQLITE_ERROR;
+ }
+ }
+ break;
+ case SQLITE_DONE:
+ case SQLITE_BUSY:
+ break;
+ default:
+ reg_sqlite_error(reg->db, errPtr, query);
+ break;
+ }
+ } while (r == SQLITE_ROW || r == SQLITE_BUSY);
+ sqlite3_finalize(stmt);
+ if (r == SQLITE_DONE) {
+ *files = result_files;
+ *md5sums = result_md5sums;
+ /* this is lacking result_count_md5sums, shouldn't be necessary */
+ return result_count_files;
+ } else {
+ int i;
+ for (i=0; i<result_count_files; i++) {
+ free(result_files[i]);
+ }
+ for (i=0; i<result_count_md5sums; i++) {
+ free(result_md5sums[i]);
+ }
+ free(result_files);
+ free(result_md5sums);
+ return -1;
+ }
+ } else {
+ reg_sqlite_error(reg->db, errPtr, query);
+ if (stmt) {
+ sqlite3_finalize(stmt);
+ }
+ return -1;
+ }
+}
+
+/**
* Sets an entry's files as being active in the filesystem. This entry will be
* subsequently returned by `reg_entry_owner` on those files' path. If all files
* are being activated as the names they are in the registry, then `as_files`
Modified: branches/gsoc10-configfiles/base/src/cregistry/entry.h
===================================================================
--- branches/gsoc10-configfiles/base/src/cregistry/entry.h 2010-08-09 19:33:55 UTC (rev 70447)
+++ branches/gsoc10-configfiles/base/src/cregistry/entry.h 2010-08-09 20:21:19 UTC (rev 70448)
@@ -84,7 +84,11 @@
int reg_entry_files(reg_entry* entry, char*** files, reg_error* errPtr);
int reg_entry_imagefiles(reg_entry* entry, char*** files, reg_error* errPtr);
-
+int reg_entry_files_with_md5(
+ reg_entry* entry, char*** files, char*** md5sums, reg_error* errPtr);
+int reg_entry_imagefiles_with_md5(
+ reg_entry* entry, char*** files, char*** md5sums, reg_error* errPtr);
+
int reg_entry_activate(reg_entry* entry, char** files, char** as_files,
int file_count, reg_error* errPtr);
int reg_entry_deactivate(reg_entry* entry, char** files, int file_count,
Modified: branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c
===================================================================
--- branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c 2010-08-09 19:33:55 UTC (rev 70447)
+++ branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c 2010-08-09 20:21:19 UTC (rev 70448)
@@ -266,6 +266,43 @@
}
}
+static int entry_obj_files_with_md5(Tcl_Interp* interp, reg_entry* entry, int objc,
+ Tcl_Obj* CONST objv[]) {
+ reg_registry* reg = registry_for(interp, reg_attached);
+ if (objc != 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "files_with_md5");
+ return TCL_ERROR;
+ } else if (reg == NULL) {
+ return TCL_ERROR;
+ } else {
+ char** files;
+ char** md5sums;
+ reg_error error;
+ /* call to entry.c function */
+ int file_count = reg_entry_files_with_md5(entry, &files, &md5sums, &error);
+ int i;
+ if (file_count >= 0) {
+ Tcl_Obj** objs;
+ int retval = TCL_ERROR;
+ if (list_string_to_obj(&objs, files, file_count, &error)) {
+ Tcl_Obj* result = Tcl_NewListObj(file_count, objs);
+ /* sending the result to Tcl, an object in this case */
+ Tcl_SetObjResult(interp, result);
+ free(objs);
+ retval = TCL_OK;
+ } else {
+ retval = registry_failed(interp, &error);
+ }
+ for (i=0; i<file_count; i++) {
+ free(files[i]);
+ }
+ free(files);
+ return retval;
+ }
+ return registry_failed(interp, &error);
+ }
+}
+
static int entry_obj_imagefiles(Tcl_Interp* interp, reg_entry* entry, int objc,
Tcl_Obj* CONST objv[]) {
reg_registry* reg = registry_for(interp, reg_attached);
@@ -300,6 +337,41 @@
}
}
+static int entry_obj_imagefiles_with_md5(Tcl_Interp* interp, reg_entry* entry, int objc,
+ Tcl_Obj* CONST objv[]) {
+ reg_registry* reg = registry_for(interp, reg_attached);
+ if (objc != 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "imagefiles_with_md5");
+ return TCL_ERROR;
+ } else if (reg == NULL) {
+ return TCL_ERROR;
+ } else {
+ char** files;
+ char** md5sums;
+ reg_error error;
+ int file_count = reg_entry_imagefiles_with_md5(entry, &files, &md5sums, &error);
+ int i;
+ if (file_count >= 0) {
+ Tcl_Obj** objs;
+ int retval = TCL_ERROR;
+ if (list_string_to_obj(&objs, files, file_count, &error)) {
+ Tcl_Obj* result = Tcl_NewListObj(file_count, objs);
+ Tcl_SetObjResult(interp, result);
+ free(objs);
+ retval = TCL_OK;
+ } else {
+ retval = registry_failed(interp, &error);
+ }
+ for (i=0; i<file_count; i++) {
+ free(files[i]);
+ }
+ free(files);
+ return retval;
+ }
+ return registry_failed(interp, &error);
+ }
+}
+
static int entry_obj_activate(Tcl_Interp* interp, reg_entry* entry, int objc,
Tcl_Obj* CONST objv[]) {
reg_registry* reg = registry_for(interp, reg_attached);
@@ -462,7 +534,9 @@
{ "map_with_md5", entry_obj_filemap_with_md5 },
{ "unmap", entry_obj_filemap },
{ "files", entry_obj_files },
+ { "files_with_md5", entry_obj_files_with_md5 },
{ "imagefiles", entry_obj_imagefiles },
+ { "imagefiles_with_md5", entry_obj_imagefiles_with_md5 },
{ "activate", entry_obj_activate },
{ "deactivate", entry_obj_filemap },
/* dep map */
@@ -483,7 +557,6 @@
int entry_obj_cmd(ClientData clientData, Tcl_Interp* interp, int objc,
Tcl_Obj* CONST objv[]) {
int cmd_index;
- int len=0;
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "cmd ?arg ...?");
return TCL_ERROR;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100809/9333780a/attachment-0001.html>
More information about the macports-changes
mailing list