summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSloane Hertel <19572925+s-hertel@users.noreply.github.com>2022-03-15 14:09:59 -0400
committerGitHub <noreply@github.com>2022-03-15 11:09:59 -0700
commitca8835c99029e6cbbb64a5510e6b03a943ba1697 (patch)
tree2d628c6eec2ece604ad135d97d468521d6a98dfb /lib
parentef46bc46f459cf702f098d64b37c74cf0557ebd7 (diff)
downloadansible-ca8835c99029e6cbbb64a5510e6b03a943ba1697.tar.gz
[2.11] ansible-galaxy collection verify - display new files/dirs as modified content (#77129)
* Fix 'ansible-galaxy collection verify' to report files/directories not listed in the FILES.json (cherry picked from commit a1d467dbb21e00cdb0ed38baf0e43e583185dc59) * changelog (cherry picked from commit 3d49d6f69ec1afa2234a21a1f9cd273d55cb6597)
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/galaxy/collection/__init__.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/ansible/galaxy/collection/__init__.py b/lib/ansible/galaxy/collection/__init__.py
index 0feb0fe637..8318f49297 100644
--- a/lib/ansible/galaxy/collection/__init__.py
+++ b/lib/ansible/galaxy/collection/__init__.py
@@ -219,11 +219,46 @@ def verify_local_collection(
_verify_file_hash(b_collection_path, file_manifest_filename, expected_hash, modified_content)
file_manifest = get_json_from_validation_source(file_manifest_filename)
+ collection_dirs = set()
+ collection_files = {
+ os.path.join(b_collection_path, b'MANIFEST.json'),
+ os.path.join(b_collection_path, b'FILES.json'),
+ }
+
# Use the file manifest to verify individual file checksums
for manifest_data in file_manifest['files']:
+ name = manifest_data['name']
+
if manifest_data['ftype'] == 'file':
+ collection_files.add(
+ os.path.join(b_collection_path, to_bytes(name, errors='surrogate_or_strict'))
+ )
expected_hash = manifest_data['chksum_%s' % manifest_data['chksum_type']]
- _verify_file_hash(b_collection_path, manifest_data['name'], expected_hash, modified_content)
+ _verify_file_hash(b_collection_path, name, expected_hash, modified_content)
+
+ if manifest_data['ftype'] == 'dir':
+ collection_dirs.add(
+ os.path.join(b_collection_path, to_bytes(name, errors='surrogate_or_strict'))
+ )
+
+ # Find any paths not in the FILES.json
+ for root, dirs, files in os.walk(b_collection_path):
+ for name in files:
+ full_path = os.path.join(root, name)
+ path = to_text(full_path[len(b_collection_path) + 1::], errors='surrogate_or_strict')
+
+ if full_path not in collection_files:
+ modified_content.append(
+ ModifiedContent(filename=path, expected='the file does not exist', installed='the file exists')
+ )
+ for name in dirs:
+ full_path = os.path.join(root, name)
+ path = to_text(full_path[len(b_collection_path) + 1::], errors='surrogate_or_strict')
+
+ if full_path not in collection_dirs:
+ modified_content.append(
+ ModifiedContent(filename=path, expected='the directory does not exist', installed='the directory exists')
+ )
if modified_content:
result.success = False