From 75ab54ee1478560fee0587b3eb27177f76db22cf Mon Sep 17 00:00:00 2001 From: Le Libre Au Quotidien Date: Wed, 7 Jul 2021 19:36:58 +0200 Subject: [PATCH 1/2] Improve disk space left verification --- locales/en.json | 2 ++ locales/fr.json | 2 ++ src/yunohost/app.py | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/locales/en.json b/locales/en.json index 84a01dfaa..cfb9826c2 100644 --- a/locales/en.json +++ b/locales/en.json @@ -273,6 +273,8 @@ "diagnosis_sshd_config_insecure": "The SSH configuration appears to have been manually modified, and is insecure because it contains no 'AllowGroups' or 'AllowUsers' directive to limit access to authorized users.", "diagnosis_sshd_config_inconsistent": "It looks like the SSH port was manually modified in /etc/ssh/sshd_config. Since YunoHost 4.2, a new global setting 'security.ssh.port' is available to avoid manually editing the configuration.", "diagnosis_sshd_config_inconsistent_details": "Please run yunohost settings set security.ssh.port -v YOUR_SSH_PORT to define the SSH port, and check yunohost tools regen-conf ssh --dry-run --with-diff and yunohost tools regen-conf ssh --force to reset your conf to the YunoHost recommendation.", + "disk_space_not_sufficient_install": "There is not enough disk space left to install this application", + "disk_space_not_sufficient_update": "There is not enough disk space left to update this application", "domain_cannot_remove_main": "You cannot remove '{domain:s}' since it's the main domain, you first need to set another domain as the main domain using 'yunohost domain main-domain -n '; here is the list of candidate domains: {other_domains:s}", "domain_cannot_add_xmpp_upload": "You cannot add domains starting with 'xmpp-upload.'. This kind of name is reserved for the XMPP upload feature integrated in YunoHost.", "domain_cannot_remove_main_add_new_one": "You cannot remove '{domain:s}' since it's the main domain and your only domain, you need to first add another domain using 'yunohost domain add ', then set is as the main domain using 'yunohost domain main-domain -n ' and then you can remove the domain '{domain:s}' using 'yunohost domain remove {domain:s}'.'", diff --git a/locales/fr.json b/locales/fr.json index 79ae8e6e7..a6dda3efd 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -44,6 +44,8 @@ "backup_output_directory_required": "Vous devez spécifier un dossier de destination pour la sauvegarde", "backup_running_hooks": "Exécution des scripts de sauvegarde...", "custom_app_url_required": "Vous devez spécifier une URL pour mettre à jour votre application personnalisée {app:s}", + "disk_space_not_sufficient_install": "Il ne reste pas assez d'espace disque pour installer cette application", + "disk_space_not_sufficient_update": "Il ne reste pas assez d'espace disque pour mettre à jour cette application", "domain_cert_gen_failed": "Impossible de générer le certificat", "domain_created": "Le domaine a été créé", "domain_creation_failed": "Impossible de créer le domaine {domain} : {error}", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 5f001c12a..b3fea9a32 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -517,6 +517,10 @@ def app_upgrade(app=[], url=None, file=None, force=False): from yunohost.regenconf import manually_modified_files apps = app + # Check if disk space available + size = os.statvfs('/') + if (size.f_bavail * size.f_frsize) / 1024 <= 512000: + raise YunohostValidationError("disk_space_not_sufficient_update") # If no app is specified, upgrade all apps if not apps: # FIXME : not sure what's supposed to happen if there is a url and a file but no apps... @@ -875,6 +879,11 @@ def app_install( manifest, extracted_app_folder = _extract_app_from_file(app) else: raise YunohostValidationError("app_unknown") + + # Check if disk space available + size = os.statvfs('/') + if (size.f_bavail * size.f_frsize) / 1024 <= 512000: + raise YunohostValidationError("disk_space_not_sufficient_install") # Check ID if "id" not in manifest or "__" in manifest["id"]: From 6f908e9ccf77df44e0e3d85555c35693ff0478c4 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 8 Aug 2021 19:00:03 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- src/yunohost/app.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index b3fea9a32..3b611e9d3 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -518,8 +518,7 @@ def app_upgrade(app=[], url=None, file=None, force=False): apps = app # Check if disk space available - size = os.statvfs('/') - if (size.f_bavail * size.f_frsize) / 1024 <= 512000: + if free_space_in_directory("/") <= 512 * 1000 * 1000: raise YunohostValidationError("disk_space_not_sufficient_update") # If no app is specified, upgrade all apps if not apps: @@ -882,7 +881,7 @@ def app_install( # Check if disk space available size = os.statvfs('/') - if (size.f_bavail * size.f_frsize) / 1024 <= 512000: + if free_space_in_directory("/") <= 512 * 1000 * 1000: raise YunohostValidationError("disk_space_not_sufficient_install") # Check ID