module main fn upgrade(config ConfigUpgrade) ! { // a --print preview asks nothing and takes no lock, as pacman's mut ui := new_trans_ui(noconfirm: config.noconfirm || config.print_only) ui.print_only = config.print_only if !config.print_only { check_ask_db_lock(mut ui) } if config.disable_timeout { cfg_disable_timeout = true } mut handle := init_handle(ui)! defer { handle.release() or { went_on('release the alpm handle', err) } } defer { ui.stop() } defer { trans_cleanup(handle) } trans_options(config).apply(handle)! mut s := ui.spinner(text: 'getting dbs and updating em') s.start() defer { stop_spinner(mut s) } init_repos(mut handle)! if config.sync_dbs { update_repos(mut handle, false)! } else { check_sync_fresh(mut ui, mut handle)! } // a fresh one shows in either case: the set_text would land on the old // spinner's frame when the prompt above paused it, and here the old one // is finished with its work anyway stop_spinner(mut s) mut look := ui.spinner(text: 'looking for upgrades') look.start() defer { stop_spinner(mut look) } mut flags := dep_check_flag(config.nodeps, config.nodeps_level) | print_flags(config.print_only) if config.download_only { flags |= .download_only } if config.dbonly { flags |= .db_only } trans_begin(handle, flags)! // pacman's -Suu: a local package newer than the sync one goes down to it handle.sync_sysupgrade(config.downgrade || config.sysupgrade_level >= 2)! trans_prepare_checked(handle)! targets := handle.trans_get_add().pkgs() end_frame(mut ui, mut look) if targets.len == 0 { // --print's output is the list alone if !config.print_only { report('nothing to upgrade.') } return } // --print stops here: the upgrade is listed with the archive names, as // install's --print lists a transaction, and nothing is downloaded if config.print_only { if ipc_on() { mut preview := trans_listing(handle, targets, .upgrade) preview.preview = true emit(preview) return } for pkg in targets { file := pkg.get_filename() println(if file == '' { pkg.get_name() } else { file }) } return } // what the upgrade removes on the way — a replaced or conflicting // package — is listed before the question, as install lists its own removals := handle.trans_get_remove().pkgs() if removals.len > 0 { ui.show_packages('${removals.len} packages to remove:', removals) } if !trans_confirm(mut ui, handle, targets, .upgrade) { return } names := targets.map(it.get_name()) mut s2 := ui.spinner( text: if config.download_only { 'downloading the upgrades' } else { 'upgrading system' } ) s2.start() defer { stop_spinner(mut s2) } trans_commit(handle)! stop_spinner(mut s2) // a frontend learns what changed as from every transaction: a done event if ipc_on() { emit(DoneEvent{ action: if config.download_only { 'downloaded' } else { 'upgraded' } packages: names }) return } ui.say(if config.download_only { 'upgrades downloaded' } else { 'system upgraded' }) }