Changeset 66696


Ignore:
Timestamp:
Apr 20, 2010, 4:39:28 PM (10 years ago)
Author:
jmr@…
Message:

delete distfiles and build dirs in altworkpath when using sudo too

Location:
trunk/base/src/port1.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/portclean.tcl

    r66694 r66696  
    1 # et:ts=4
     1# -*- 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
    22# portclean.tcl
    33# $Id$
     
    5959    global UI_PREFIX
    6060    global ports_clean_dist ports_clean_work ports_clean_archive ports_clean_logs
    61     global ports_clean_all usealtworkpath
    62     global      keeplogs
     61    global ports_clean_all
     62    global keeplogs
    6363
    6464    if {[info exists ports_clean_all] && $ports_clean_all == "yes" || \
     
    8080    if {([info exists ports_clean_logs] && $ports_clean_logs == "yes") || ($keeplogs == "no")} {
    8181        clean_logs
    82     }
    83 
    84     # start gsoc-08 privileges
    85     if {[info exists usealtworkpath] && $usealtworkpath == "yes"} {
    86         ui_info "$UI_PREFIX [format [msgcat::mc "Removing alt source directory for %s"] [option name]]"
    87         clean_altsource
    88     }
    89     # end gsoc-08 privileges
    90 
    91     return 0
    92 }
    93 
    94 proc portclean::clean_altsource {args} {
    95     global usealtworkpath worksymlink
    96 
    97     set sourcepath [string map {"work" ""} $worksymlink]
    98 
    99     if {[file isdirectory $sourcepath]} {
    100         ui_debug "Removing directory: ${sourcepath}"
    101         if {[catch {delete $sourcepath} result]} {
    102             ui_debug "$::errorInfo"
    103             ui_error "$result"
    104         }
    105     } else {
    106         ui_debug "No alt source directory found to remove."
    10782    }
    10883
     
    127102                ui_error "$result"
    128103            }
    129             set count [expr $count + 1]
     104            incr count
     105        }
     106        if {!$usealtworkpath && [file isfile ${altprefix}${distfile}]} {
     107            ui_debug "Removing file: ${altprefix}${distfile}"
     108            if {[catch {delete ${altprefix}${distfile}} result]} {
     109                ui_debug "$::errorInfo"
     110                ui_error "$result"
     111            }
     112            incr count
    130113        }
    131114    }
     
    154137    set count 0
    155138    foreach dir $dirlist {
    156         if {$usealtworkpath} {
    157             set distdir [file join ${altprefix}${portdbpath} distfiles $dir]
    158         } else {
    159             set distdir [file join ${portdbpath} distfiles $dir]
    160         }
     139        set distdir [file join ${portdbpath} distfiles $dir]
    161140        if {[file isdirectory $distdir]} {
    162141            ui_debug "Removing directory: ${distdir}"
     
    165144                ui_error "$result"
    166145            }
    167             set count [expr $count + 1]
     146            incr count
     147        }
     148        if {!$usealtworkpath && [file isdirectory ${altprefix}${distdir}]} {
     149            ui_debug "Removing directory: ${altprefix}${distdir}"
     150            if {[catch {delete ${altprefix}${distdir}} result]} {
     151                ui_debug "$::errorInfo"
     152                ui_error "$result"
     153            }
     154            incr count
    168155        }
    169156    }
     
    177164
    178165proc portclean::clean_work {args} {
    179     global portbuildpath worksymlink
     166    global portbuildpath worksymlink usealtworkpath altprefix
    180167
    181168    if {[file isdirectory $portbuildpath]} {
     
    187174    } else {
    188175        ui_debug "No work directory found to remove at ${portbuildpath}"
     176    }
     177
     178    if {!$usealtworkpath && [file isdirectory ${altprefix}${portbuildpath}]} {
     179        ui_debug "Removing directory: ${altprefix}${portbuildpath}"
     180        if {[catch {delete ${altprefix}${portbuildpath}} result]} {
     181            ui_debug "$::errorInfo"
     182            ui_error "$result"
     183        }
     184    } else {
     185        ui_debug "No work directory found to remove at ${altprefix}${portbuildpath}"
    189186    }
    190187
     
    243240            # Make sure file is truly a port archive file, and not
    244241            # an accidental match with some other file that might exist.
    245             if {[regexp $regexstring $file]} {
    246                 if {[file isfile $path]} {
    247                     ui_debug "Removing archive: $path"
    248                     if {[catch {delete $path} result]} {
    249                         ui_debug "$::errorInfo"
    250                         ui_error "$result"
    251                     }
    252                     set count [expr $count + 1]
     242            if {[regexp $regexstring $file] && [file isfile $path]} {
     243                ui_debug "Removing archive: $path"
     244                if {[catch {delete $path} result]} {
     245                    ui_debug "$::errorInfo"
     246                    ui_error "$result"
    253247                }
     248                incr count
    254249            }
    255250        }
  • trunk/base/src/port1.0/portmain.tcl

    r66694 r66696  
    139139set egid [getegid]
    140140
    141 # if unable to write to workpath, implies running without either root privileges
    142 # or a shared directory owned by the group so use ~/.macports
    143 if { $euid != 0 && (([info exists workpath] && [file exists $workpath] && ![file writable $workpath]) || ([info exists portdbpath] && ![file writable [file join $portdbpath build]])) } {
    144 
    145     set username [uid_to_name [getuid]]
    146 
    147     # set global variable indicating to other functions to use ~/.macports as well
    148     set usealtworkpath yes
     141# resolve the alternate work path in ~/.macports
     142proc portmain::set_altprefix {} {
     143    global altprefix env euid
    149144
    150145    # do tilde expansion manually - Tcl won't expand tildes automatically for curl, etc.
     
    152147        # HOME environment var is set, use it.
    153148        set userhome "$env(HOME)"
     149    } elseif {$euid == 0 && [info exists env(SUDO_USER)]} {
     150        set userhome [file normalize "~$env(SUDO_USER)"]
    154151    } else {
    155152        # the environment var isn't set, expand ~user instead
    156         set userhome [file normalize "~${username}"]
     153        set userhome [file normalize "~[uid_to_name [getuid]]"]
    157154    }
    158155
    159     # set alternative prefix global variable
    160156    set altprefix [file join $userhome .macports]
     157}
     158
     159# if unable to write to workpath, implies running without either root privileges
     160# or a shared directory owned by the group so use ~/.macports
     161portmain::set_altprefix
     162if { $euid != 0 && (([info exists workpath] && [file exists $workpath] && ![file writable $workpath]) || ([info exists portdbpath] && ![file writable [file join $portdbpath build]])) } {
     163
     164    # set global variable indicating to other functions to use ~/.macports as well
     165    set usealtworkpath yes
    161166
    162167    default worksymlink {[file join ${altprefix}${portpath} work]}
     
    171176    default distpath {[file join $portdbpath distfiles ${dist_subdir}]}
    172177}
     178
    173179# end gsoc08-privileges
    174180
Note: See TracChangeset for help on using the changeset viewer.