From f0e9caaf04ba30853a4c9704afd6433fdc7294ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 18 Sep 2025 14:51:00 +0800 Subject: [PATCH] Disk: allows array input for disk folder and filesystem options --- doc/json_schema.json | 55 ++++++++++++++++++++++++++++++++++----- src/detection/disk/disk.c | 8 +----- src/detection/disk/disk.h | 6 +++++ src/modules/disk/disk.c | 32 ++++++++++++++++++++--- 4 files changed, 85 insertions(+), 16 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index 284ec5736..071695dba 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -2307,17 +2307,60 @@ "const": "disk" }, "folders": { - "type": "string", - "description": "A colon (semicolon on Windows) separated list of folder paths for the disk output\nDefault: auto detection using mount-points\nThis option overrides other `show*` options" + "description": "A list of folder paths for the disk output\nDefault: auto detection using mount-points\nThis option overrides other `show*` options", + "oneOf": [ + { + "type": "string", + "description": "A colon (semicolon on Windows) separated list of folder paths to get disk usage from", + "default": "/" + }, + { + "type": "array", + "description": "An array of folder paths to get disk usage from", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + } + ] }, "hideFolders": { - "type": "string", - "description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output", + "description": "A list of folder paths to hide from the disk output", + "oneOf": [ + { + "type": "string", + "description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output" + }, + { + "type": "array", + "description": "An array of folder paths to hide from the disk output", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + } + ], "default": "/efi:/boot:/boot/efi:/boot/firmware" }, "hideFS": { - "type": "string", - "description": "A colon separated file systems to hide from the disk output" + "description": "A list of file systems to hide from the disk output", + "oneOf": [ + { + "type": "string", + "description": "A colon separated list of file systems to hide from the disk output" + }, + { + "type": "array", + "description": "An array of file systems to hide from the disk output", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + } + ] }, "showRegular": { "type": "boolean", diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index 0b43027fa..5b17dc0c3 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -2,18 +2,12 @@ bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint) { - #ifdef _WIN32 - const char separator = ';'; - #else - const char separator = ':'; - #endif - uint32_t mountpointLength = (uint32_t) strlen(mountpoint); uint32_t startIndex = 0; while(startIndex < folders->length) { - uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator); + uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, FF_DISK_FOLDER_SEPARATOR); uint32_t folderLength = colonIndex - startIndex; if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0) diff --git a/src/detection/disk/disk.h b/src/detection/disk/disk.h index 526de8128..ba8ead2fa 100644 --- a/src/detection/disk/disk.h +++ b/src/detection/disk/disk.h @@ -3,6 +3,12 @@ #include "fastfetch.h" #include "modules/disk/option.h" +#ifdef _WIN32 + #define FF_DISK_FOLDER_SEPARATOR ';' +#else + #define FF_DISK_FOLDER_SEPARATOR ':' +#endif + typedef struct FFDisk { FFstrbuf mountFrom; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 43283de4a..c9d8fc4e6 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -223,6 +223,32 @@ bool ffPrintDisk(FFDiskOptions* options) return true; } +static bool setSeparatedList(FFstrbuf* strbuf, yyjson_val* val, char separator) +{ + if (yyjson_is_str(val)) + { + ffStrbufSetJsonVal(strbuf, val); + return true; + } + if (yyjson_is_arr(val)) + { + ffStrbufClear(strbuf); + yyjson_val *elem; + size_t eidx, emax; + yyjson_arr_foreach(val, eidx, emax, elem) + { + if (yyjson_is_str(elem)) + { + if (strbuf->length > 0) + ffStrbufAppendC(strbuf, separator); + ffStrbufAppendJsonVal(strbuf, elem); + } + } + return true; + } + return false; +} + void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) { yyjson_val *key, *val; @@ -234,19 +260,19 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) if (unsafe_yyjson_equals_str(key, "folders")) { - ffStrbufSetJsonVal(&options->folders, val); + setSeparatedList(&options->folders, val, FF_DISK_FOLDER_SEPARATOR); continue; } if (unsafe_yyjson_equals_str(key, "hideFolders")) { - ffStrbufSetJsonVal(&options->hideFolders, val); + setSeparatedList(&options->hideFolders, val, FF_DISK_FOLDER_SEPARATOR); continue; } if (unsafe_yyjson_equals_str(key, "hideFS")) { - ffStrbufSetJsonVal(&options->hideFS, val); + setSeparatedList(&options->hideFS, val, ':'); continue; }