From 3a3c889b3dba023ffef05c8f821c25236424938f Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Mon, 10 Jan 2022 19:54:32 -0800
Subject: [PATCH] loadfiles() will perform liberal filename matching when len >
 12 chars

As discovered while making the Synchronet v3.18b feature video (https://www.youtube.com/watch?v=_IWzIV0_sZ4), when only a shortened version of a long filename is displayed (e.g. due to 80 column terminal width limitations), trying to download that filename by specifying the filename at the Download File(s) Filespec [All Files]: prompt can be problematic.

For example (as seen in the video), the file "SyncTERM-1.1-setup.exe" is displayed as "SyncTERM.exe" (on an 80-column terminal), yet trying to download "SyncTERM.exe" (or "syncterm.exe") using the 'D'ownload command would fail to find a file with that name (understandably, but frustratingly so).

This change will transform the requested filename-to-load if it is at least 12 characters in length and contains no wildcards (* or ?), to include a filename extending wildcard: "filename.txt" will become "filename*.txt" and "longfilename" will become "longfilename*".

For requested filespecs of NULL (all files) or specs containing wildcards or specs (filenames) less than 12 characters in length, no filespec transform takes place: so trying to list/download "a" doesn't match "apple.txt".
---
 src/sbbs3/filedat.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/sbbs3/filedat.c b/src/sbbs3/filedat.c
index 9b2086885a..920d3d9382 100644
--- a/src/sbbs3/filedat.c
+++ b/src/sbbs3/filedat.c
@@ -189,6 +189,22 @@ str_list_t loadfilenames(smb_t* smb, const char* filespec, time_t t, enum file_s
 // Load and optionally-sort files from an open filebase into a dynamically-allocated list of "objects"
 file_t* loadfiles(smb_t* smb, const char* filespec, time_t t, enum file_detail detail, enum file_sort order, size_t* count)
 {
+	// Liberal filespec matching when filespec does not contain wildcards and is at least 12 chars in length
+	char newfilespec[SMB_FILEIDX_NAMELEN + 1] = "";
+	if(filespec != NULL) {
+		size_t len = strlen(filespec);
+		if(len >= 12 && strcspn(filespec, "*?") == len) {
+			SAFECOPY(newfilespec, filespec);
+			char* ext = getfext(newfilespec);
+			if(ext != NULL) {
+				*ext = 0;
+				SAFECAT(newfilespec, "*");
+				SAFECAT(newfilespec, getfext(filespec));
+			} else
+				SAFECAT(newfilespec, "*");
+			filespec = newfilespec;
+		}
+	}
 	*count = 0;
 
 	long start = 0;	
-- 
GitLab