@ -224,7 +224,7 @@ class CollectionRequirement:
_extract_tar_file ( collection_tar , file_name , b_collection_path , b_temp_path ,
_extract_tar_file ( collection_tar , file_name , b_collection_path , b_temp_path ,
expected_hash = file_info [ ' chksum_sha256 ' ] )
expected_hash = file_info [ ' chksum_sha256 ' ] )
else :
else :
os . makedirs ( os . path . join ( b_collection_path , to_bytes ( file_name , errors = ' surrogate_or_strict ' ) ) )
os . makedirs ( os . path . join ( b_collection_path , to_bytes ( file_name , errors = ' surrogate_or_strict ' ) ) , mode = 0o0755 )
except Exception :
except Exception :
# Ensure we don't leave the dir behind in case of a failure.
# Ensure we don't leave the dir behind in case of a failure.
shutil . rmtree ( b_collection_path )
shutil . rmtree ( b_collection_path )
@ -386,7 +386,7 @@ class CollectionRequirement:
metadata = meta , files = files , allow_pre_releases = allow_pre_release )
metadata = meta , files = files , allow_pre_releases = allow_pre_release )
@staticmethod
@staticmethod
def from_path ( b_path , force , parent = None ):
def from_path ( b_path , force , parent = None , fallback_metadata = False ):
info = { }
info = { }
for b_file_name , property_name in CollectionRequirement . _FILE_MAPPING :
for b_file_name , property_name in CollectionRequirement . _FILE_MAPPING :
b_file_path = os . path . join ( b_path , b_file_name )
b_file_path = os . path . join ( b_path , b_file_name )
@ -399,6 +399,13 @@ class CollectionRequirement:
except ValueError :
except ValueError :
raise AnsibleError ( " Collection file at ' %s ' does not contain a valid json string. "
raise AnsibleError ( " Collection file at ' %s ' does not contain a valid json string. "
% to_native ( b_file_path ) )
% to_native ( b_file_path ) )
if not info and fallback_metadata :
b_galaxy_path = os . path . join ( b_path , b ' galaxy.yml ' )
if os . path . exists ( b_galaxy_path ) :
collection_meta = _get_galaxy_yml ( b_galaxy_path )
info [ ' files_file ' ] = _build_files_manifest ( b_path , collection_meta [ ' namespace ' ] , collection_meta [ ' name ' ] ,
collection_meta [ ' build_ignore ' ] )
info [ ' manifest_file ' ] = _build_manifest ( * * collection_meta )
allow_pre_release = False
allow_pre_release = False
if ' manifest_file ' in info :
if ' manifest_file ' in info :
@ -419,8 +426,11 @@ class CollectionRequirement:
dependencies = manifest [ ' dependencies ' ]
dependencies = manifest [ ' dependencies ' ]
else :
else :
display . warning ( " Collection at ' %s ' does not have a MANIFEST.json file, cannot detect version. "
if fallback_metadata :
% to_text ( b_path ) )
warning = " Collection at ' %s ' does not have a galaxy.yml or a MANIFEST.json file, cannot detect version. "
else :
warning = " Collection at ' %s ' does not have a MANIFEST.json file, cannot detect version. "
display . warning ( warning % to_text ( b_path ) )
parent_dir , name = os . path . split ( to_text ( b_path , errors = ' surrogate_or_strict ' ) )
parent_dir , name = os . path . split ( to_text ( b_path , errors = ' surrogate_or_strict ' ) )
namespace = os . path . split ( parent_dir ) [ 1 ]
namespace = os . path . split ( parent_dir ) [ 1 ]
@ -998,7 +1008,7 @@ def _build_collection_tar(b_collection_path, b_tar_path, collection_manifest, fi
display . display ( ' Created collection for %s at %s ' % ( collection_name , to_text ( b_tar_path ) ) )
display . display ( ' Created collection for %s at %s ' % ( collection_name , to_text ( b_tar_path ) ) )
def find_existing_collections ( path ):
def find_existing_collections ( path , fallback_metadata = False ):
collections = [ ]
collections = [ ]
b_path = to_bytes ( path , errors = ' surrogate_or_strict ' )
b_path = to_bytes ( path , errors = ' surrogate_or_strict ' )
@ -1010,7 +1020,7 @@ def find_existing_collections(path):
for b_collection in os . listdir ( b_namespace_path ) :
for b_collection in os . listdir ( b_namespace_path ) :
b_collection_path = os . path . join ( b_namespace_path , b_collection )
b_collection_path = os . path . join ( b_namespace_path , b_collection )
if os . path . isdir ( b_collection_path ) :
if os . path . isdir ( b_collection_path ) :
req = CollectionRequirement . from_path ( b_collection_path , False )
req = CollectionRequirement . from_path ( b_collection_path , False , fallback_metadata = fallback_metadata )
display . vvv ( " Found installed collection %s : %s at ' %s ' " % ( to_text ( req ) , req . latest_version ,
display . vvv ( " Found installed collection %s : %s at ' %s ' " % ( to_text ( req ) , req . latest_version ,
to_text ( b_collection_path ) ) )
to_text ( b_collection_path ) ) )
collections . append ( req )
collections . append ( req )