Skip to content

Commit 57a4b9b

Browse files
committed
Disk: refactors mountpoint matching to use shared string utilities
1 parent ef3989d commit 57a4b9b

File tree

8 files changed

+7
-27
lines changed

8 files changed

+7
-27
lines changed

src/detection/disk/disk.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
#include "disk.h"
22

3-
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint)
4-
{
5-
uint32_t mountpointLength = (uint32_t) strlen(mountpoint);
6-
7-
uint32_t startIndex = 0;
8-
while(startIndex < folders->length)
9-
{
10-
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, FF_DISK_FOLDER_SEPARATOR);
11-
12-
uint32_t folderLength = colonIndex - startIndex;
13-
if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0)
14-
return true;
15-
16-
startIndex = colonIndex + 1;
17-
}
18-
19-
return false;
20-
}
21-
223
static int compareDisks(const FFDisk* disk1, const FFDisk* disk2)
234
{
245
return ffStrbufComp(&disk1->mountpoint, &disk2->mountpoint);

src/detection/disk/disk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ typedef struct FFDisk
3535
const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks /* list of FFDisk */);
3636

3737
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks);
38-
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint);

src/detection/disk/disk_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
145145
{
146146
if(__builtin_expect(options->folders.length > 0, 0))
147147
{
148-
if(!ffDiskMatchMountpoint(&options->folders, fs->f_mntonname))
148+
if(!ffStrbufSeparatedContainS(&options->folders, fs->f_mntonname, FF_DISK_FOLDER_SEPARATOR))
149149
continue;
150150
}
151151
else if(!ffStrEquals(fs->f_mntonname, "/") && !ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs") && !ffStrEquals(fs->f_fstypename, "fusefs.sshfs"))

src/detection/disk/disk_haiku.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
2323

2424
if (__builtin_expect(options->folders.length, 0))
2525
{
26-
if (!ffDiskMatchMountpoint(&options->folders, path.Path()))
26+
if (!ffStrbufSeparatedContainS(&options->folders, path.Path(), FF_DISK_FOLDER_SEPARATOR))
2727
continue;
2828
}
2929

src/detection/disk/disk_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
291291
{
292292
if (__builtin_expect(options->folders.length > 0, false))
293293
{
294-
if (!ffDiskMatchMountpoint(&options->folders, device->mnt_dir))
294+
if (!ffStrbufSeparatedContainS(&options->folders, device->mnt_dir, FF_DISK_FOLDER_SEPARATOR))
295295
continue;
296296
}
297297
else if(!isPhysicalDevice(device))

src/detection/disk/disk_sunos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
113113
{
114114
if (__builtin_expect(options->folders.length, 0))
115115
{
116-
if (!ffDiskMatchMountpoint(&options->folders, device.mnt_mountp))
116+
if (!ffStrbufSeparatedContainS(&options->folders, device.mnt_mountp, FF_DISK_FOLDER_SEPARATOR))
117117
continue;
118118
}
119119
else if(!isPhysicalDevice(&device))

src/detection/disk/disk_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
4747

4848
if (__builtin_expect((long) options->folders.length, 0))
4949
{
50-
if (!ffDiskMatchMountpoint(&options->folders, buffer.chars))
50+
if (!ffStrbufSeparatedContain(&options->folders, &buffer, FF_DISK_FOLDER_SEPARATOR))
5151
continue;
5252
}
5353
else if(driveType == DRIVE_NO_ROOT_DIR)

src/modules/disk/disk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ bool ffPrintDisk(FFDiskOptions* options)
203203
if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes))
204204
continue;
205205

206-
if (options->hideFolders.length && ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars))
206+
if (options->hideFolders.length && ffStrbufSeparatedContain(&options->hideFolders, &disk->mountpoint, FF_DISK_FOLDER_SEPARATOR))
207207
continue;
208208

209-
if (options->hideFS.length && ffStrbufMatchSeparated(&disk->filesystem, &options->hideFS, ':'))
209+
if (options->hideFS.length && ffStrbufSeparatedContain(&options->hideFS, &disk->filesystem, ':'))
210210
continue;
211211

212212
printDisk(options, disk, ++index);

0 commit comments

Comments
 (0)