[99865] trunk/base/src

jmr at macports.org jmr at macports.org
Mon Nov 19 13:10:26 PST 2012


Revision: 99865
          https://trac.macports.org/changeset/99865
Author:   jmr at macports.org
Date:     2012-11-19 13:10:26 -0800 (Mon, 19 Nov 2012)
Log Message:
-----------
use a hash of the portvariants in the archive filename if it would otherwise be too long

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/md_wrappers.h
    trunk/base/src/pextlib1.0/rmd160cmd.c
    trunk/base/src/port1.0/portutil.tcl

Modified: trunk/base/src/pextlib1.0/md_wrappers.h
===================================================================
--- trunk/base/src/pextlib1.0/md_wrappers.h	2012-11-19 19:11:16 UTC (rev 99864)
+++ trunk/base/src/pextlib1.0/md_wrappers.h	2012-11-19 21:10:26 UTC (rev 99865)
@@ -79,5 +79,15 @@
     return algo##End(&ctx, buf);						\
 }
 
+#define CHECKSUMData(algo, ctxtype)						\
+static char *algo##Data(const u_char *str, u_int32_t len, char *buf)		\
+{														\
+    ctxtype ctx;										\
+														\
+    algo##Init(&ctx);									\
+    algo##Update(&ctx,str,len);					        \
+    return algo##End(&ctx, buf);						\
+}
+
 #endif
 /* _MD_WRAPPERS_H */

Modified: trunk/base/src/pextlib1.0/rmd160cmd.c
===================================================================
--- trunk/base/src/pextlib1.0/rmd160cmd.c	2012-11-19 19:11:16 UTC (rev 99864)
+++ trunk/base/src/pextlib1.0/rmd160cmd.c	2012-11-19 21:10:26 UTC (rev 99865)
@@ -55,6 +55,7 @@
 #include "md_wrappers.h"
 CHECKSUMEnd(RIPEMD160_, RIPEMD160_CTX, RIPEMD160_DIGEST_LENGTH)
 CHECKSUMFile(RIPEMD160_, RIPEMD160_CTX)
+CHECKSUMData(RIPEMD160_, RIPEMD160_CTX)
 #else
 /*
  * let's use our own version of rmd160* libraries.
@@ -64,18 +65,22 @@
 #include "rmd160.c"
 #define RIPEMD160_DIGEST_LENGTH 20
 #define RIPEMD160_File(x,y) RMD160File(x,y)
+#define RIPEMD160_Data(x,y,z) RMD160Data(x,y,z)
 
 #include "md_wrappers.h"
 CHECKSUMEnd(RMD160, RMD160_CTX, RIPEMD160_DIGEST_LENGTH)
 CHECKSUMFile(RMD160, RMD160_CTX)
+CHECKSUMData(RMD160, RMD160_CTX)
 #endif
 
 int RMD160Cmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	char *file, *action;
+	char *file, *instr, *action;
+	int inlen;
 	char buf[2*RIPEMD160_DIGEST_LENGTH + 1];
 	const char usage_message[] = "Usage: rmd160 file";
-	const char error_message[] = "Could not open file: ";
+	const char file_error_message[] = "Could not open file: ";
+	const char string_error_message[] = "Could not process string: ";
 	Tcl_Obj *tcl_result;
 
 	if (objc != 3) {
@@ -84,22 +89,33 @@
 	}
 
 	/*
-	 * Only the 'file' action is currently supported
+	 * 'file' and 'string' actions are currently supported
 	 */
 	action = Tcl_GetString(objv[1]);
-	if (strcmp(action, "file") != 0) {
+	if (strcmp(action, "file") == 0) {
+	    file = Tcl_GetString(objv[2]);
+
+        if (!RIPEMD160_File(file, buf)) {
+            tcl_result = Tcl_NewStringObj(file_error_message, sizeof(file_error_message) - 1);
+            Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(file, -1));
+            Tcl_SetObjResult(interp, tcl_result);
+            return TCL_ERROR;
+        }
+	} else if (strcmp(action, "string") == 0) {
+	    instr = Tcl_GetStringFromObj(objv[2], &inlen);
+
+	    if (!RIPEMD160_Data((u_char *)instr, (u_int32_t)inlen, buf)) {
+            tcl_result = Tcl_NewStringObj(string_error_message, sizeof(string_error_message) - 1);
+            Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(instr, -1));
+            Tcl_SetObjResult(interp, tcl_result);
+            return TCL_ERROR;
+        }
+	} else {
 		tcl_result = Tcl_NewStringObj(usage_message, sizeof(usage_message) - 1);
 		Tcl_SetObjResult(interp, tcl_result);
 		return TCL_ERROR;
 	}
-	file = Tcl_GetString(objv[2]);
-
-	if (!RIPEMD160_File(file, buf)) {
-		tcl_result = Tcl_NewStringObj(error_message, sizeof(error_message) - 1);
-		Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(file, -1));
-		Tcl_SetObjResult(interp, tcl_result);
-		return TCL_ERROR;
-	}
+	
 	tcl_result = Tcl_NewStringObj(buf, sizeof(buf) - 1);
 	Tcl_SetObjResult(interp, tcl_result);
 	return TCL_OK;

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2012-11-19 19:11:16 UTC (rev 99864)
+++ trunk/base/src/port1.0/portutil.tcl	2012-11-19 21:10:26 UTC (rev 99865)
@@ -2398,7 +2398,17 @@
 # return filename of the archive for this port
 proc get_portimage_name {} {
     global portdbpath subport version revision portvariants os.platform os.major portarchivetype
-    return "${subport}-${version}_${revision}${portvariants}.${os.platform}_${os.major}.[join [get_canonical_archs] -].${portarchivetype}"
+    set ret "${subport}-${version}_${revision}${portvariants}.${os.platform}_${os.major}.[join [get_canonical_archs] -].${portarchivetype}"
+    # should really look up NAME_MAX here, but it's 255 for all OS X so far
+    # (leave 10 chars for an extension like .rmd160 on the sig file)
+    if {[string length $ret] > 245 && ${portvariants} != ""} {
+        # try hashing the variants
+        set ret "${subport}-${version}_${revision}+[rmd160 string ${portvariants}].${os.platform}_${os.major}.[join [get_canonical_archs] -].${portarchivetype}"
+    }
+    if {[string length $ret] > 245} {
+        error "filename too long: $ret"
+    }
+    return $ret
 }
 
 # return path where a newly created image/archive for this port will be stored
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20121119/4d9e9bbc/attachment.html>


More information about the macports-changes mailing list