Commit 60e4d7af authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

loadfiles() will perform liberal filename matching when len > 12 chars

As discovered while making the Synchronet v3.18b feature video (, 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".
parent a3cb5471
......@@ -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;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment