[57436] trunk/base/src

jmr at macports.org jmr at macports.org
Thu Sep 10 23:24:31 PDT 2009


Revision: 57436
          http://trac.macports.org/changeset/57436
Author:   jmr at macports.org
Date:     2009-09-10 23:24:27 -0700 (Thu, 10 Sep 2009)
Log Message:
-----------
add realpath command to try to fix #21082

Modified Paths:
--------------
    trunk/base/src/macports1.0/Makefile
    trunk/base/src/macports1.0/macports.c
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/registry1.0/portimage.tcl
    trunk/base/src/registry1.0/portuninstall.tcl
    trunk/base/src/registry2.0/portimage.tcl
    trunk/base/src/registry2.0/portuninstall.tcl

Added Paths:
-----------
    trunk/base/src/macports1.0/realpath.c
    trunk/base/src/macports1.0/realpath.h

Modified: trunk/base/src/macports1.0/Makefile
===================================================================
--- trunk/base/src/macports1.0/Makefile	2009-09-11 04:09:50 UTC (rev 57435)
+++ trunk/base/src/macports1.0/Makefile	2009-09-11 06:24:27 UTC (rev 57436)
@@ -1,6 +1,6 @@
 SRCS=		macports.tcl macports_dlist.tcl macports_util.tcl \
 		macports_autoconf.tcl macports_index.tcl macports_fastload.tcl
-OBJS=		macports.o get_systemconfiguration_proxies.o sysctl.o
+OBJS=		macports.o get_systemconfiguration_proxies.o realpath.o sysctl.o
 SHLIB_NAME=	MacPorts${SHLIB_SUFFIX}
 
 INSTALLDIR=	${DESTDIR}${TCL_PACKAGE_DIR}/macports1.0

Modified: trunk/base/src/macports1.0/macports.c
===================================================================
--- trunk/base/src/macports1.0/macports.c	2009-09-11 04:09:50 UTC (rev 57435)
+++ trunk/base/src/macports1.0/macports.c	2009-09-11 06:24:27 UTC (rev 57436)
@@ -38,6 +38,7 @@
 #include <tcl.h>
 
 #include "get_systemconfiguration_proxies.h"
+#include "realpath.h"
 #include "sysctl.h"
 
 static int
@@ -58,6 +59,7 @@
 		return TCL_ERROR;
 	Tcl_CreateObjCommand(interp, "macports::version", macports__version, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "get_systemconfiguration_proxies", GetSystemConfigurationProxiesCmd, NULL, NULL);
+	Tcl_CreateObjCommand(interp, "realpath", RealpathCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "sysctl", SysctlCmd, NULL, NULL);
 	if (Tcl_PkgProvide(interp, "macports", "1.0") != TCL_OK)
 		return TCL_ERROR;

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2009-09-11 04:09:50 UTC (rev 57435)
+++ trunk/base/src/macports1.0/macports.tcl	2009-09-11 06:24:27 UTC (rev 57436)
@@ -834,6 +834,7 @@
     $workername alias findBinary macports::findBinary
     $workername alias binaryInPath macports::binaryInPath
     $workername alias sysctl sysctl
+    $workername alias realpath realpath
 
     # New Registry/Receipts stuff
     $workername alias registry_new registry::new_entry

Added: trunk/base/src/macports1.0/realpath.c
===================================================================
--- trunk/base/src/macports1.0/realpath.c	                        (rev 0)
+++ trunk/base/src/macports1.0/realpath.c	2009-09-11 06:24:27 UTC (rev 57436)
@@ -0,0 +1,77 @@
+/*
+ * realpath.c
+ * $Id$
+ *
+ * Copyright (c) 2009 The MacPorts Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of MacPorts Team nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <tcl.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "realpath.h"
+
+/**
+ * realpath command entry point.
+ *
+ * @param interp		current interpreter
+ * @param objc			number of parameters
+ * @param objv			parameters
+ */
+int RealpathCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
+{
+    const char error_message[] = "realpath failed: ";
+    Tcl_Obj *tcl_result;
+    char *path;
+    char *rpath;
+
+    if (objc != 2) {
+        Tcl_WrongNumArgs(interp, 1, objv, "path");
+        return TCL_ERROR;
+    }
+
+    path = Tcl_GetString(objv[1]);
+    rpath = realpath(path, NULL);
+    if (!rpath) {
+        tcl_result = Tcl_NewStringObj(error_message, sizeof(error_message) - 1);
+        Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(strerror(errno), -1));
+        Tcl_SetObjResult(interp, tcl_result);
+        return TCL_ERROR;
+    } else {
+        tcl_result = Tcl_NewStringObj(rpath, -1);
+    }
+    
+    Tcl_SetObjResult(interp, tcl_result);
+    return TCL_OK;
+}

