Add --rsync option for selfupdate

Forces use of rsync to download bases sources, just in case there are
unforeseen issues with http. Don't delete the base sources after
successful update with this option, since rsync updates them
incrementally.
This commit is contained in:
Joshua Root
2024-07-08 17:14:27 +10:00
parent 2cc59df311
commit 30dbb2f218
3 changed files with 22 additions and 9 deletions
+6 -2
View File
@@ -9,7 +9,7 @@ port-selfupdate - Upgrade MacPorts itself and update the port definition files.
SYNOPSIS
--------
[cmdsynopsis]
*port* [*-qvdf*] *selfupdate* [--no-sync] [--migrate]
*port* [*-qvdf*] *selfupdate* [--no-sync] [--migrate] [--rsync]
DESCRIPTION
-----------
@@ -34,6 +34,10 @@ OPTIONS
available. Contrary to *-f*, this flag will prevent downgrades. This flag is
useful when upgrading to a newer macOS major version.
*--rsync*::
Use the older rsync method for downloading the new version of MacPorts.
The default is to try HTTP(S) first, and use rsync only if that fails.
include::global-flags.txt[]
*-q*::
@@ -85,7 +89,7 @@ If *selfupdate* fails, it usually does so in one of two places: The network
connection, or the installation of the update.
Network Problems::
MacPorts uses the 'rsync' protocol to update its port tree to the latest version.
MacPorts uses the 'rsync' protocol to update its ports tree to the latest version.
This will fail if you are on a network that blocks TCP connections to the rsync
port 873. Talk to your network administrators and ask them to allow connections
to port 873 if this happens to you. Alternatively, you can just download a new
+15 -6
View File
@@ -494,7 +494,8 @@ proc selfupdate::install {source} {
proc selfupdate::cleanup_sources {mp_source_path} {
global macports::portdbpath macports::rsync_server
file delete -force $mp_source_path [file join $portdbpath sources $rsync_server]
set rsync_base_files [glob -nocomplain -directory [file join $portdbpath sources $rsync_server] base*]
file delete -force $mp_source_path {*}$rsync_base_files
}
proc selfupdate::do_sync {options presync} {
@@ -540,6 +541,7 @@ proc selfupdate::main {{options {}} {updatestatusvar {}}} {
}
ui_debug "MacPorts sources location: $mp_source_path"
set prefer_rsync [expr {[dict exists $options ports_selfupdate_rsync] && [dict get $options ports_selfupdate_rsync]}]
set rsync_fetched 0
macports_try -pass_signal {
set macports_version_new [get_current_version $mp_source_path]
@@ -583,10 +585,14 @@ proc selfupdate::main {{options {}} {updatestatusvar {}}} {
ui_msg "$ui_prefix MacPorts base is outdated, installing new version $macports_version_new"
if {!$rsync_fetched} {
macports_try -pass_signal {
set source_code [download_source $mp_source_path $macports_version_new]
} on error {eMessage} {
ui_debug "download_source failed: $eMessage"
if {!$prefer_rsync} {
macports_try -pass_signal {
set source_code [download_source $mp_source_path $macports_version_new]
} on error {eMessage} {
ui_debug "download_source failed: $eMessage"
set source_code [download_source_rsync]
}
} else {
set source_code [download_source_rsync]
}
}
@@ -596,7 +602,10 @@ proc selfupdate::main {{options {}} {updatestatusvar {}}} {
dict set updatestatus base_updated yes
}
cleanup_sources $mp_source_path
# Keep sources for future syncing if preferring rsync
if {!$prefer_rsync} {
cleanup_sources $mp_source_path
}
# Return here, port.tcl will re-execute selfupdate with the updated
# base to trigger sync and portindex with the new version
return 0
+1 -1
View File
@@ -4208,7 +4208,7 @@ set cmd_opts_array [dict create {*}{
depends description epoch exact glob homepage line
long_description maintainer maintainers name platform
platforms portdir regex revision variant variants version}
selfupdate {migrate no-sync nosync}
selfupdate {migrate no-sync nosync rsync}
space {{units 1} total}
activate {no-exec}
deactivate {no-exec}