Blob Blame History Raw
From b9ee0c547797f253771489542f0f5ac08bf04bf6 Mon Sep 17 00:00:00 2001
From: Timo Benk <benk@b1-systems.de>
Date: Wed, 19 Apr 2017 20:15:20 +0200
Subject: [PATCH] fix ansible galaxy file mangling (#23703)

without this patch, ansible-galaxy will mangle files containing
the archive parent directory name, eg 'owncloud/files/owncloud.cron'
will become 'owncloud/files/.cron'.

The previous code could affect the entire path and even filenames.
If a file path has the top level dir name as a substring, galaxy
replaces it with ''. In one example, the archive top level dir
is 'go', so 'files/go-bin.sh' becomes 'files/-bin.sh'.

Fixes #22572, #23694, #23623
(cherry picked from commit 79943b86a1ee9338049149824bbb12f99d8186ee)
---
 lib/ansible/galaxy/role.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py
index 67bdc95..3b89176 100644
--- a/lib/ansible/galaxy/role.py
+++ b/lib/ansible/galaxy/role.py
@@ -316,7 +316,7 @@ def install(self):
                             # bits that might be in the file for security purposes
                             # and drop any containing directory, as mentioned above
                             if member.isreg() or member.issym():
-                                parts = member.name.replace(archive_parent_dir, "").split(os.sep)
+                                parts = member.name.replace(archive_parent_dir, "", 1).split(os.sep)
                                 final_parts = []
                                 for part in parts:
                                     if part != '..' and '~' not in part and '$' not in part: