summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorNikias Bassen <nikias@gmx.li>2010-03-15 14:42:23 +0100
committerBastien Nocera <hadess@hadess.net>2010-03-15 18:37:04 +0000
commit27478c09c87946217e8ba6108467fd49dc0b9e26 (patch)
treefe288e5c92d93d6c3e6c09708a40f122161fea33 /daemon
parent7900fd49cb10286976d5472645f69313692454c8 (diff)
downloadgvfs-27478c09c87946217e8ba6108467fd49dc0b9e26.tar.gz
g_vfs_backend_afc_open_for_read: only open regular files
https://bugzilla.gnome.org/show_bug.cgi?id=612536
Diffstat (limited to 'daemon')
-rw-r--r--daemon/gvfsbackendafc.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/daemon/gvfsbackendafc.c b/daemon/gvfsbackendafc.c
index 2b7744a1..ae41a043 100644
--- a/daemon/gvfsbackendafc.c
+++ b/daemon/gvfsbackendafc.c
@@ -429,6 +429,44 @@ g_vfs_backend_afc_unmount (GVfsBackend *backend,
g_vfs_job_succeeded (G_VFS_JOB(job));
}
+static gboolean file_get_info (GVfsBackendAfc *backend, const char *path, GFileInfo *info);
+
+static gboolean
+is_directory (GVfsBackendAfc *backend,
+ const char *path)
+{
+ gboolean result = FALSE;
+ GFileInfo *info;
+
+ info = g_file_info_new();
+ if (file_get_info (backend, path, info))
+ {
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ result = TRUE;
+ }
+
+ g_object_unref (info);
+ return result;
+}
+
+static gboolean
+is_regular (GVfsBackendAfc *backend,
+ const char *path)
+{
+ gboolean result = FALSE;
+ GFileInfo *info;
+
+ info = g_file_info_new();
+ if (file_get_info (backend, path, info))
+ {
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR)
+ result = TRUE;
+ }
+
+ g_object_unref (info);
+ return result;
+}
+
/* Callback to open an existing file for reading. */
static void
g_vfs_backend_afc_open_for_read (GVfsBackend *backend,
@@ -441,6 +479,22 @@ g_vfs_backend_afc_open_for_read (GVfsBackend *backend,
self = G_VFS_BACKEND_AFC(backend);
g_return_if_fail (self->connected);
+ if (is_directory (self, path))
+ {
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
+ G_IO_ERROR_IS_DIRECTORY,
+ _("Can't open directory"));
+ return;
+ }
+
+ if (!is_regular (self, path))
+ {
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
+ G_IO_ERROR_NOT_FOUND,
+ _("File doesn't exist"));
+ return;
+ }
+
if (G_UNLIKELY(g_vfs_backend_afc_check (afc_file_open (self->afc_cli,
path, AFC_FOPEN_RDONLY, &fd),
G_VFS_JOB(job))))
@@ -969,6 +1023,36 @@ g_vfs_backend_afc_set_info_from_afcinfo (GVfsBackendAfc *self,
}
}
+static gboolean
+file_get_info (GVfsBackendAfc *backend,
+ const char *path,
+ GFileInfo *info)
+{
+ char **afcinfo = NULL;
+ const char *basename, *ptr;
+ gboolean result = FALSE;
+
+ g_return_val_if_fail (backend->connected, result);
+ g_return_val_if_fail (info, result);
+
+ if (G_LIKELY(afc_get_file_info (backend->afc_cli, path, &afcinfo) == AFC_E_SUCCESS))
+ {
+ ptr = strrchr (path, '/');
+ if (ptr && ptr[1] != '\0')
+ basename = ptr + 1;
+ else
+ basename = path;
+
+ g_vfs_backend_afc_set_info_from_afcinfo (backend, info, afcinfo, basename, path, NULL, 0);
+ result = TRUE;
+ }
+
+ if (afcinfo)
+ g_strfreev(afcinfo);
+
+ return result;
+}
+
/* Callback for iterating over a directory. */
static void
g_vfs_backend_afc_enumerate (GVfsBackend *backend,