Added: trunk/base/src/macports1.0/realpath.h
===================================================================
--- trunk/base/src/macports1.0/realpath.h	                        (rev 0)
+++ trunk/base/src/macports1.0/realpath.h	2009-09-11 06:24:27 UTC (rev 57436)
@@ -0,0 +1,49 @@
+/*
+ * realpath.h
+ * $Id$
+ *
+ * Copyright (c) 2009 The MacPorts Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of MacPorts Team nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _REALPATH_H
+#define _REALPATH_H
+
+#include <tcl.h>
+
+/**
+ * A native command to handle a limitation of old versions of Tcl.
+ *
+ * The syntax is:
+ * realpath path
+ *	Normalize path like file normalize does.
+ *  Fixes a problem with Tcl installations affected by not defining HAVE_REALPATH (this is
+ *	the case with the Tcl in OS X shipped prior to 10.6)
+ */
+int RealpathCmd(ClientData clientData, Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
+
+#endif /* _REALPATH_H */

Modified: trunk/base/src/registry1.0/portimage.tcl
===================================================================
--- trunk/base/src/registry1.0/portimage.tcl	2009-09-11 04:09:50 UTC (rev 57435)
+++ trunk/base/src/registry1.0/portimage.tcl	2009-09-11 06:24:27 UTC (rev 57436)
@@ -411,8 +411,9 @@
 			lappend files $theFile
 			
 			# Split out the filename's subpaths and add them to the image list as
-			# well.
-			set directory [file dirname $theFile]
+			# well. The realpath call is necessary because file normalize
+			# does not resolve symlinks on OS X < 10.6
+			set directory [realpath [file dirname $theFile]]
 			while { [lsearch -exact $files $directory] == -1 } { 
 				lappend files $directory
 				set directory [file dirname $directory]

Modified: trunk/base/src/registry1.0/portuninstall.tcl
===================================================================
--- trunk/base/src/registry1.0/portuninstall.tcl	2009-09-11 04:09:50 UTC (rev 57435)
+++ trunk/base/src/registry1.0/portuninstall.tcl	2009-09-11 06:24:27 UTC (rev 57436)
@@ -194,8 +194,9 @@
 			lappend files $theFile
 
 			# Split out the filename's subpaths and add them to the
-			# list as well.
-			set directory [file dirname $theFile]
+			# list as well. The realpath call is necessary because file normalize
+			# does not resolve symlinks on OS X < 10.6
+			set directory [realpath [file dirname $theFile]]
 			while { [lsearch -exact $files $directory] == -1 } { 
 				lappend files $directory
 				set directory [file dirname $directory]

Modified: trunk/base/src/registry2.0/portimage.tcl
===================================================================
--- trunk/base/src/registry2.0/portimage.tcl	2009-09-11 04:09:50 UTC (rev 57435)
+++ trunk/base/src/registry2.0/portimage.tcl	2009-09-11 06:24:27 UTC (rev 57436)
@@ -400,7 +400,7 @@
 
             # Split out the filename's subpaths and add them to the image list
             # as well.
-            set directory [file dirname $theFile]
+            set directory [realpath [file dirname $theFile]]
             while { [lsearch -exact $files $directory] == -1 } {
                 lappend files $directory
                 set directory [file dirname $directory]

Modified: trunk/base/src/registry2.0/portuninstall.tcl
===================================================================
--- trunk/base/src/registry2.0/portuninstall.tcl	2009-09-11 04:09:50 UTC (rev 57435)
+++ trunk/base/src/registry2.0/portuninstall.tcl	2009-09-11 06:24:27 UTC (rev 57436)
@@ -129,7 +129,7 @@
 
         # Split out the filename's subpaths and add them to the
         # list as well.
-        set directory [file dirname $theFile]
+        set directory [realpath [file dirname $theFile]]
         while { [lsearch -exact $files $directory] == -1 } { 
             lappend files $directory
             set directory [file dirname $directory]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090910/38a8956a/attachment-0001.html>


More information about the macports-changes mailing list