summaryrefslogtreecommitdiff
path: root/gio/glocalfile.c
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-01-18 18:44:11 -0500
committerMatthias Clasen <mclasen@redhat.com>2013-01-19 14:04:49 -0500
commit6be54e9f56e9344ecd55a8952dff957573a136b7 (patch)
tree075594cfd2c3bd2c9dcc96dd73ca46caf66fab72 /gio/glocalfile.c
parentc83600e8ae419df7c30b16d267d71d706a29936f (diff)
downloadglib-6be54e9f56e9344ecd55a8952dff957573a136b7.tar.gz
glib-6be54e9f56e9344ecd55a8952dff957573a136b7.tar.bz2
glib-6be54e9f56e9344ecd55a8952dff957573a136b7.zip
localfile: add support for monitoring on NFS
Add a pair of new extension points: 'gio-nfs-file-monitor' and 'gio-nfs-directory-monitor'. Add a check to GLocalFile when creating a file monitor. If the requested file is in the user's home directory and the user has an NFS home directory then attempt to use an implementation of one of the new extension points. If we don't have any implementations then fall back to the normal "local" monitors. https://bugzilla.gnome.org/show_bug.cgi?id=592211
Diffstat (limited to 'gio/glocalfile.c')
-rw-r--r--gio/glocalfile.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index db4a48ae5..96177546f 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -2405,6 +2405,75 @@ g_local_file_move (GFile *source,
return TRUE;
}
+static gboolean
+is_remote_fs (const gchar *filename)
+{
+ const char *fsname = NULL;
+
+#ifdef USE_STATFS
+ struct statfs statfs_buffer;
+ int statfs_result = 0;
+
+#if STATFS_ARGS == 2
+ statfs_result = statfs (filename, &statfs_buffer);
+#elif STATFS_ARGS == 4
+ statfs_result = statfs (filename, &statfs_buffer, sizeof (statfs_buffer), 0);
+#endif
+
+#elif defined(USE_STATVFS)
+ struct statvfs statfs_buffer;
+
+ statfs_result = statvfs (filename, &statfs_buffer);
+#else
+ return FALSE;
+#endif
+
+ if (statfs_result == -1)
+ return FALSE;
+
+#ifdef USE_STATFS
+#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
+ fsname = statfs_buffer.f_fstypename;
+#else
+ fsname = get_fs_type (statfs_buffer.f_type);
+#endif
+
+#elif defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
+ fsname = statfs_buffer.f_basetype;
+#endif
+
+ if (fsname != NULL)
+ {
+ if (strcmp (fsname, "nfs") == 0)
+ return TRUE;
+ if (strcmp (fsname, "nfs4") == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+is_remote (const gchar *filename)
+{
+ static gboolean remote_home;
+ static gsize initialized;
+ const gchar *home;
+
+ home = g_get_home_dir ();
+ if (path_has_prefix (filename, home))
+ {
+ if (g_once_init_enter (&initialized))
+ {
+ remote_home = is_remote_fs (home);
+ g_once_init_leave (&initialized, TRUE);
+ }
+ return remote_home;
+ }
+
+ return FALSE;
+}
+
static GFileMonitor*
g_local_file_monitor_dir (GFile *file,
GFileMonitorFlags flags,
@@ -2412,7 +2481,7 @@ g_local_file_monitor_dir (GFile *file,
GError **error)
{
GLocalFile* local_file = G_LOCAL_FILE(file);
- return _g_local_directory_monitor_new (local_file->filename, flags, error);
+ return _g_local_directory_monitor_new (local_file->filename, flags, is_remote (local_file->filename), error);
}
static GFileMonitor*
@@ -2422,7 +2491,7 @@ g_local_file_monitor_file (GFile *file,
GError **error)
{
GLocalFile* local_file = G_LOCAL_FILE(file);
- return _g_local_file_monitor_new (local_file->filename, flags, error);
+ return _g_local_file_monitor_new (local_file->filename, flags, is_remote (local_file->filename), error);
}
static void