[54706] trunk/base/src/port1.0

jmr at macports.org jmr at macports.org
Fri Jul 31 15:03:25 PDT 2009


Revision: 54706
          http://trac.macports.org/changeset/54706
Author:   jmr at macports.org
Date:     2009-07-31 15:03:23 -0700 (Fri, 31 Jul 2009)
Log Message:
-----------
Set up options for the alternate (home dir) build prefix right from the start, instead of trying to munge them later on. Should fix #20461.

Modified Paths:
--------------
    trunk/base/src/port1.0/portdestroot.tcl
    trunk/base/src/port1.0/portfetch.tcl
    trunk/base/src/port1.0/portmain.tcl
    trunk/base/src/port1.0/porttrace.tcl
    trunk/base/src/port1.0/portutil.tcl

Modified: trunk/base/src/port1.0/portdestroot.tcl
===================================================================
--- trunk/base/src/port1.0/portdestroot.tcl	2009-07-31 21:53:20 UTC (rev 54705)
+++ trunk/base/src/port1.0/portdestroot.tcl	2009-07-31 22:03:23 UTC (rev 54706)
@@ -88,7 +88,7 @@
 
 proc portdestroot::destroot_start {args} {
     global UI_PREFIX prefix name porturl destroot os.platform destroot.clean portsharepath
-    global destroot.umask destroot.asroot macportsuser euid egid usealtworkpath altprefix
+    global destroot.umask destroot.asroot macportsuser euid egid
     global applications_dir frameworks_dir
     variable oldmask
 
@@ -109,14 +109,6 @@
         return -code error "You cannot run this port without root privileges. You need to re-run with 'sudo port'.";
     }
 
-    if {[info exists usealtworkpath] && $usealtworkpath == "yes"} {
-        # rewrite destroot.args
-        set argprefix "=[option prefix]"
-        set newargprefix "=${altprefix}[option prefix]"
-        set newdestrootargs [string map [list $argprefix $newargprefix] [option destroot.args]]
-        option destroot.args $newdestrootargs
-    }
-
     # end gsoc08-privileges
 
     set oldmask [umask ${destroot.umask}]

Modified: trunk/base/src/port1.0/portfetch.tcl
===================================================================
--- trunk/base/src/port1.0/portfetch.tcl	2009-07-31 21:53:20 UTC (rev 54705)
+++ trunk/base/src/port1.0/portfetch.tcl	2009-07-31 22:03:23 UTC (rev 54706)
@@ -704,19 +704,9 @@
 # Initialize fetch target and call checkfiles.
 proc portfetch::fetch_init {args} {
     global distfiles distname distpath all_dist_files dist_subdir fetch.type fetch_init_done
-    global altprefix usealtworkpath
     variable fetch_urls
 
     if {[info exists distpath] && [info exists dist_subdir] && ![info exists fetch_init_done]} {
-
-        # start gsoc08-privileges
-        if {[info exists usealtworkpath] && $usealtworkpath == "yes"} {
-            # I have removed ![file writable $distpath] from the if condition as
-            # the writable condition seems to get confused by effective uids.
-            set distpath "$altprefix/[ string range $distpath 1 end ]"
-            ui_debug "Going to use $distpath for fetch."
-        }
-        # end gsoc08-privileges
         set distpath ${distpath}/${dist_subdir}
         set fetch_init_done yes
     }

Modified: trunk/base/src/port1.0/portmain.tcl
===================================================================
--- trunk/base/src/port1.0/portmain.tcl	2009-07-31 21:53:20 UTC (rev 54705)
+++ trunk/base/src/port1.0/portmain.tcl	2009-07-31 22:03:23 UTC (rev 54706)
@@ -56,9 +56,7 @@
 # Assign option procedure to default_variants
 option_proc default_variants handle_default_variants
 
-default distpath {[file join $portdbpath distfiles]}
 default workpath {[getportworkpath_from_buildpath $portbuildpath]}
-default worksymlink {[file join $portpath work]}
 default prefix /opt/local
 default applications_dir /Applications/MacPorts
 default frameworks_dir {${prefix}/Library/Frameworks}
@@ -128,10 +126,53 @@
     option os.universal_supported yes
 }
 
