From f2d4187761272d0be29252099e71ac2bae0e8a03 Mon Sep 17 00:00:00 2001 From: feranwq Date: Sat, 19 Jan 2019 04:41:23 +0800 Subject: [PATCH] archive: Fix check if archive is created in path to be removed (#29420) (#49444) * archive: Fix check if archive is created in path to be removed (#29420) (cherry picked from commit 3a45de4209e47491e9c907030952cd4722bceea3) * add changelog --- ...check_if_archive_is_created_in_path_to_be_removed.yml | 2 ++ lib/ansible/modules/files/archive.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/49444_fix_check_if_archive_is_created_in_path_to_be_removed.yml diff --git a/changelogs/fragments/49444_fix_check_if_archive_is_created_in_path_to_be_removed.yml b/changelogs/fragments/49444_fix_check_if_archive_is_created_in_path_to_be_removed.yml new file mode 100644 index 00000000000..3823a7224a9 --- /dev/null +++ b/changelogs/fragments/49444_fix_check_if_archive_is_created_in_path_to_be_removed.yml @@ -0,0 +1,2 @@ +bugfixes: + - archive - Fix check if archive is created in path to be removed diff --git a/lib/ansible/modules/files/archive.py b/lib/ansible/modules/files/archive.py index b14907aa42a..b4c8c3a70d5 100644 --- a/lib/ansible/modules/files/archive.py +++ b/lib/ansible/modules/files/archive.py @@ -261,8 +261,13 @@ def main(): arcroot += os.sep # Don't allow archives to be created anywhere within paths to be removed - if remove and os.path.isdir(path) and dest.startswith(path): - module.fail_json(path=', '.join(paths), msg='Error, created archive can not be contained in source paths when remove=True') + if remove and os.path.isdir(path): + path_dir = path + if path[-1] != '/': + path_dir += '/' + + if dest.startswith(path_dir): + module.fail_json(path=', '.join(paths), msg='Error, created archive can not be contained in source paths when remove=True') if os.path.lexists(path) and path not in expanded_exclude_paths: archive_paths.append(path)