From 71b75f1c0fae172722ea17c22b8177cef4286b1f Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Thu, 11 Apr 2024 12:36:32 +0100 Subject: [PATCH] Bug fix: Collections and unmounted drives (2) Did not compile on FreeBSD This is a blind fix. --- src/collect-io.cc | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/collect-io.cc b/src/collect-io.cc index 5b9c5ba6..656cce0d 100644 --- a/src/collect-io.cc +++ b/src/collect-io.cc @@ -27,7 +27,12 @@ #include #include #include + +#if defined(__linux__) #include +#else +#include +#endif #include @@ -231,6 +236,7 @@ static gboolean collection_load_private(CollectionData *cd, const gchar *path, C if (*buffer2) { gboolean valid; + gboolean found = FALSE; if (!flush) changed |= collect_manager_process_action(entry, &buffer2); @@ -249,9 +255,9 @@ static gboolean collection_load_private(CollectionData *cd, const gchar *path, C if (!g_str_has_prefix(buffer2, "/home") && !g_str_has_prefix(buffer2, "/tmp") && !g_str_has_prefix(buffer2, "/usr")) { /* The file was on a mounted drive and either has been deleted or the drive is not mounted */ +#if defined(__linux__) struct mntent *mount_entry; FILE *mount_entries; - gboolean found = FALSE; mount_entries = setmntent("/proc/mounts", "r"); if (mount_entries == nullptr) @@ -274,6 +280,30 @@ static gboolean collection_load_private(CollectionData *cd, const gchar *path, C } } endmntent(mount_entries); +#else + struct statfs* mounts; + int num_mounts = getmntinfo(&mounts, MNT_NOWAIT); + + if (num_mounts < 0) + { + /* It is assumed this will never fail */ + perror("setmntent"); + exit(1); + } + + for (int i = 0; i < num_mounts; i++) + { + if (g_strcmp0(mounts[i].f_mntonname, G_DIR_SEPARATOR_S) != 0) + { + if (g_str_has_prefix(buffer2, mounts[i].f_mntonname)) + { + log_printf("%s was a file on a mounted filesystem but has been deleted: %s", buffer2, cd->name); + found = TRUE; + break; + } + } + } +#endif if (!found) { -- 2.20.1