Skip to content

Commit

Permalink
galaxy: raise error when inaccessible path is specified multiple times (
Browse files Browse the repository at this point in the history
#76318)

Fixes #76316
  • Loading branch information
mkrizek committed Nov 22, 2021
1 parent 0ddaf6e commit f59d045
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
@@ -0,0 +1,2 @@
bugfixes:
- "ansible-galaxy - when installing a role properly raise an error when inaccessible path is specified multiple times in roles_path (e.g. via environment variable and command line option) (https://github.com/ansible/ansible/issues/76316)"
32 changes: 16 additions & 16 deletions lib/ansible/galaxy/role.py
Expand Up @@ -85,7 +85,7 @@ def __init__(self, galaxy, api, name, src=None, version=None, scm=None, path=Non
self.path = path
else:
# use the first path by default
self.path = os.path.join(galaxy.roles_paths[0], self.name)
self.path = self.paths[0]

def __repr__(self):
"""
Expand Down Expand Up @@ -308,11 +308,14 @@ def install(self):
except Exception:
raise AnsibleError("this role does not appear to have a valid meta/main.yml file.")

# we strip off any higher-level directories for all of the files contained within
# the tar file here. The default is 'github_repo-target'. Gerrit instances, on the other
# hand, does not have a parent directory at all.
installed = False
while not installed:
paths = self.paths
if self.path != paths[0]:
# path can be passed though __init__
# FIXME should this be done in __init__?
paths[:0] = self.path
paths_len = len(paths)
for idx, path in enumerate(paths):
self.path = path
display.display("- extracting %s to %s" % (self.name, self.path))
try:
if os.path.exists(self.path):
Expand All @@ -328,7 +331,9 @@ def install(self):
else:
os.makedirs(self.path)

# now we do the actual extraction to the path
# We strip off any higher-level directories for all of the files
# contained within the tar file here. The default is 'github_repo-target'.
# Gerrit instances, on the other hand, does not have a parent directory at all.
for member in members:
# we only extract files, and remove any relative path
# bits that might be in the file for security purposes
Expand All @@ -350,16 +355,11 @@ def install(self):

# write out the install info file for later use
self._write_galaxy_install_info()
installed = True
break
except OSError as e:
error = True
if e.errno == errno.EACCES and len(self.paths) > 1:
current = self.paths.index(self.path)
if len(self.paths) > current:
self.path = self.paths[current + 1]
error = False
if error:
raise AnsibleError("Could not update files in %s: %s" % (self.path, to_native(e)))
if e.errno == errno.EACCES and idx < paths_len - 1:
continue
raise AnsibleError("Could not update files in %s: %s" % (self.path, to_native(e)))

# return the parsed yaml metadata
display.display("- %s was installed successfully" % str(self))
Expand Down

0 comments on commit f59d045

Please sign in to comment.