fix: do not print file retrieval errors unless fallbacks fail
@@ -2051,6 +2051,76 @@ fn test_a_failed_refresh_is_an_error() ! {
20512051 assert se.err != ''
20522052 assert fy.err != ''
20532053 assert s.installed()!['foo']! == '1.0-1'
2054+ // no server left to fall through to: the held 404 is said, an error
2055+ said := se.of('message').filter(it['text'] or { json2.Any('') }.str().contains('failed retrieving'))
2056+ assert said.len == 1
2057+ assert said[0]['error'] or { json2.Any(false) }.bool()
2058+}
2059+
2060+// a mirror that lacks the package falls through to the next server: libalpm
2061+// tries a repo's servers in order, and a file the first one does not have
2062+// moves it on — the way a mirror that has not synced the archive yet is met.
2063+// the first server here serves the db alone, the way a lagging mirror does,
2064+// and the archive lives on the second
2065+fn test_a_mirror_without_the_package_falls_through_to_the_next() ! {
2066+ s := fake_system('fallback')!
2067+ defer { os.rmdir_all(s.tmp) or {} }
2068+ s.install_local(foo('1.0-1', 'one'))!
2069+ s.publish([foo('2.0-1', 'two')])!
2070+ // the lagging mirror: the db the primary serves, none of the archives
2071+ lag := s.path('lag')
2072+ os.mkdir_all(lag)!
2073+ os.cp(s.path('repo/core.db'), os.join_path(lag, 'core.db'))!
2074+ os.cp(s.path('repo/core.files'), os.join_path(lag, 'core.files'))!
2075+ up := s.run('', fn [s, lag] () ! {
2076+ cfg_repos = [CfgRepo{
2077+ name: 'core'
2078+ kind: 'sync'
2079+ servers: ['file://' + lag, 'file://' + s.path('repo')]
2080+ }]
2081+ upgrade(ConfigUpgrade{ noconfirm: true })!
2082+ })!
2083+ assert up.err == '', up.err
2084+ assert s.installed()!['foo']! == '2.0-1'
2085+ // the fallback is an event a frontend sees: the archive's download says
2086+ // retry, then completes
2087+ retries := up.of('download').filter(it['retry'] or { json2.Any(false) }.bool())
2088+ assert retries.len == 1
2089+ assert retries[0]['file'].str() == 'foo-2.0-1-any.pkg.tar'
2090+ // the 404 the lagging mirror got is not said: a mirror served the file
2091+ said := up.of('message').filter(it['text'] or { json2.Any('') }.str().contains('failed retrieving'))
2092+ assert said.len == 0
2093+}
2094+
2095+// --verbose says the mirror's 404 as it comes, even when the fallback finds
2096+// the file on the next mirror: the verbose log tells a run's whole story
2097+fn test_verbose_says_the_fallback_error() ! {
2098+ s := fake_system('fallbackverbose')!
2099+ defer { os.rmdir_all(s.tmp) or {} }
2100+ s.install_local(foo('1.0-1', 'one'))!
2101+ s.publish([foo('2.0-1', 'two')])!
2102+ lag := s.path('lag')
2103+ os.mkdir_all(lag)!
2104+ os.cp(s.path('repo/core.db'), os.join_path(lag, 'core.db'))!
2105+ os.cp(s.path('repo/core.files'), os.join_path(lag, 'core.files'))!
2106+ saved_verbose := verbose_flag
2107+ defer {
2108+ verbose_flag = saved_verbose
2109+ }
2110+ up := s.run('', fn [s, lag] () ! {
2111+ verbose_flag = true
2112+ cfg_repos = [CfgRepo{
2113+ name: 'core'
2114+ kind: 'sync'
2115+ servers: ['file://' + lag, 'file://' + s.path('repo')]
2116+ }]
2117+ upgrade(ConfigUpgrade{ noconfirm: true })!
2118+ })!
2119+ assert up.err == '', up.err
2120+ assert s.installed()!['foo']! == '2.0-1'
2121+ said := up.of('message').filter(it['text'] or { json2.Any('') }.str().contains('failed retrieving'))
2122+ assert said.len == 1
2123+ assert said[0]['text'].str().contains('from disk')
20542124}
20552125
20562126// check is an assertion inside a run's closure, where a failed assert would
@@ -165,6 +165,12 @@ mut:
165165 // send twice
166166 dlast map[string]DownloadSent
167167 plast ProgressEvent
168+ // dfails holds the 'failed retrieving file' lines libalpm logged for
169+ // mirrors that did not have a download: the line is logged before anyone
170+ // knows a later mirror serves the file, so it is held until the download
171+ // ends, and said only when no mirror served it. --verbose says it as it
172+ // comes
173+ dfails map[string]string
168174}
169175
170176// TransUIOptions are what a command tells its TransUI
@@ -533,6 +539,7 @@ fn cb_download(ctx voidptr, filename &u8, event alpm.DownloadEventType, data voi
533539 // and nothing was fetched, 0 a finished download, -1 an error. a
534540 // download can finish before its first progress event, so the bar
535541 // may not exist yet; only result 1 is labelled up to date
542+ ui.download_ended(name, c.result == -1)
536543 on_end := if c.result == 1 { '${name} is up to date' } else { '' }
537544 bar := ui.download_bar(name, c.total, on_end, false)
538545 bar.set(c.total)
@@ -550,6 +557,19 @@ fn (mut ui TransUI) restart_download_bar(name string) {
550557 bar.set(0)
551558}
552559
560+// download_ended releases the 'failed retrieving file' line a download held
561+// while it fell through the mirrors: a download no mirror served says its
562+// line as an error now, one a mirror served keeps it quiet
563+fn (mut ui TransUI) download_ended(name string, failed bool) {
564+ ui.mu.lock()
565+ held := ui.dfails[name] or { '' }
566+ ui.dfails.delete(name)
567+ ui.mu.unlock()
568+ if held != '' && failed {
569+ ui.alpm_said(true, held)
570+ }
571+}
572+
553573// DownloadSent is what a download last reported under --ui ipc: its percent,
554574// and when, in the monotonic clock's nanoseconds
555575struct DownloadSent {
@@ -610,6 +630,9 @@ fn ipc_download(mut ui TransUI, name string, event alpm.DownloadEventType, data
610630 }
611631 .completed {
612632 c := unsafe { &alpm.DownloadEventCompleted(data) }
633+ // the error goes out before the completed event, the order a
634+ // frontend reads a failure in
635+ ui.download_ended(name, c.result == -1)
613636 emit(DownloadEvent{
614637 file: name
615638 downloaded: c.total
@@ -814,6 +837,17 @@ fn alpm_log_line(ctx voidptr, level int, text &char) {
814837 if msg == '' {
815838 return
816839 }
840+ // a mirror that lacks a download is logged as an error before anyone
841+ // knows a later mirror serves the file: without --verbose it is held
842+ // until the download ends, and said as an error only when no mirror
843+ // served it (download_ended)
844+ if level == alpm_log_error && msg.starts_with("failed retrieving file '") && !verbose_on() {
845+ file := msg.all_after("failed retrieving file '").all_before("'")
846+ ui.mu.lock()
847+ ui.dfails[file] = msg
848+ ui.mu.unlock()
849+ return
850+ }
817851 ui.alpm_said(level == alpm_log_error, msg)
818852}
819853