summaryrefslogtreecommitdiff
path: root/daemon/gvfsbackendftp.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2009-06-11 11:01:39 +0200
committerBenjamin Otte <otte@gnome.org>2009-06-11 11:01:39 +0200
commit36bd5e3846effed5fe8252ece85c93f00c3a0761 (patch)
treee5016bd58143df547b676229b28e08997c3fd0f4 /daemon/gvfsbackendftp.c
parentf9940f8318eb0835fb793557dbd914b856cbabf9 (diff)
downloadgvfs-36bd5e3846effed5fe8252ece85c93f00c3a0761.tar.gz
[FTP] use directory cache for error handling
Fix FIXME that complained about not having access to the cache from error handlers. Now that we have access, we can use it to check if a file exists and/or is a directory instead of issuing some commands manually.
Diffstat (limited to 'daemon/gvfsbackendftp.c')
-rw-r--r--daemon/gvfsbackendftp.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/daemon/gvfsbackendftp.c b/daemon/gvfsbackendftp.c
index 67f9e4ca..79f83c54 100644
--- a/daemon/gvfsbackendftp.c
+++ b/daemon/gvfsbackendftp.c
@@ -529,17 +529,12 @@ do_unmount (GVfsBackend * backend,
static void
error_550_exists (GVfsFtpTask *task, gpointer file)
{
- /* FIXME:
- * What we should do here is look at the cache to figure out if the file
- * exists, but as cache access is only exposed via the backend
- * structure (it should be properly abstracted into an opaque thread-safe
- * structure and then be available per-connection), we could not do that.
- * So instead, we use the same code we use when trying to find hidden
- * directories.
- */
- if (g_vfs_ftp_task_try_cd (task, file) ||
- g_vfs_ftp_task_send (task, 0, "SIZE %s", g_vfs_ftp_file_get_ftp_path (file)))
+ GFileInfo *info;
+
+ info = g_vfs_ftp_dir_cache_lookup_file (task->backend->dir_cache, task, file, FALSE);
+ if (info)
{
+ g_object_unref (info);
g_set_error_literal (&task->error,
G_IO_ERROR,
G_IO_ERROR_EXISTS,
@@ -547,7 +542,7 @@ error_550_exists (GVfsFtpTask *task, gpointer file)
}
else
{
- /* clear potential error from g_vfs_ftp_task_send() above */
+ /* clear potential error from file lookup above */
g_vfs_ftp_task_clear_error (task);
}
}
@@ -555,19 +550,23 @@ error_550_exists (GVfsFtpTask *task, gpointer file)
static void
error_550_is_directory (GVfsFtpTask *task, gpointer file)
{
- if (g_vfs_ftp_task_send (task,
- 0,
- "CWD %s", g_vfs_ftp_file_get_ftp_path (file)))
+ GFileInfo *info;
+
+ /* need to resolve symlinks here to know if a link is a dir or not */
+ info = g_vfs_ftp_dir_cache_lookup_file (task->backend->dir_cache, task, file, TRUE);
+ if (info && g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
{
+ g_object_unref (info);
g_set_error_literal (&task->error, G_IO_ERROR,
G_IO_ERROR_IS_DIRECTORY,
_("File is directory"));
+ return;
}
- else
- {
- /* clear potential error from g_vfs_ftp_task_send() above */
- g_vfs_ftp_task_clear_error (task);
- }
+ else if (info)
+ g_object_unref (info);
+
+ /* clear potential error from file lookup above */
+ g_vfs_ftp_task_clear_error (task);
}
static void