From 30dbb2f218232bdca20fb257d16babed745a6151 Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Mon, 8 Jul 2024 17:14:27 +1000 Subject: [PATCH] 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. --- doc/port-selfupdate.1.txt | 8 ++++++-- src/macports1.0/selfupdate.tcl | 21 +++++++++++++++------ src/port/port.tcl | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/doc/port-selfupdate.1.txt b/doc/port-selfupdate.1.txt index d7a6bb0c5..86a145b85 100644 --- a/doc/port-selfupdate.1.txt +++ b/doc/port-selfupdate.1.txt @@ -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 diff --git a/src/macports1.0/selfupdate.tcl b/src/macports1.0/selfupdate.tcl index 7292b88dd..956049c10 100644 --- a/src/macports1.0/selfupdate.tcl +++ b/src/macports1.0/selfupdate.tcl @@ -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 diff --git a/src/port/port.tcl b/src/port/port.tcl index 793646cbf..8a9dfa29b 100755 --- a/src/port/port.tcl +++ b/src/port/port.tcl @@ -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}