[arch] improvement -> upgrade: only removing packages after downloading the required ones (when multi-threaded download is enabled)

This commit is contained in:
Vinicius Moreira
2020-08-06 14:52:46 -03:00
parent 78912d5eee
commit b68a21894e
10 changed files with 72 additions and 30 deletions

View File

@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<p align="center">
<img src="https://raw.githubusercontent.com/vinifmor/bauh/staging/pictures/releases/0.9.7/arch_install_reason.png">
</p>
- upgrade: only removing packages after downloading the required ones (when multi-threaded download is enabled)
### Fixes
- Arch

View File

@@ -769,16 +769,15 @@ class ArchManager(SoftwareManager):
return files
def _upgrade_repo_pkgs(self, pkgs: List[str], handler: ProcessHandler, root_password: str, arch_config: dict, overwrite_files: bool = False,
status_handler: TransactionStatusHandler = None, already_downloaded: bool = False, sizes: Dict[str, int] = None) -> bool:
status_handler: TransactionStatusHandler = None, skip_download: bool = False, sizes: Dict[str, int] = None, already_downloaded: int = 0) -> bool:
downloaded = 0
if not already_downloaded:
if self._should_download_packages(arch_config):
try:
downloaded = self._download_packages(pkgs, handler, root_password, sizes)
except ArchDownloadException:
return False
if not skip_download and self._should_download_packages(arch_config):
try:
downloaded = self._download_packages(pkgs, handler, root_password, sizes)
except ArchDownloadException:
return False
else:
downloaded = already_downloaded
try:
if status_handler:
@@ -823,7 +822,7 @@ class ArchManager(SoftwareManager):
root_password=root_password,
overwrite_files=True,
status_handler=output_handler,
already_downloaded=True,
skip_download=True,
arch_config=arch_config,
sizes=sizes)
else:
@@ -843,6 +842,37 @@ class ArchManager(SoftwareManager):
traceback.print_exc()
return False
def _remove_transaction_packages(self, requirements: UpgradeRequirements, handler: ProcessHandler, root_password: str) -> bool:
to_remove_names = {r.pkg.name for r in requirements.to_remove}
output_handler = TransactionStatusHandler(watcher=handler.watcher,
i18n=self.i18n,
pkgs_to_sync=0,
logger=self.logger,
pkgs_to_remove=len(to_remove_names))
output_handler.start()
try:
success = handler.handle(pacman.remove_several(pkgnames=to_remove_names, root_password=root_password, skip_checks=True),
output_handler=output_handler.handle)
if not success:
self.logger.error("Could not remove packages: {}".format(', '.join(to_remove_names)))
output_handler.stop_working()
output_handler.join()
return False
return True
except:
self.logger.error("An error occured while removing packages: {}".format(', '.join(to_remove_names)))
traceback.print_exc()
output_handler.stop_working()
output_handler.join()
return False
def _show_upgrade_download_failed(self, watcher: ProcessWatcher):
watcher.show_message(title=self.i18n['error'].capitalize(),
body=self.i18n['arch.upgrade.mthreaddownload.fail'],
type_=MessageType.ERROR)
def upgrade(self, requirements: UpgradeRequirements, root_password: str, watcher: ProcessWatcher) -> bool:
self.aur_client.clean_caches()
watcher.change_status("{}...".format(self.i18n['manage_window.status.upgrading']))
@@ -869,31 +899,32 @@ class ArchManager(SoftwareManager):
arch_config = read_config()
self._sync_databases(arch_config=arch_config, root_password=root_password, handler=handler)
if requirements.to_remove:
to_remove_names = {r.pkg.name for r in requirements.to_remove}
output_handler = TransactionStatusHandler(watcher=handler.watcher,
i18n=self.i18n,
pkgs_to_sync=0,
logger=self.logger,
pkgs_to_remove=len(to_remove_names))
output_handler.start()
try:
success = handler.handle(pacman.remove_several(to_remove_names, root_password), output_handler=output_handler.handle)
# for now if the multithreaded-download is disabled packages will be removed before the download:
multithreaded_download = self._should_download_packages(arch_config)
if not success:
self.logger.error("Could not remove packages: {}".format(', '.join(to_remove_names)))
output_handler.stop_working()
output_handler.join()
return False
except:
self.logger.error("An error occured while removing packages: {}".format(', '.join(to_remove_names)))
traceback.print_exc()
output_handler.stop_working()
output_handler.join()
if requirements.to_remove and (not repo_pkgs or not multithreaded_download):
if not self._remove_transaction_packages(requirements, handler, root_password):
return False
if repo_pkgs:
repo_pkgs_names = [p.name for p in repo_pkgs]
downloaded = -1
if requirements.to_remove and multithreaded_download: # pre-downloading all packages before removing any
try:
downloaded = self._download_packages(repo_pkgs_names, handler, root_password, pkg_sizes)
if downloaded < len(repo_pkgs_names):
self._show_upgrade_download_failed(handler.watcher)
return False
except ArchDownloadException:
self._show_upgrade_download_failed(handler.watcher)
return False
if not self._remove_transaction_packages(requirements, handler, root_password):
return False
watcher.change_status('{}...'.format(self.i18n['arch.upgrade.upgrade_repo_pkgs']))
self.logger.info("Upgrading {} repository packages: {}".format(len(repo_pkgs_names),
', '.join(repo_pkgs_names)))
@@ -902,6 +933,8 @@ class ArchManager(SoftwareManager):
handler=handler,
root_password=root_password,
arch_config=arch_config,
skip_download=downloaded >= 0,
already_downloaded=0 if downloaded < 0 else downloaded,
sizes=pkg_sizes):
return False

