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

jmr at macports.org jmr at macports.org
Tue Apr 20 09:39:33 PDT 2010


Revision: 66696
          http://trac.macports.org/changeset/66696
Author:   jmr at macports.org
Date:     2010-04-20 09:39:28 -0700 (Tue, 20 Apr 2010)
Log Message:
-----------
delete distfiles and build dirs in altworkpath when using sudo too

Modified Paths:
--------------
    trunk/base/src/port1.0/portclean.tcl
    trunk/base/src/port1.0/portmain.tcl

Modified: trunk/base/src/port1.0/portclean.tcl
===================================================================
--- trunk/base/src/port1.0/portclean.tcl	2010-04-20 16:27:29 UTC (rev 66695)
+++ trunk/base/src/port1.0/portclean.tcl	2010-04-20 16:39:28 UTC (rev 66696)
@@ -1,4 +1,4 @@
-# et:ts=4
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
 # portclean.tcl
 # $Id$
 #
@@ -58,8 +58,8 @@
 proc portclean::clean_main {args} {
     global UI_PREFIX
     global ports_clean_dist ports_clean_work ports_clean_archive ports_clean_logs
-    global ports_clean_all usealtworkpath 
-    global	keeplogs
+    global ports_clean_all 
+    global keeplogs
 
     if {[info exists ports_clean_all] && $ports_clean_all == "yes" || \
         [info exists ports_clean_dist] && $ports_clean_dist == "yes"} {
@@ -81,34 +81,9 @@
         clean_logs
     }
 
-    # start gsoc-08 privileges
-    if {[info exists usealtworkpath] && $usealtworkpath == "yes"} {
-        ui_info "$UI_PREFIX [format [msgcat::mc "Removing alt source directory for %s"] [option name]]"
-        clean_altsource
-    }
-    # end gsoc-08 privileges
-
     return 0
 }
 
-proc portclean::clean_altsource {args} {
-    global usealtworkpath worksymlink
-
-    set sourcepath [string map {"work" ""} $worksymlink]
-
-    if {[file isdirectory $sourcepath]} {
-        ui_debug "Removing directory: ${sourcepath}"
-        if {[catch {delete $sourcepath} result]} {
-            ui_debug "$::errorInfo"
-            ui_error "$result"
-        }
-    } else {
-        ui_debug "No alt source directory found to remove."
-    }
-
-    return 0
-}
-
 #
 # Remove the directory where the distfiles reside.
 # This is crude, but works.
@@ -126,8 +101,16 @@
                 ui_debug "$::errorInfo"
                 ui_error "$result"
             }
-            set count [expr $count + 1]
+            incr count
         }
