[129924] trunk/base/src/port1.0/porttrace.tcl

Lawrence Velázquez larryv at macports.org
Wed Dec 24 19:49:06 PST 2014


On Dec 23, 2014, at 4:48 PM, Mihai Moldovan <ionic at macports.org> wrote:

> There's no technical reason. normalize and resolve operate on the
> (shared) original path. I don't really get your question, though. What
> would you have done differently?

Originally I was just thinking about reorganizing the code, but after
staring at it a bit, I'd suggest something like this. As far as I can tell,
using `realpath` here obviates both `file normalize` and `file
readlink`.

Can we just do this instead? It's simpler and more correct. Or are there
catches I'm not seeing?

vq

diff --git a/base/src/port1.0/porttrace.tcl b/base/src/port1.0/porttrace.tcl
index 7c9e1c1..3796a55 100644
--- a/base/src/port1.0/porttrace.tcl
+++ b/base/src/port1.0/porttrace.tcl
@@ -67,28 +67,11 @@ namespace eval porttrace {
         # Escape equal signs with \=
         lappend mapping "=" "\\="
 
-        set normalizedPath [file normalize $path]
-        # file normalize will leave symlinks as the very last
-        # path component intact. This will, for instance, prevent /tmp from
-        # being resolved to /private/tmp.
-        # Also use file readlink to counter this behavior.
-        # file readlink returns an error, if the last component is not
-        # a symlink. Catch that.
-        set resolvedPath {}
-        if {![catch {file readlink $path}]} {
-          set resolvedPath [file readlink $path]
-
-          if {[string length $resolvedPath] > 0 && [string index $resolvedPath 0] ne "/"} {
-              # Canonicalize.
-              set resolvedPath [file normalize [file dirname $path]/$resolvedPath]
-          }
-        }
         lappend sndbxlst "[string map $mapping $path]=$action"
-        if {$normalizedPath ne $path} {
-            lappend sndbxlst "[string map $mapping $normalizedPath]=$action"
-        }
-        if {[string length $resolvedPath] > 0 && $resolvedPath ne $path} {
-            lappend sndbxlst "[string map $mapping $resolvedPath]=$action"
+
+        if {![catch {realpath $path} canonicalPath]
+                && $canonicalPath ne $path} {
+            lappend sndbxlst "[string map $mapping $canonicalPath]=$action"
         }
     }
 


More information about the macports-dev mailing list