From 46e388460cddf70fdbf1d4fac8f7c5d22ebd3927 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 18 Jun 2019 14:11:53 +0200 Subject: [PATCH 1/2] [fix] Backup delete should delete symlink target --- src/yunohost/backup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 20dbc8695..835b6979b 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -2319,7 +2319,14 @@ def backup_delete(name): archive_file = '%s/%s.tar.gz' % (ARCHIVES_PATH, name) info_file = "%s/%s.info.json" % (ARCHIVES_PATH, name) - for backup_file in [archive_file, info_file]: + files_to_delete = [archive_file, info_file] + + # To handle the case where archive_file is in fact a symlink + actual_archive = os.path.realpath(archive_file) + if actual_archive != archive_file: + files_to_delete.append(actual_archive) + + for backup_file in files_to_delete: try: os.remove(backup_file) except: From 9d63a067be65546f994918b368b22e741dc81f95 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 18 Jun 2019 15:41:27 +0200 Subject: [PATCH 2/2] Improve semantics as suggested by decentral1se --- src/yunohost/backup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 835b6979b..6745df865 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -2322,8 +2322,8 @@ def backup_delete(name): files_to_delete = [archive_file, info_file] # To handle the case where archive_file is in fact a symlink - actual_archive = os.path.realpath(archive_file) - if actual_archive != archive_file: + if os.islink(archive_file): + actual_archive = os.path.realpath(archive_file) files_to_delete.append(actual_archive) for backup_file in files_to_delete: