From 50af0393d1e06a888d7a39ab71635835b4fe3a88 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 20 Apr 2021 20:21:37 +0200 Subject: [PATCH] Fix a stupid issue where an app's tmp work dir would be deleted during upgrade because of the backup process --- src/yunohost/app.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index e0e8f7b14..c048ca5ea 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -3360,9 +3360,21 @@ def _make_tmp_workdir_for_app(app=None): if not os.path.exists(APP_TMP_WORKDIRS): os.makedirs(APP_TMP_WORKDIRS) - # Cleanup old dirs + now = int(time.time()) + + # Cleanup old dirs (if any) for dir_ in os.listdir(APP_TMP_WORKDIRS): - shutil.rmtree(os.path.join(APP_TMP_WORKDIRS, dir_)) + path = os.path.join(APP_TMP_WORKDIRS, dir_) + # We only delete folders older than an arbitary 12 hours + # This is to cover the stupid case of upgrades + # Where many app will call 'yunohost backup create' + # from the upgrade script itself, + # which will also call this function while the upgrade + # script itself is running in one of those dir... + # It could be that there are other edge cases + # such as app-install-during-app-install + if os.stat(path).st_mtime < now - 12 * 3600: + shutil.rmtree(path) tmpdir = tempfile.mkdtemp(prefix="app_", dir=APP_TMP_WORKDIRS) # Copy existing app scripts, conf, ... if an app arg was provided