mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +01:00
Disk (Linux): adds glob pattern matching for hidden disk folders
Fixes #1999
This commit is contained in:
+34
-4
@@ -5,7 +5,10 @@
|
||||
#include "common/time.h"
|
||||
#include "detection/disk/disk.h"
|
||||
#include "modules/disk/disk.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
|
||||
@@ -186,6 +189,30 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool isMatchFolders(FFstrbuf* folders, const FFstrbuf* path, char separator)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
uint32_t startIndex = 0;
|
||||
while(startIndex < folders->length)
|
||||
{
|
||||
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator);
|
||||
|
||||
char savedColon = folders->chars[colonIndex]; // Can be '\0' if at end
|
||||
folders->chars[colonIndex] = '\0';
|
||||
|
||||
bool matched = fnmatch(&folders->chars[startIndex], path->chars, 0) == 0;
|
||||
folders->chars[colonIndex] = savedColon;
|
||||
|
||||
if (matched) return true;
|
||||
|
||||
startIndex = colonIndex + 1;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return ffStrbufSeparatedContain(folders, path, separator);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ffPrintDisk(FFDiskOptions* options)
|
||||
{
|
||||
FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk));
|
||||
@@ -203,8 +230,11 @@ bool ffPrintDisk(FFDiskOptions* options)
|
||||
if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes))
|
||||
continue;
|
||||
|
||||
if (options->hideFolders.length && ffStrbufSeparatedContain(&options->hideFolders, &disk->mountpoint, FF_DISK_FOLDER_SEPARATOR))
|
||||
continue;
|
||||
if (options->hideFolders.length)
|
||||
{
|
||||
if (isMatchFolders(&options->hideFolders, &disk->mountpoint, FF_DISK_FOLDER_SEPARATOR))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (options->hideFS.length && ffStrbufSeparatedContain(&options->hideFS, &disk->filesystem, ':'))
|
||||
continue;
|
||||
@@ -452,7 +482,7 @@ void ffInitDiskOptions(FFDiskOptions* options)
|
||||
#if _WIN32 || __APPLE__ || __ANDROID__
|
||||
ffStrbufInit(&options->hideFolders);
|
||||
#else
|
||||
ffStrbufInitStatic(&options->hideFolders, "/efi:/boot:/boot/efi:/boot/firmware");
|
||||
ffStrbufInitS(&options->hideFolders, "/efi:/boot:/boot/efi:/boot/firmware");
|
||||
#endif
|
||||
ffStrbufInit(&options->hideFS);
|
||||
options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT;
|
||||
|
||||
Reference in New Issue
Block a user