Skip to content

Commit a0f5790

Browse files
committed
Disk: add --disk-hide-fs
Fix #1762
1 parent d439ce8 commit a0f5790

File tree

8 files changed

+93
-10
lines changed

8 files changed

+93
-10
lines changed

doc/json_schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,10 @@
17581758
"type": "string",
17591759
"description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output\nDefault: /efi:/boot:/boot/efi"
17601760
},
1761+
"hideFS": {
1762+
"type": "string",
1763+
"description": "A colon separated file systems to hide from the disk output"
1764+
},
17611765
"showExternal": {
17621766
"type": "boolean",
17631767
"description": "Set if external volume should be printed",

src/data/help.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,15 @@
845845
"desc": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output",
846846
"arg": {
847847
"type": "path",
848-
"default": "Auto detection using mount-points"
848+
"default": "/efi:/boot:/boot/efi"
849+
}
850+
},
851+
{
852+
"long": "disk-hide-fs",
853+
"desc": "A colon separated list of file systems to hide from the disk output",
854+
"arg": {
855+
"type": "string",
856+
"default": ""
849857
}
850858
},
851859
{

src/detection/disk/disk.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,5 @@ const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
5454
}
5555
}
5656

57-
if (options->hideFolders.length)
58-
{
59-
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
60-
{
61-
if (ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars))
62-
disk->type |= FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
63-
}
64-
}
65-
6657
return NULL;
6758
}

src/modules/disk/disk.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ void ffPrintDisk(FFDiskOptions* options)
179179
if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes))
180180
continue;
181181

182+
if (options->hideFolders.length && ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars))
183+
continue;
184+
185+
if (options->hideFS.length && ffStrbufMatchSeparated(&disk->filesystem, &options->hideFS, ':'))
186+
continue;
187+
182188
printDisk(options, disk, ++index);
183189
}
184190
}
@@ -211,6 +217,12 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch
211217
return true;
212218
}
213219

220+
if (ffStrEqualsIgnCase(subKey, "hide-fs"))
221+
{
222+
ffOptionParseString(key, value, &options->hideFS);
223+
return true;
224+
}
225+
214226
if (ffStrEqualsIgnCase(subKey, "show-regular"))
215227
{
216228
if (ffOptionParseBoolean(value))
@@ -305,6 +317,12 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
305317
continue;
306318
}
307319

320+
if (ffStrEqualsIgnCase(key, "hideFS"))
321+
{
322+
ffStrbufSetS(&options->hideFS, yyjson_get_str(val));
323+
continue;
324+
}
325+
308326
if (ffStrEqualsIgnCase(key, "showExternal"))
309327
{
310328
if (yyjson_get_bool(val))
@@ -397,6 +415,9 @@ void ffGenerateDiskJsonConfig(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso
397415
if (!ffStrbufEqual(&options->hideFolders, &defaultOptions.hideFolders))
398416
yyjson_mut_obj_add_strbuf(doc, module, "hideFolders", &options->hideFolders);
399417

418+
if (!ffStrbufEqual(&options->hideFS, &defaultOptions.hideFS))
419+
yyjson_mut_obj_add_strbuf(doc, module, "hideFS", &options->hideFS);
420+
400421
if (defaultOptions.calcType != options->calcType)
401422
yyjson_mut_obj_add_bool(doc, module, "useAvailable", options->calcType == FF_DISK_CALC_TYPE_AVAILABLE);
402423

@@ -516,6 +537,7 @@ void ffInitDiskOptions(FFDiskOptions* options)
516537
#else
517538
ffStrbufInitStatic(&options->hideFolders, "/efi:/boot:/boot/efi");
518539
#endif
540+
ffStrbufInit(&options->hideFS);
519541
options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT;
520542
options->calcType = FF_DISK_CALC_TYPE_FREE;
521543
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
@@ -524,4 +546,7 @@ void ffInitDiskOptions(FFDiskOptions* options)
524546
void ffDestroyDiskOptions(FFDiskOptions* options)
525547
{
526548
ffOptionDestroyModuleArg(&options->moduleArgs);
549+
ffStrbufDestroy(&options->folders);
550+
ffStrbufDestroy(&options->hideFolders);
551+
ffStrbufDestroy(&options->hideFS);
527552
}

src/modules/disk/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct FFDiskOptions
3030

3131
FFstrbuf folders;
3232
FFstrbuf hideFolders;
33+
FFstrbuf hideFS;
3334
FFDiskVolumeType showTypes;
3435
FFDiskCalcType calcType;
3536
FFPercentageModuleConfig percent;

src/util/FFstrbuf.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,32 @@ bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf)
607607

608608
return changed;
609609
}
610+
611+
/// @brief Check if a separated string contains a substring.
612+
/// @param strbuf The substring to check.
613+
/// @param compLength The length of the separated string to check.
614+
/// @param comp The separated string to check.
615+
/// @param separator The separator character.
616+
bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator)
617+
{
618+
if (strbuf->length == 0)
619+
return true;
620+
621+
if (compLength == 0)
622+
return false;
623+
624+
for (const char* p = comp; p < comp + compLength;)
625+
{
626+
const char* colon = memchr(p, separator, compLength);
627+
if (colon == NULL)
628+
return strcmp(strbuf->chars, p) == 0;
629+
630+
uint32_t substrLength = (uint32_t) (colon - p);
631+
if (strbuf->length == substrLength && memcmp(strbuf->chars, p, substrLength) == 0)
632+
return true;
633+
634+
p = colon + 1;
635+
}
636+
637+
return false;
638+
}

src/util/FFstrbuf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void ffStrbufLowerCase(FFstrbuf* strbuf);
9292
bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer);
9393
void ffStrbufGetlineRestore(char** lineptr, size_t* n, FFstrbuf* buffer);
9494
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf);
95+
bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator);
9596

9697
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate)
9798
{
@@ -506,4 +507,14 @@ static inline void ffStrbufTrim(FFstrbuf* strbuf, char c)
506507
ffStrbufTrimLeft(strbuf, c);
507508
}
508509

510+
static inline bool ffStrbufMatchSeparatedS(const FFstrbuf* strbuf, const char* comp, char separator)
511+
{
512+
return ffStrbufMatchSeparatedNS(strbuf, (uint32_t) strlen(comp), comp, separator);
513+
}
514+
515+
static inline bool ffStrbufMatchSeparated(const FFstrbuf* strbuf, const FFstrbuf* comp, char separator)
516+
{
517+
return ffStrbufMatchSeparatedNS(strbuf, comp->length, comp->chars, separator);
518+
}
519+
509520
#define FF_STRBUF_AUTO_DESTROY FFstrbuf __attribute__((__cleanup__(ffStrbufDestroy)))

tests/strbuf.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,20 @@ int main(void)
635635
VERIFY(ffStrbufEqualS(&newStr, ""));
636636
}
637637

638+
{
639+
ffStrbufSetStatic(&strbuf, "abc");
640+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc:def:ghi", ' ') == false);
641+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc:def:ghi", ':') == true);
642+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "def:ghi", ' ') == false);
643+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "def:ghi", ':') == false);
644+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "def", ':') == false);
645+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc", ':') == true);
646+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "", ' ') == false);
647+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, ":abc:", ':') == true);
648+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc:", ':') == true);
649+
VERIFY(ffStrbufMatchSeparatedS(&strbuf, ":abc", ':') == true);
650+
}
651+
638652
//Success
639653
puts("\e[32mAll tests passed!" FASTFETCH_TEXT_MODIFIER_RESET);
640654
}

0 commit comments

Comments
 (0)