[37344] branches/gsoc08-privileges/base/src/port1.0

Rainer Müller raimue at macports.org
Mon Jun 23 13:29:23 PDT 2008


pmagrath at macports.org wrote:
> Revision: 37344
>           http://trac.macosforge.org/projects/macports/changeset/37344
> Author:   pmagrath at macports.org
> Date:     2008-06-03 15:20:38 -0700 (Tue, 03 Jun 2008)
> 
> Log Message:
> -----------
> Updates to Port API.
> 
> Modified Paths:
> --------------
>     branches/gsoc08-privileges/base/src/port1.0/portfetch.tcl
>     branches/gsoc08-privileges/base/src/port1.0/portutil.tcl
> 
> Modified: branches/gsoc08-privileges/base/src/port1.0/portfetch.tcl
> ===================================================================
> --- branches/gsoc08-privileges/base/src/port1.0/portfetch.tcl	2008-06-03 22:11:31 UTC (rev 37343)
> +++ branches/gsoc08-privileges/base/src/port1.0/portfetch.tcl	2008-06-03 22:20:38 UTC (rev 37344)
> @@ -628,6 +628,12 @@
>      global distfiles distname distpath all_dist_files dist_subdir fetch.type fetch_init_done
>      
>      if {[info exists distpath] && [info exists dist_subdir] && ![info exists fetch_init_done]} {
> +		# start gsoc08-privileges
> +    	if {![file writable $distpath]} {
> +			set distpath "/Users/[exec whoami]/.macports/[ string range $distpath 1 end ]"
> +			ui_warn "Going to use $distpath for fetch."
> +    	}
> +    	# end gsoc08-privileges

Please use an appropriate way to find the home directory of the user
here, not an hardcoded /Users.

There must be a better way to find the current user than an external
whoami. If you really need whoami, run it only once at a central place.

What happens if I run as root and this directory is not writeable? There
is no /Users/root (it would be /root) and an additional fallback is needed.

And what if ~/.macports is not writeable?

The path ~/.macports should only be listed at one central place so it is
easier to change it later or customize it.

Also, I don't think there should be a warning to the user, just a message.

>  	    set distpath ${distpath}/${dist_subdir}
>  	    set fetch_init_done yes
>      }
> 
> Modified: branches/gsoc08-privileges/base/src/port1.0/portutil.tcl
> ===================================================================
> --- branches/gsoc08-privileges/base/src/port1.0/portutil.tcl	2008-06-03 22:11:31 UTC (rev 37343)
> +++ branches/gsoc08-privileges/base/src/port1.0/portutil.tcl	2008-06-03 22:20:38 UTC (rev 37344)
> @@ -1375,11 +1375,40 @@
>  proc open_statefile {args} {
>      global workpath worksymlink place_worksymlink portname portpath ports_ignore_older
>      
> +    # start gsoc08-privileges
> +    if {![file writable $workpath] && [string first "~/.macports" $workpath] == -1} {
> +    
> +    	set userhome "/Users/[exec whoami]"

See above about the home directory.

Why are you checking workpath for "~/.macports"?

> +    	
> +        set newworkpath "$userhome/.macports/[ string range $workpath 1 end ]"
> +		set newworksymlink "$userhome/.macports/[ string range $worksymlink 1 end ]"
> +        
> +        set sourcepath [string map {"work" ""} $worksymlink] 
> +        set newsourcepath "$userhome/.macports/[ string range $sourcepath 1 end ]"
> +        
> +        if {![file exists ${sourcepath}Portfile] } {
> +			file mkdir $newsourcepath
> +			ui_debug "$newsourcepath created"
> +        	ui_debug "Going to copy: ${sourcepath}Portfile"
> +        	file copy ${sourcepath}Portfile $newsourcepath
> +        }

There are ports consisting of more than just one Portfile (e.g. vim),
you need to copy files, too.

> +        
> +        set workpath $newworkpath
> +        set worksymlink $newworksymlink
> +        
> +        ui_warn "Going to use $newworkpath for statefile."
> +    } else {	
> +    	set notroot no
> +    }
> +    # end gsoc08-privileges
> +
>      if {![file isdirectory $workpath]} {
>          file mkdir $workpath
>      }
> +    
>      # flock Portfile
>      set statefile [file join $workpath .macports.${portname}.state]

You still lock at the old place? I think this needs further investigation.

> +    
>      if {[file exists $statefile]} {
>          if {![file writable $statefile]} {
>              return -code error "$statefile is not writable - check permission on port directory"
> @@ -1394,7 +1423,8 @@
>  
>      # Create a symlink to the workpath for port authors 
>      if {[tbool place_worksymlink] && ![file isdirectory $worksymlink]} {
> -        exec ln -sf $workpath $worksymlink
> +    	#pmagrath TODO: fix this quick hack.
> +		#exec ln -sf $workpath $worksymlink
>      }
>      
>      set fd [open $statefile a+]

Sorry for coming back to this commit so late.

Rainer


More information about the macports-dev mailing list