diff --git a/plugins/module_utils/sap_launchpad_software_center_download_runner.py b/plugins/module_utils/sap_launchpad_software_center_download_runner.py index d4914fd..09a54df 100644 --- a/plugins/module_utils/sap_launchpad_software_center_download_runner.py +++ b/plugins/module_utils/sap_launchpad_software_center_download_runner.py @@ -313,12 +313,12 @@ def _get_valid_filename(software_found): """ # Check if Title contains filename and extension - if re.match(r'^[^/\\\0]+\.[^/\\\0]+$', software_found['Title']): - return software_found['Title'] - else: - # Check if Description contains filename and extension - if re.match(r'^[^/\\\0]+\.[^/\\\0]+$', software_found['Description']): + if re.match(r'^\d+$', software_found['Title']): + # Check if Description attribute exists and that it does not contain empty spaces + if software_found['Description'] and ' ' not in software_found['Description']: return software_found['Description'] else: - # Default to Title if Description does not help return software_found['Title'] + else: + # Default to Title if Description does not help + return software_found['Title'] diff --git a/plugins/modules/software_center_download.py b/plugins/modules/software_center_download.py index 5b909e8..9ec4e0f 100644 --- a/plugins/modules/software_center_download.py +++ b/plugins/modules/software_center_download.py @@ -128,9 +128,15 @@ def _check_similar_files(dest, filename): bool: True if similar files exist, False otherwise. filename_similar_names: A list of similar filenames if they exist, empty list otherwise. """ - # pattern = dest + '/**/' + os.path.splitext(filename)[0] - filename_base = os.path.splitext(filename)[0] - filename_pattern = os.path.join(dest, "**", filename_base) + + # Check if filename has has extension and remove it for search + if os.path.splitext(filename)[1]: + filename_base = os.path.splitext(filename)[0] + filename_pattern = os.path.join(dest, "**", filename_base + ".*") + else: + filename_pattern = os.path.join(dest, "**", filename + ".*") + + # Find all similar files in dest and sub-folders. filename_similar = glob.glob(filename_pattern, recursive=True) if filename_similar: @@ -217,7 +223,7 @@ def run_module(): else: # Exact file not found, search for similar files with pattern filename_similar_exists, filename_similar_names = _check_similar_files(dest, filename) - if filename_similar_exists and not (query and search_alternatives): + if filename_similar_exists: result['skipped'] = True result['msg'] = f"Similar file(s) already exist: {', '.join(filename_similar_names)}" module.exit_json(**result)