+# start gsoc08-privileges
+
 # Record initial euid/egid
 set euid [geteuid]
 set egid [getegid]
 
+# if unable to write to workpath, implies running without either root privileges
+# or a shared directory owned by the group so use ~/.macports
+if { ([info exists workpath] && [file exists $workpath] && ![file writable $workpath]) || [info exists portbuildpath] && ![file writable $portbuildpath] } {
+
+    set userid [getuid]
+    set username [uid_to_name $userid]
+
+    if { $userid !=0 } {
+        ui_msg "MacPorts running without privileges.\
+                You may be unable to complete certain actions (eg install)."
+    }
+
+    # set global variable indicating to other functions to use ~/.macports as well
+    set usealtworkpath yes
+
+    # do tilde expansion manually - Tcl won't expand tildes automatically for curl, etc.
+    if {[info exists env(HOME)]} {
+        # HOME environment var is set, use it.
+        set userhome "$env(HOME)"
+    } else {
+        # the environment var isn't set, expand ~user instead
+        set userhome [file normalize "~${username}"]
+    }
+
+    # set alternative prefix global variable
+    set altprefix [file join $userhome .macports]
+
+    default worksymlink {[file join ${altprefix}${portpath} work]}
+    default distpath {[file join ${altprefix}${portdbpath} distfiles]}
+    set portbuildpath "${altprefix}${portbuildpath}"
+
+    ui_debug "Going to use alternate build prefix: $altprefix"
+    ui_debug "portbuildpath = $portbuildpath"
+    ui_debug "workpath = $workpath"
+} else {
+    set usealtworkpath no
+    default worksymlink {[file join $portpath work]}
+    default distpath {[file join $portdbpath distfiles]}
+}
+# end gsoc08-privileges
+
 proc portmain::main {args} {
     return 0
 }

Modified: trunk/base/src/port1.0/porttrace.tcl
===================================================================
--- trunk/base/src/port1.0/porttrace.tcl	2009-07-31 21:53:20 UTC (rev 54705)
+++ trunk/base/src/port1.0/porttrace.tcl	2009-07-31 22:03:23 UTC (rev 54706)
@@ -44,7 +44,7 @@
         if {[catch {package require Thread} error]} {
             ui_warn "trace requires Tcl Thread package ($error)"
         } else {
-            global env trace_fifo trace_sandboxbounds portpath distpath
+            global env trace_fifo trace_sandboxbounds portpath distpath altprefix
             # Create a fifo.
             # path in unix socket limited to 109 chars
             # # set trace_fifo "$workpath/trace_fifo"

Modified: trunk/base/src/port1.0/portutil.tcl
===================================================================
--- trunk/base/src/port1.0/portutil.tcl	2009-07-31 21:53:20 UTC (rev 54705)
+++ trunk/base/src/port1.0/portutil.tcl	2009-07-31 22:03:23 UTC (rev 54706)
@@ -1497,83 +1497,35 @@
 # open file to store name of completed targets
 proc open_statefile {args} {
     global workpath worksymlink place_worksymlink name portpath ports_ignore_older
-    global altprefix usealtworkpath env applications_dir portbuildpath distpath
+    global usealtworkpath altprefix env applications_dir
 
-    # start gsoc08-privileges
-    if { ![file exists $workpath] } {
-        if {[catch {set result [file mkdir $workpath]} result]} {
-            global errorInfo
-            ui_debug "mkdir $workpath: $errorInfo"
-        }
+    if {![file isdirectory $workpath]} {
+        file mkdir $workpath
+        chownAsRoot $workpath
     }
-
-    # if unable to write to workpath, implies running without either root privileges
-    # or a shared directory owned by the group so use ~/.macports
-    if { ![file writable $workpath] } {
-
-        set userid [getuid]
-        set username [uid_to_name $userid]
-
-        if { $userid !=0 } {
-            ui_msg "MacPorts running without privileges.\
-                    You may be unable to complete certain actions (eg install)."
-        }
-
-        # set global variable indicating to other functions to use ~/.macports as well
-        set usealtworkpath yes
-
-        # do tilde expansion manually - tcl won't expand tildes automatically for curl, etc.
-        if {[info exists env(HOME)]} {
-            # HOME environment var is set, use it.
-            set userhome "$env(HOME)"
-        } else {
-            # the environment var isn't set, expand ~user instead
-            set userhome [file normalize "~${username}"]
-        }
-
-        # set alternative prefix global variables
-        set altprefix "$userhome/.macports"
-
-        # get alternative paths
-        set newworkpath "$altprefix$workpath"
-        set newworksymlink "$altprefix$worksymlink"
-        set newportbuildpath "$altprefix$portbuildpath"
-        set newdistpath "$altprefix$distpath"
-
-        set sourcepath [string map {"work" ""} $worksymlink]
-        set newsourcepath "$altprefix/[ string range $sourcepath 1 end ]"
-
+    # de-escalate privileges if MacPorts was started with sudo
+    dropPrivileges
+    
+    if {$usealtworkpath} {
+        set newsourcepath "$altprefix/$portpath"
+    
         # copy Portfile (and patch files) if not there already
         # note to maintainers/devs: the original portfile in /opt/local is ALWAYS the one that will be
         #    read by macports. The copying of the portfile is done to preserve the symlink provided
         #    historically by macports from the portfile directory to the work directory.
         #    It is NOT read by MacPorts.
-        if {![file exists ${newsourcepath}Portfile] } {
+        if {![file exists ${newsourcepath}/Portfile] } {
             file mkdir $newsourcepath
             ui_debug "$newsourcepath created"
-            ui_debug "Going to copy: ${sourcepath}Portfile"
-            file copy ${sourcepath}Portfile $newsourcepath
-            if {[file exists ${sourcepath}files] } {
-                ui_debug "Going to copy: ${sourcepath}files"
-                file copy ${sourcepath}files $newsourcepath
+            ui_debug "Going to copy: ${portpath}/Portfile"
+            file copy ${portpath}/Portfile $newsourcepath
+            if {[file exists ${portpath}/files] } {
+                ui_debug "Going to copy: ${portpath}/files"
+                file copy ${portpath}/files $newsourcepath
             }
         }
-
-        set workpath $newworkpath
-        set worksymlink $newworksymlink
-        set portbuildpath $newportbuildpath
-        set distpath $newdistpath
-
-        ui_debug "Going to use $newworkpath for statefile."
-    } else {
-        set usealtworkpath no
     }
-    # end gsoc08-privileges
 
-    if {![file isdirectory $workpath]} {
-        file mkdir $workpath
-    }
-
     # flock Portfile
     set statefile [file join $workpath .macports.${name}.state]
     if {[file exists $statefile]} {
@@ -1583,22 +1535,18 @@
         if {!([info exists ports_ignore_older] && $ports_ignore_older == "yes") && [file mtime $statefile] < [file mtime ${portpath}/Portfile]} {
             if {!([info exists ports_dryrun] && $ports_dryrun == "yes")} {
                 ui_msg "Portfile changed since last build; discarding previous state."
-                delete [file join $workpath]
-                file mkdir [file join $workpath]
+                eval delete [glob -nocomplain -directory -- $workpath * .*]
             } else {
                 ui_msg "Portfile changed since last build but not discarding previous state (dry run)"
             }
         }
     }
-    chownAsRoot $workpath
 
     # Create a symlink to the workpath for port authors
     if {[tbool place_worksymlink] && ![file isdirectory $worksymlink]} {
         ui_debug "Attempting ln -sf $workpath $worksymlink"
         ln -sf $workpath $worksymlink
     }
-    # de-escalate privileges - only run if MacPorts was started with sudo
-    dropPrivileges
 
     set fd [open $statefile a+]
     if {[catch {flock $fd -exclusive -noblock} result]} {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090731/03ee2695/attachment.html>


More information about the macports-changes mailing list