Revision: 70488 http://trac.macports.org/changeset/70488 Author: and.damore@macports.org Date: 2010-08-11 04:05:46 -0700 (Wed, 11 Aug 2010) Log Message: ----------- added "md5sums" command to registry::entry, returns a list of bare 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 branches/gsoc10-configfiles/base/src/registry2.0/portimage.tcl Modified: branches/gsoc10-configfiles/base/src/cregistry/entry.c =================================================================== --- branches/gsoc10-configfiles/base/src/cregistry/entry.c 2010-08-11 09:15:56 UTC (rev 70487) +++ branches/gsoc10-configfiles/base/src/cregistry/entry.c 2010-08-11 11:05:46 UTC (rev 70488) @@ -1310,6 +1310,73 @@ } /** + * Gets a list of md5sums owned by the given port. + * + * TODO: check that the port is active + * + * @param [in] entry entry to get the list for + * @param [out] md5sums a list of md5sums owned by the port + * @param [out] errPtr on error, a description of the error that occurred + * @return the number of md5sums if success; negative if failure + */ +int reg_entry_md5sums(reg_entry* entry, char*** md5sums, reg_error* errPtr) { + reg_registry* reg = entry->reg; + sqlite3_stmt* stmt = NULL; + char* query = "SELECT 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 = malloc(10*sizeof(char*)); + int result_count = 0; + int result_space = 10; + int r; + const char *text; + char* element; + if (!result) { + return -1; + } + do { + r = sqlite3_step(stmt); + switch (r) { + case SQLITE_ROW: + text = (const char*)sqlite3_column_text(stmt, 0); + if (text) { + element = strdup(text); + if (!element || !reg_listcat((void***)&result, &result_count, &result_space, 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) { + *md5sums = result; + return result_count; + } else { + int i; + for (i=0; i<result_count; i++) { + free(result[i]); + } + free(result); + 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-11 09:15:56 UTC (rev 70487) +++ branches/gsoc10-configfiles/base/src/cregistry/entry.h 2010-08-11 11:05:46 UTC (rev 70488) @@ -84,11 +84,14 @@ 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_md5sums(reg_entry* entry, 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-11 09:15:56 UTC (rev 70487) +++ branches/gsoc10-configfiles/base/src/registry2.0/entryobj.c 2010-08-11 11:05:46 UTC (rev 70488) @@ -404,6 +404,40 @@ } } +static int entry_obj_md5sums(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, "md5sums"); + return TCL_ERROR; + } else if (reg == NULL) { + return TCL_ERROR; + } else { + char** md5sums; + reg_error error; + int file_count = reg_entry_md5sums(entry, &md5sums, &error); + int i; + if (file_count >= 0) { + Tcl_Obj** objs; + int retval = TCL_ERROR; + if (list_string_to_obj(&objs, md5sums, 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(md5sums[i]); + } + free(md5sums); + 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); @@ -569,6 +603,7 @@ { "files_with_md5", entry_obj_files_with_md5 }, { "imagefiles", entry_obj_imagefiles }, { "imagefiles_with_md5", entry_obj_imagefiles_with_md5 }, + { "md5sums", entry_obj_md5sums }, { "activate", entry_obj_activate }, { "deactivate", entry_obj_filemap }, /* dep map */ Modified: branches/gsoc10-configfiles/base/src/registry2.0/portimage.tcl =================================================================== --- branches/gsoc10-configfiles/base/src/registry2.0/portimage.tcl 2010-08-11 09:15:56 UTC (rev 70487) +++ branches/gsoc10-configfiles/base/src/registry2.0/portimage.tcl 2010-08-11 11:05:46 UTC (rev 70488) @@ -216,7 +216,6 @@ } } - #branch on sqlite-registry-db or old–flatfile if {$use_reg2} { if { [string equal $name ""] } { throw registry::image-error "Registry error: Please specify the name of the port." @@ -258,7 +257,6 @@ ui_msg "$UI_PREFIX [format [msgcat::mc "Deactivating %s"] $name]" } - #here we go - if {$use_reg2} { if { ![string equal [$requested installtype] "image"] } { return -code error "Image error: ${name} @${specifier} not installed as an image." @@ -699,7 +697,7 @@ variable use_reg2 set files [list] - foreach file $imagefiles { + foreach file $imagefiles { if { [file exists $file] || (![catch {file type $file}] && [file type $file] == "link") } { # Normalize the file path to avoid removing the intermediate # symlinks (remove the empty directories instead) @@ -736,7 +734,7 @@ $port deactivate $imagefiles foreach file $files { if {[is_config_file $file]} { - #puts "GSOC: $file is config file, skipping for now" + puts "GSOC: $file is config file" #continue } _deactivate_file $file @@ -751,7 +749,7 @@ proc is_config_file {filename} { #replace hardcoded path with $config_path from portmain.tcl, what namespace does "option" add options to? - if {[string match ${::macports::prefix} "$filename"]} {return 1} {return 0} + if {[string match ${::macports::prefix}/etc "$filename"]} {return 1} {return 0} } # End of portimage namespace
participants (1)
-
and.damore@macports.org