[tracker] libtracker-common: Don’t fail statvfs () on a missing directory
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-common: Don’t fail statvfs () on a missing directory
- Date: Sun, 31 May 2015 17:10:21 +0000 (UTC)
commit 707b9dff7090adf01102185a66d869d23db28b6f
Author: Philip Withnall <philip withnall collabora co uk>
Date: Mon May 4 13:38:51 2015 +0100
libtracker-common: Don’t fail statvfs() on a missing directory
If $XDG_CACHE_HOME/tracker doesn’t exist on startup, the statvfs() call
to determine how much space is left will fail with ENOENT. However, the
code currently interprets this as being out of space, and will cause the
rest of Tracker to shut down, even if there is actually plenty of space
left on the disk.
Avoid this by traversing up the directory hierarchy until statvfs() does
not fail with ENOENT.
https://bugzilla.gnome.org/show_bug.cgi?id=748907
src/libtracker-common/tracker-file-utils.c | 56 +++++++++++++++++----------
1 files changed, 35 insertions(+), 21 deletions(-)
---
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index ad9f6b3..6fca87e 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -256,44 +256,58 @@ tracker_file_get_mime_type (GFile *file)
#endif /* __linux__ */
-guint64
-tracker_file_system_get_remaining_space (const gchar *path)
+static gboolean
+statvfs_helper (const gchar *path, struct __statvfs *st)
{
- guint64 remaining;
- struct __statvfs st;
+ gchar *_path;
+ int retval;
//LCOV_EXCL_START
- if (__statvfs (path, &st) == -1) {
- remaining = 0;
+ /* Iterate up the path to the root until statvfs() doesn’t error with
+ * ENOENT. This prevents the call failing on first-startup when (for
+ * example) ~/.cache/tracker might not exist. */
+ _path = g_strdup (path);
+
+ while ((retval = __statvfs (_path, st)) == -1 && errno == ENOENT) {
+ gchar *tmp = g_path_get_dirname (_path);
+ g_free (_path);
+ _path = tmp;
+ }
+
+ g_free (_path);
+//LCOV_EXCL_STOP
+
+ if (retval == -1) {
g_critical ("Could not statvfs() '%s': %s",
path,
g_strerror (errno));
-//LCOV_EXCL_STOP
- } else {
- remaining = st.f_bsize * st.f_bavail;
}
- return remaining;
+ return (retval == 0);
+}
+
+guint64
+tracker_file_system_get_remaining_space (const gchar *path)
+{
+ struct __statvfs st;
+
+ if (statvfs_helper (path, &st)) {
+ return st.f_bsize * st.f_bavail;
+ } else {
+ return 0;
+ }
}
gdouble
tracker_file_system_get_remaining_space_percentage (const gchar *path)
{
- gdouble remaining;
struct __statvfs st;
-//LCOV_EXCL_START
- if (__statvfs (path, &st) == -1) {
- remaining = 0.0;
- g_critical ("Could not statvfs() '%s': %s",
- path,
- g_strerror (errno));
-//LCOV_EXCL_STOP
+ if (statvfs_helper (path, &st)) {
+ return (st.f_bavail * 100.0 / st.f_blocks);
} else {
- remaining = (st.f_bavail * 100.0 / st.f_blocks);
+ return 0.0;
}
-
- return remaining;
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]