Skip to content

Commit 190190e

Browse files
committed
improved logic for skipping and getting valid filename
1 parent 5fd8038 commit 190190e

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

plugins/module_utils/sap_launchpad_software_center_download_runner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,12 @@ def _get_valid_filename(software_found):
313313
"""
314314

315315
# Check if Title contains filename and extension
316-
if re.match(r'^[^/\\\0]+\.[^/\\\0]+$', software_found['Title']):
317-
return software_found['Title']
318-
else:
319-
# Check if Description contains filename and extension
320-
if re.match(r'^[^/\\\0]+\.[^/\\\0]+$', software_found['Description']):
316+
if re.match(r'^\d+$', software_found['Title']):
317+
# Check if Description attribute exists and that it does not contain empty spaces
318+
if software_found['Description'] and ' ' not in software_found['Description']:
321319
return software_found['Description']
322320
else:
323-
# Default to Title if Description does not help
324321
return software_found['Title']
322+
else:
323+
# Default to Title if Description does not help
324+
return software_found['Title']

plugins/modules/software_center_download.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,15 @@ def _check_similar_files(dest, filename):
128128
bool: True if similar files exist, False otherwise.
129129
filename_similar_names: A list of similar filenames if they exist, empty list otherwise.
130130
"""
131-
# pattern = dest + '/**/' + os.path.splitext(filename)[0]
132-
filename_base = os.path.splitext(filename)[0]
133-
filename_pattern = os.path.join(dest, "**", filename_base)
131+
132+
# Check if filename has has extension and remove it for search
133+
if os.path.splitext(filename)[1]:
134+
filename_base = os.path.splitext(filename)[0]
135+
filename_pattern = os.path.join(dest, "**", filename_base + ".*")
136+
else:
137+
filename_pattern = os.path.join(dest, "**", filename + ".*")
138+
139+
# Find all similar files in dest and sub-folders.
134140
filename_similar = glob.glob(filename_pattern, recursive=True)
135141

136142
if filename_similar:
@@ -217,7 +223,7 @@ def run_module():
217223
else:
218224
# Exact file not found, search for similar files with pattern
219225
filename_similar_exists, filename_similar_names = _check_similar_files(dest, filename)
220-
if filename_similar_exists and not (query and search_alternatives):
226+
if filename_similar_exists:
221227
result['skipped'] = True
222228
result['msg'] = f"Similar file(s) already exist: {', '.join(filename_similar_names)}"
223229
module.exit_json(**result)

0 commit comments

Comments
 (0)