diff --git a/locales/en.json b/locales/en.json index ca766d642..901d36574 100644 --- a/locales/en.json +++ b/locales/en.json @@ -157,6 +157,7 @@ "diagnosis_monitor_system_error": "Can't monitor system: {error}", "diagnosis_no_apps": "No installed application", "dpkg_is_broken": "You cannot do this right now because dpkg/apt (the system package managers) seems to be in a broken state... You can try to solve this issue by connecting through SSH and running `sudo dpkg --configure -a`.", + "dpkg_lock_not_available": "This command can't be ran right now because another program seems to be using the lock of dpkg (the system package manager)", "dnsmasq_isnt_installed": "dnsmasq does not seem to be installed, please run 'apt-get remove bind9 && apt-get install dnsmasq'", "domain_cannot_remove_main": "Cannot remove main domain. Set a new main domain first", "domain_cert_gen_failed": "Unable to generate certificate", diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 3bb69c961..b0ed1c449 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -553,6 +553,10 @@ def tools_upgrade(operation_logger, apps=None, system=False): if packages.dpkg_is_broken(): raise YunohostError("dpkg_is_broken") + # Check for obvious conflict with other dpkg/apt commands already running in parallel + if not packages.dpkg_lock_available(): + raise YunohostError("dpkg_lock_not_available") + if system is not False and apps is not None: raise YunohostError("tools_upgrade_cant_both") diff --git a/src/yunohost/utils/packages.py b/src/yunohost/utils/packages.py index b564d2dea..84901bbff 100644 --- a/src/yunohost/utils/packages.py +++ b/src/yunohost/utils/packages.py @@ -482,6 +482,8 @@ def dpkg_is_broken(): return any(re.match("^[0-9]+$", f) for f in os.listdir("/var/lib/dpkg/updates/")) +def dpkg_lock_available(): + return os.system("lsof /var/lib/dpkg/lock >/dev/null") != 0 def _list_upgradable_apt_packages():