55#include "common/time.h"
66#include "detection/disk/disk.h"
77#include "modules/disk/disk.h"
8- #include "util/stringUtils.h"
8+
9+ #ifndef _WIN32
10+ #include <fnmatch.h>
11+ #endif
912
1013#pragma GCC diagnostic ignored "-Wsign-conversion"
1114
@@ -186,6 +189,30 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
186189 }
187190}
188191
192+ static inline bool isMatchFolders (FFstrbuf * folders , const FFstrbuf * path , char separator )
193+ {
194+ #ifndef _WIN32
195+ uint32_t startIndex = 0 ;
196+ while (startIndex < folders -> length )
197+ {
198+ uint32_t colonIndex = ffStrbufNextIndexC (folders , startIndex , separator );
199+
200+ char savedColon = folders -> chars [colonIndex ]; // Can be '\0' if at end
201+ folders -> chars [colonIndex ] = '\0' ;
202+
203+ bool matched = fnmatch (& folders -> chars [startIndex ], path -> chars , 0 ) == 0 ;
204+ folders -> chars [colonIndex ] = savedColon ;
205+
206+ if (matched ) return true;
207+
208+ startIndex = colonIndex + 1 ;
209+ }
210+ return false;
211+ #else
212+ return ffStrbufSeparatedContain (folders , path , separator );
213+ #endif
214+ }
215+
189216bool ffPrintDisk (FFDiskOptions * options )
190217{
191218 FF_LIST_AUTO_DESTROY disks = ffListCreate (sizeof (FFDisk ));
@@ -203,8 +230,11 @@ bool ffPrintDisk(FFDiskOptions* options)
203230 if (__builtin_expect (options -> folders .length == 0 , 1 ) && (disk -> type & ~options -> showTypes ))
204231 continue ;
205232
206- if (options -> hideFolders .length && ffStrbufSeparatedContain (& options -> hideFolders , & disk -> mountpoint , FF_DISK_FOLDER_SEPARATOR ))
207- continue ;
233+ if (options -> hideFolders .length )
234+ {
235+ if (isMatchFolders (& options -> hideFolders , & disk -> mountpoint , FF_DISK_FOLDER_SEPARATOR ))
236+ continue ;
237+ }
208238
209239 if (options -> hideFS .length && ffStrbufSeparatedContain (& options -> hideFS , & disk -> filesystem , ':' ))
210240 continue ;
@@ -452,7 +482,7 @@ void ffInitDiskOptions(FFDiskOptions* options)
452482 #if _WIN32 || __APPLE__ || __ANDROID__
453483 ffStrbufInit (& options -> hideFolders );
454484 #else
455- ffStrbufInitStatic (& options -> hideFolders , "/efi:/boot:/boot/efi:/boot/firmware" );
485+ ffStrbufInitS (& options -> hideFolders , "/efi:/boot:/boot/efi:/boot/firmware" );
456486 #endif
457487 ffStrbufInit (& options -> hideFS );
458488 options -> showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT ;
0 commit comments