+        if {!$usealtworkpath && [file isfile ${altprefix}${distfile}]} {
+            ui_debug "Removing file: ${altprefix}${distfile}"
+            if {[catch {delete ${altprefix}${distfile}} result]} {
+                ui_debug "$::errorInfo"
+                ui_error "$result"
+            }
+            incr count
+        }
     }
     if {$count > 0} {
         ui_debug "$count distfile(s) removed."
@@ -153,19 +136,23 @@
     # loop through directories
     set count 0
     foreach dir $dirlist {
-        if {$usealtworkpath} {
-            set distdir [file join ${altprefix}${portdbpath} distfiles $dir]
-        } else {
-            set distdir [file join ${portdbpath} distfiles $dir]
-        }
+        set distdir [file join ${portdbpath} distfiles $dir]
         if {[file isdirectory $distdir]} {
             ui_debug "Removing directory: ${distdir}"
             if {[catch {delete $distdir} result]} {
                 ui_debug "$::errorInfo"
                 ui_error "$result"
             }
-            set count [expr $count + 1]
+            incr count
         }
+        if {!$usealtworkpath && [file isdirectory ${altprefix}${distdir}]} {
+            ui_debug "Removing directory: ${altprefix}${distdir}"
+            if {[catch {delete ${altprefix}${distdir}} result]} {
+                ui_debug "$::errorInfo"
+                ui_error "$result"
+            }
+            incr count
+        }
     }
     if {$count > 0} {
         ui_debug "$count distfile directory(s) removed."
@@ -176,7 +163,7 @@
 }
 
 proc portclean::clean_work {args} {
-    global portbuildpath worksymlink
+    global portbuildpath worksymlink usealtworkpath altprefix
 
     if {[file isdirectory $portbuildpath]} {
         ui_debug "Removing directory: ${portbuildpath}"
@@ -188,6 +175,16 @@
         ui_debug "No work directory found to remove at ${portbuildpath}"
     }
 
+    if {!$usealtworkpath && [file isdirectory ${altprefix}${portbuildpath}]} {
+        ui_debug "Removing directory: ${altprefix}${portbuildpath}"
+        if {[catch {delete ${altprefix}${portbuildpath}} result]} {
+            ui_debug "$::errorInfo"
+            ui_error "$result"
+        }
+    } else {
+        ui_debug "No work directory found to remove at ${altprefix}${portbuildpath}"
+    }
+
     # Clean symlink, if necessary
     if {![catch {file type $worksymlink} result] && $result eq "link"} {
         ui_debug "Removing symlink: $worksymlink"
@@ -242,15 +239,13 @@
             set file [file tail $path]
             # Make sure file is truly a port archive file, and not
             # an accidental match with some other file that might exist.
-            if {[regexp $regexstring $file]} {
-                if {[file isfile $path]} {
-                    ui_debug "Removing archive: $path"
-                    if {[catch {delete $path} result]} {
-                        ui_debug "$::errorInfo"
-                        ui_error "$result"
-                    }
-                    set count [expr $count + 1]
+            if {[regexp $regexstring $file] && [file isfile $path]} {
+                ui_debug "Removing archive: $path"
+                if {[catch {delete $path} result]} {
+                    ui_debug "$::errorInfo"
+                    ui_error "$result"
                 }
+                incr count
             }
         }
     }

Modified: trunk/base/src/port1.0/portmain.tcl
===================================================================
--- trunk/base/src/port1.0/portmain.tcl	2010-04-20 16:27:29 UTC (rev 66695)
+++ trunk/base/src/port1.0/portmain.tcl	2010-04-20 16:39:28 UTC (rev 66696)
@@ -138,27 +138,32 @@
 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 { $euid != 0 && (([info exists workpath] && [file exists $workpath] && ![file writable $workpath]) || ([info exists portdbpath] && ![file writable [file join $portdbpath build]])) } {
+# resolve the alternate work path in ~/.macports
+proc portmain::set_altprefix {} {
+    global altprefix env euid
 
-    set username [uid_to_name [getuid]]
-
-    # 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)"
+    } elseif {$euid == 0 && [info exists env(SUDO_USER)]} {
+        set userhome [file normalize "~$env(SUDO_USER)"]
     } else {
         # the environment var isn't set, expand ~user instead
-        set userhome [file normalize "~${username}"]
+        set userhome [file normalize "~[uid_to_name [getuid]]"]
     }
 
-    # set alternative prefix global variable
     set altprefix [file join $userhome .macports]
+}
 
+# if unable to write to workpath, implies running without either root privileges
+# or a shared directory owned by the group so use ~/.macports
+portmain::set_altprefix
+if { $euid != 0 && (([info exists workpath] && [file exists $workpath] && ![file writable $workpath]) || ([info exists portdbpath] && ![file writable [file join $portdbpath build]])) } {
+
+    # set global variable indicating to other functions to use ~/.macports as well
+    set usealtworkpath yes
+
     default worksymlink {[file join ${altprefix}${portpath} work]}
     default distpath {[file join ${altprefix}${portdbpath} distfiles ${dist_subdir}]}
     set portbuildpath "${altprefix}${portbuildpath}"
@@ -170,6 +175,7 @@
     default worksymlink {[file join $portpath work]}
     default distpath {[file join $portdbpath distfiles ${dist_subdir}]}
 }
+
 # end gsoc08-privileges
 
 proc portmain::main {args} {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100420/177b778c/attachment.html>


More information about the macports-changes mailing list