[35647] trunk/base/src/macports1.0/macports.tcl

raimue at macports.org raimue at macports.org
Tue Apr 1 06:09:48 PDT 2008


Revision: 35647
          http://trac.macosforge.org/projects/macports/changeset/35647
Author:   raimue at macports.org
Date:     2008-04-01 06:09:48 -0700 (Tue, 01 Apr 2008)

Log Message:
-----------
macports1.0/macports.tcl:
Implement fetching of daily snapshot tarballs as an alternative to rsync.
Just add the following line to sources.conf instead of rsync:
http://macports.org/files/ports.tar.gz

Modified Paths:
--------------
    trunk/base/src/macports1.0/macports.tcl

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2008-04-01 13:03:47 UTC (rev 35646)
+++ trunk/base/src/macports1.0/macports.tcl	2008-04-01 13:09:48 UTC (rev 35647)
@@ -1285,10 +1285,37 @@
 
 proc macports::getsourcepath {url} {
     global macports::portdbpath
+
     set source_path [split $url ://]
+
+    if {[_source_is_snapshot $url]} {
+        # daily snapshot tarball
+        return [file join $portdbpath sources [join [lrange $source_path 3 end-1] /] ports]
+    }
+
     return [file join $portdbpath sources [lindex $source_path 3] [lindex $source_path 4] [lindex $source_path 5]]
 }
 
+##
+# Checks whether a supplied source URL is for a daily snapshot tarball
+# (private)
+#
+# @param url source URL to check
+# @return a list containing filename and extension or an empty list
+proc _source_is_snapshot {url {filename ""} {extension ""}} {
+    upvar $filename myfilename
+    upvar $extension myextension
+
+    if {[regexp {^(?:https?|ftp)://.+/(.+\.(tar\.gz|tar\.bz2))$} $url -> f e]} {
+        set myfilename $f
+        set myextension $e
+
+        return 1
+    }
+
+    return 0
+}
+
 proc macports::getportbuildpath {id} {
     global macports::portdbpath
     regsub {://} $id {.} port_path
@@ -1323,6 +1350,7 @@
 
 proc mportsync {} {
     global macports::sources macports::portdbpath macports::rsync_options tcl_platform
+    global macports::portverbose
     global macports::autoconf::rsync_path 
     
     set numfailed 0
@@ -1385,9 +1413,52 @@
                 }
             }
             {^https?$|^ftp$} {
-                set indexfile [macports::getindex $source]
-                file mkdir [file dirname $indexfile]
-                exec curl -L -s -S -o $indexfile $source/PortIndex
+                if {[_source_is_snapshot $source filename extension]} {
+                    # sync a daily port snapshot tarball
+                    set indexfile [macports::getindex $source]
+                    set destdir [file dirname $indexfile]
+                    set tarpath [file join [file normalize [file join $destdir ..]] $filename]
+
+                    file mkdir [file dirname $indexfile]
+
+                    set verboseflag {}
+                    if {$macports::portverbose == "yes"} {
+                        set verboseflag "-v"
+                    }
+
+                    if {[catch {eval curl fetch $verboseflag {$source} {$tarpath}} error]} {
+                        ui_error "Fetching $source failed ($error)"
+                        incr numfailed
+                        continue
+                    }
+
+                    set extflag {}
+                    switch $extension {
+                        {tar.gz} {
+                            set extflag "-z"
+                        }
+                        {tar.bz2} {
+                            set extflag "-j"
+                        }
+                    }
+
+                    if { [catch { system "cd $destdir/.. && tar ${verboseflag} ${extflag} -xf $filename" } error] } {
+                        ui_error "Extracting $source failed ($error)"
+                        incr numfailed
+                        continue
+                    }
+
+                    if {[catch {system "chmod -R a+r \"$destdir\""}]} {
+                        ui_warn "Setting world read permissions on parts of the ports tree failed, need root?"
+                    }
+
+                    file delete $tarpath
+                } else {
+                    # sync just a PortIndex file
+                    set indexfile [macports::getindex $source]
+                    file mkdir [file dirname $indexfile]
+                    exec curl -L -s -S -o $indexfile $source/PortIndex
+                }
             }
             default {
                 ui_warn "Unknown synchronization protocol for $source"
@@ -1463,6 +1534,15 @@
                                     # Rsync files are local
                                     set source_url "file://[macports::getsourcepath $source]"
                                 }
+                                {^https?$|^ftp$} {
+                                    if {[_source_is_snapshot $source filename extension]} {
+                                        # daily snapshot tarball
+                                        set source_url "file://[macports::getsourcepath $source]"
+                                    } else {
+                                        # default action
+                                        set source_url $source
+                                    }
+                                }
                                 default {
                                     set source_url $source
                                 }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080401/c0c71167/attachment.html


More information about the macports-changes mailing list