View File

@@ -199,6 +199,7 @@ arch.upgrade.error.conflicting_files=Some of the packages being upgraded want to
arch.upgrade.conflicting_files.proceed=Allow and continue
arch.upgrade.conflicting_files.stop=Cancel upgrading
arch.upgrade.fail=Package {} upgrade failed
arch.upgrade.mthreaddownload.fail=It was not possible to download all packages for upgrading
arch.upgrade.success=Package {} successfully upgraded
arch.upgrade.upgrade_aur_pkgs=Upgrading AUR packages
arch.upgrade.upgrade_repo_pkgs=Upgrading packages from repositories

View File

@@ -199,6 +199,7 @@ arch.upgrade.error.conflicting_files=Some of the packages being upgraded want to
arch.upgrade.conflicting_files.proceed=Allow and continue
arch.upgrade.conflicting_files.stop=Cancel upgrading
arch.upgrade.fail=Package {} upgrade failed
arch.upgrade.mthreaddownload.fail=It was not possible to download all packages for upgrading
arch.upgrade.success=Package {} successfully upgraded
arch.upgrade.upgrade_aur_pkgs=Upgrading AUR packages
arch.upgrade.upgrade_repo_pkgs=Upgrading packages from repositories

View File

@@ -199,6 +199,7 @@ arch.upgrade.error.conflicting_files=Some of the packages being upgraded want to
arch.upgrade.conflicting_files.proceed=Allow and continue
arch.upgrade.conflicting_files.stop=Cancel upgrading
arch.upgrade.fail=Package {} upgrade failed
arch.upgrade.mthreaddownload.fail=It was not possible to download all packages for upgrading
arch.upgrade.success=Package {} successfully upgraded
arch.upgrade.upgrade_aur_pkgs=Upgrading AUR packages
arch.upgrade.upgrade_repo_pkgs=Upgrading packages from repositories

View File

@@ -199,6 +199,7 @@ arch.upgrade.error.conflicting_files=Algunos de los paquetes que se están actua
arch.upgrade.conflicting_files.proceed=Permitir y continuar
arch.upgrade.conflicting_files.stop=Cancelar la actualización
arch.upgrade.fail=Falló la actualización del paquete {}
arch.upgrade.mthreaddownload.fail=No fue posible descargar todos los paquetes para actualizar
arch.upgrade.success=Paquete {} actualizado con éxito
arch.upgrade.upgrade_aur_pkgs=Actualizando paquetes de AUR
arch.upgrade.upgrade_repo_pkgs=Actualizando paquetes de repositorios

View File

@@ -199,6 +199,7 @@ arch.upgrade.error.conflicting_files=Some of the packages being upgraded want to
arch.upgrade.conflicting_files.proceed=Allow and continue
arch.upgrade.conflicting_files.stop=Cancel upgrading
arch.upgrade.fail=Package {} upgrade failed
arch.upgrade.mthreaddownload.fail=It was not possible to download all packages for upgrading
arch.upgrade.success=Package {} successfully upgraded
arch.upgrade.upgrade_aur_pkgs=Upgrading AUR packages
arch.upgrade.upgrade_repo_pkgs=Upgrading packages from repositories

View File

@@ -198,6 +198,7 @@ arch.upgrade.error.conflicting_files=Alguns dos pacotes que estão sendo atualiz
arch.upgrade.conflicting_files.proceed=Permitir e continuar
arch.upgrade.conflicting_files.stop=Cancelar atualização
arch.upgrade.fail=Atualização do pacote {} falhou
arch.upgrade.mthreaddownload.fail=Não foi possível baixar todos os pacotes para atualizar
arch.upgrade.success=Pacote {} atualizado com sucesso
arch.upgrade.upgrade_aur_pkgs=Atualizando pacotes do AUR
arch.upgrade.upgrade_repo_pkgs=Atualizando pacotes dos repositórios

View File

@@ -199,6 +199,7 @@ arch.upgrade.error.conflicting_files=Some of the packages being upgraded want to
arch.upgrade.conflicting_files.proceed=Allow and continue
arch.upgrade.conflicting_files.stop=Cancel upgrading
arch.upgrade.fail=Package {} upgrade failed
arch.upgrade.mthreaddownload.fail=It was not possible to download all packages for upgrading
arch.upgrade.success=Package {} successfully upgraded
arch.upgrade.upgrade_aur_pkgs=Upgrading AUR packages
arch.upgrade.upgrade_repo_pkgs=Upgrading packages from repositories

View File

@@ -199,6 +199,7 @@ arch.upgrade.error.conflicting_files=Some of the packages being upgraded want to
arch.upgrade.conflicting_files.proceed=Allow and continue
arch.upgrade.conflicting_files.stop=Cancel upgrading
arch.upgrade.fail={} paketi yükseltilemedi
arch.upgrade.mthreaddownload.fail=It was not possible to download all packages for upgrading
arch.upgrade.success={} paketi başarıyla yükseltildi
arch.upgrade.upgrade_aur_pkgs=AUR paketleri yükseltiliyor
arch.upgrade.upgrade_repo_pkgs=Resmi depo paketleri yükseltiliyor