[70399] branches/gsoc10-configfiles/base/src

and.damore at macports.org and.damore at macports.org
Sun Aug 8 01:13:03 PDT 2010


Revision: 70399
          http://trac.macports.org/changeset/70399
Author:   and.damore at macports.org
Date:     2010-08-08 01:13:03 -0700 (Sun, 08 Aug 2010)
Log Message:
-----------
C registry functions in cregistry and registry2.0 to allow md5 checksum storage

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-08 08:10:03 UTC (rev 70398)
+++ branches/gsoc10-configfiles/base/src/cregistry/entry.c	2010-08-08 08:13:03 UTC (rev 70399)
@@ -860,6 +860,69 @@
 }
 
 /**
+ * Maps files to the given port in the filemap along with their md5 checksums.
+ * The list of files must not contain files that are already mapped to the
+ * given port.
+ *
+ * @param [in] entry      the entry to map the files to
+ * @param [in] files      a list of files to map
+ * @param [in] md5sums      a list of files to map
+ * @param [in] arg_count the number of files
+ * @param [out] errPtr    on error, a description of the error that occurred
+ * @return                true if success; false if failure
+ */
+int reg_entry_map_with_md5(reg_entry* entry, char** files, char** md5sums, int arg_count,
+        reg_error* errPtr) {
+    reg_registry* reg = entry->reg;
+    int result = 1;
+    sqlite3_stmt* stmt = NULL;
+    char* insert = "INSERT INTO registry.files (id, path, mtime, active, md5sum) "
+        "VALUES (?, ?, 0, 0, ?)";
+    /*  sqlite3_prepare() is documented as legacy, http://www.sqlite.org/c3ref/step.html
+        use sqlite3_prepare_v2() should be used instead */
+    if ((sqlite3_prepare(reg->db, insert, -1, &stmt, NULL) == SQLITE_OK)
+            && (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)) {
+        int i;
+        for (i=0; i<arg_count && result; i++) {
+            /*  cycles through files[] array of strings,
+                the if argument parse a file from the array and put in into
+                the SQL statement */
+            if (sqlite3_bind_text(stmt, 2, files[i], -1, SQLITE_STATIC)
+                    == SQLITE_OK) {
+                if (sqlite3_bind_text(stmt, 3, md5sums[i], -1, SQLITE_STATIC)
+                        == SQLITE_OK) {
+                    int r;
+                    do {
+                        r = sqlite3_step(stmt);
+                        switch (r) {
+                            case SQLITE_DONE:
+                                sqlite3_reset(stmt);
+                                break;
+                            case SQLITE_BUSY:
+                                break;
+                            default:
+                                reg_sqlite_error(reg->db, errPtr, insert);
+                                result = 0;
+                                break;
+                        }
+                    } while (r == SQLITE_BUSY);
+                }
+            } else {
+                reg_sqlite_error(reg->db, errPtr, insert);
+                result = 0;
+            }
+        }
+    } else {
+        reg_sqlite_error(reg->db, errPtr, insert);
+        result = 0;
+    }
+    if (stmt) {
+        sqlite3_finalize(stmt);
+    }
+    return result;
+}
+        
+/**
  * Unaps files from the given port in the filemap. The files must be owned by
  * the given entry.
  *

Modified: branches/gsoc10-configfiles/base/src/cregistry/entry.h
===================================================================
--- branches/gsoc10-configfiles/base/src/cregistry/entry.h	2010-08-08 08:10:03 UTC (rev 70398)
+++ branches/gsoc10-configfiles/base/src/cregistry/entry.h	2010-08-08 08:13:03 UTC (rev 70399)
@@ -77,6 +77,8 @@
 
 int reg_entry_map(reg_entry* entry, char** files, int file_count,
         reg_error* errPtr);
+int reg_entry_map_with_md5(reg_entry* entry, char** files, char** md5sums, int arg_count,
+        reg_error* errPtr);
 int reg_entry_unmap(reg_entry* entry, char** files, int file_count,
         reg_error* errPtr);
 

Modified: branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c
===================================================================
--- branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c	2010-08-08 08:10:03 UTC (rev 70398)
+++ branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c	2010-08-08 08:13:03 UTC (rev 70399)
@@ -155,6 +155,67 @@
     }
 }
 
+static int entry_obj_filemap_with_md5(Tcl_Interp* interp, reg_entry* entry, int objc,
+        Tcl_Obj* CONST objv[]) {
+    reg_registry* reg = registry_for(interp, reg_attached);
+    if (objc != 3) {
+        Tcl_WrongNumArgs(interp, 2, objv, "map {file md5checksum}-list");
+        return TCL_ERROR;
+    } else if (reg == NULL) {
+        return TCL_ERROR;
+    } else {
+        char** files;
+        char** md5sums;
+        reg_error error;
+        Tcl_Obj *element; 
+        Tcl_Obj** listv;
+        int listc;
+        int result = TCL_ERROR;
+        int i;
+
+        if (Tcl_ListObjGetElements(interp, objv[2], &listc, &listv) != TCL_OK) {
+            return TCL_ERROR;
+        }
+        files=malloc(listc*sizeof(char *));
+        md5sums=malloc(listc*sizeof(char*));
+        /*  remember to add check for malloc return values */
+        for (i = 0; i < listc; i++) { 
+            if (Tcl_ListObjIndex(interp, listv[i], 0, &element) != TCL_OK) {
+                free(files); free(md5sums); return TCL_ERROR; } 
+            else if(element != NULL)
+                files[i] = Tcl_GetString(element);
+            else {
+                Tcl_SetErrorCode(interp, "illegal input", NULL); return TCL_ERROR; }
+
+            if (Tcl_ListObjIndex(interp, listv[i], 1, &element) != TCL_OK) {
+                free(files); free(md5sums); return TCL_ERROR; } 
+            else if(element != NULL)
+                md5sums[i] = Tcl_GetString(element); 
+            else {
+                Tcl_SetErrorCode(interp, "illegal input", NULL); return TCL_ERROR; }
+        }
+        
+        /*  change the condition, */
+        /*  it used to be list_obj_to_string() but now we're filling arrays by hand  */
+        if ( 1 ) {
+            if (reg_entry_map_with_md5(entry, files, md5sums, listc, &error)) {
+                result = TCL_OK;
+            } else {
+                result = registry_failed(interp, &error);
+            }
+            free(files);
+            free(md5sums);
+        }
+        /*  the else branch is useless because if condition is a constant
+            cf. previous comment 
+        else {
+            result = registry_failed(interp, &error);
+        }
+        */
+        return result;
+    }
+}
+
 static int entry_obj_files(Tcl_Interp* interp, reg_entry* entry, int objc,
         Tcl_Obj* CONST objv[]) {
     reg_registry* reg = registry_for(interp, reg_attached);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100808/74bb9b11/attachment.html>


More information about the macports-changes mailing list