summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSloane Hertel <19572925+s-hertel@users.noreply.github.com>2022-03-15 13:57:32 -0400
committerGitHub <noreply@github.com>2022-03-15 10:57:32 -0700
commitbedff70f3e3411f56f310a91a21fe80210a80f58 (patch)
tree24f38ef6e44283aa216739afbb5a9ba96e4d3f68 /lib
parenta45c4aadb8f16102ea4398f9a12eb3532b97d860 (diff)
downloadansible-bedff70f3e3411f56f310a91a21fe80210a80f58.tar.gz
[2.12] ansible-galaxy collection verify - display new files/dirs as modified content (#77128)
* 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 436436e6e1..9634f602f8 100644
--- a/lib/ansible/galaxy/collection/__init__.py
+++ b/lib/ansible/galaxy/collection/__init__.py
@@ -220,11 +220,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