11#include "fastfetch.h"
22#include "common/printing.h"
33#include "common/parsing.h"
4+ #include "detection/disk/disk.h"
45
56#include <sys/statvfs.h>
67
@@ -64,49 +65,7 @@ static void printStatvfs(FFinstance* instance, const FFstrbuf* key, const char*
6465 ffStrbufDestroy (& usedPretty );
6566}
6667
67- static void printFolderAutodetection (FFinstance * instance , const char * folderPath , struct statvfs * fs )
68- {
69- FFstrbuf key ;
70- ffStrbufInit (& key );
71- createKey (instance , folderPath , & key );
72- printStatvfs (instance , & key , folderPath , fs );
73- ffStrbufDestroy (& key );
74- }
75-
76- static void printFoldersAutodetection (FFinstance * instance )
77- {
78- struct statvfs fsRoot ;
79- int rootRet = statvfs (FASTFETCH_TARGET_DIR_ROOT "/" , & fsRoot );
80-
81- if (rootRet != 0 )
82- {
83- FFstrbuf key ;
84- ffStrbufInit (& key );
85- createKey (instance , NULL , & key );
86- ffPrintErrorString (instance , key .chars , 0 , NULL , & instance -> config .disk .errorFormat , "statvfs for / returned not zero: %i" , rootRet );
87- ffStrbufDestroy (& key );
88- return ;
89- }
90-
91- //On MacOS statvfs seems to return different f_fsid for the same filesystem.
92- //Since it isn't really possible to install /Users on a separate disk anyway, just never print it by default.
93- #ifndef __APPLE__
94- struct statvfs fsHome ;
95- int homeRet = statvfs (FASTFETCH_TARGET_DIR_HOME , & fsHome );
96- bool printHome = homeRet == 0 && (fsRoot .f_fsid != fsHome .f_fsid );
97- #else
98- bool printHome = false;
99- #endif // !__APPLE__
100-
101- printFolderAutodetection (instance , printHome ? FASTFETCH_TARGET_DIR_ROOT "/" : NULL , & fsRoot );
102-
103- #ifndef __APPLE__
104- if (printHome )
105- printFolderAutodetection (instance , FASTFETCH_TARGET_DIR_HOME , & fsHome );
106- #endif // !__APPLE__
107- }
108-
109- static void printFolderCustom (FFinstance * instance , const char * folderPath )
68+ static void printFolder (FFinstance * instance , const char * folderPath )
11069{
11170 FFstrbuf key ;
11271 ffStrbufInit (& key );
@@ -131,17 +90,28 @@ void ffPrintDisk(FFinstance* instance)
13190
13291 if (instance -> config .diskFolders .length == 0 )
13392 {
134- printFoldersAutodetection (instance );
93+ FFlist folders ;
94+ ffListInit (& folders , sizeof (FFstrbuf ));
95+ const char * error = ffDiskAutodetectFolders (instance , & folders );
96+ if (error )
97+ ffPrintError (instance , FF_DISK_MODULE_NAME , 0 , & instance -> config .disk , "%s" , error );
98+ for (uint32_t i = 0 ; i < folders .length ; ++ i )
99+ {
100+ FFstrbuf * folder = (FFstrbuf * )ffListGet (& folders , i );
101+ printFolder (instance , folder -> chars );
102+ ffStrbufDestroy (folder );
103+ }
104+ ffListDestroy (& folders );
135105 return ;
136106 }
137107
138108 uint32_t startIndex = 0 ;
139- while (startIndex < instance -> config .diskFolders .length )
109+ while (startIndex < instance -> config .diskFolders .length )
140110 {
141111 uint32_t colonIndex = ffStrbufNextIndexC (& instance -> config .diskFolders , startIndex , ':' );
142112 instance -> config .diskFolders .chars [colonIndex ] = '\0' ;
143113
144- printFolderCustom (instance , instance -> config .diskFolders .chars + startIndex );
114+ printFolder (instance , instance -> config .diskFolders .chars + startIndex );
145115
146116 startIndex = colonIndex + 1 ;
147117 }
0 commit comments