mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Only do substitutions for container path conversions with resolved paths (#12313)
* Resolve paths as much as possible before doing replacements * Move unused method out of main code, test symlink
This commit is contained in:
@@ -58,17 +58,9 @@ def to_container_path(path, private_data_dir):
|
||||
"""
|
||||
if not os.path.isabs(private_data_dir):
|
||||
raise RuntimeError('The private_data_dir path must be absolute')
|
||||
if private_data_dir != path and Path(private_data_dir) not in Path(path).resolve().parents:
|
||||
raise RuntimeError(f'Cannot convert path {path} unless it is a subdir of {private_data_dir}')
|
||||
return path.replace(private_data_dir, CONTAINER_ROOT, 1)
|
||||
|
||||
|
||||
def to_host_path(path, private_data_dir):
|
||||
"""Given a path inside of the EE container, this gives the absolute path
|
||||
on the host machine within the private_data_dir
|
||||
"""
|
||||
if not os.path.isabs(private_data_dir):
|
||||
raise RuntimeError('The private_data_dir path must be absolute')
|
||||
if CONTAINER_ROOT != path and Path(CONTAINER_ROOT) not in Path(path).resolve().parents:
|
||||
raise RuntimeError(f'Cannot convert path {path} unless it is a subdir of {CONTAINER_ROOT}')
|
||||
return path.replace(CONTAINER_ROOT, private_data_dir, 1)
|
||||
# due to how tempfile.mkstemp works, we are probably passed a resolved path, but unresolved private_data_dir
|
||||
resolved_path = Path(path).resolve()
|
||||
resolved_pdd = Path(private_data_dir).resolve()
|
||||
if resolved_pdd != resolved_path and resolved_pdd not in resolved_path.parents:
|
||||
raise RuntimeError(f'Cannot convert path {resolved_path} unless it is a subdir of {resolved_pdd}')
|
||||
return str(resolved_path).replace(str(resolved_pdd), CONTAINER_ROOT, 1)
|
||||
|
||||
Reference in New Issue
Block a user