diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2015-02-07 22:17:53 +0000 |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2015-02-11 23:20:23 +0000 |
commit | 5620bd8acb05c0a4eb93a792b25c349c5c6efebd (patch) | |
tree | e18742992c24522b44a84408b62513af68d8185a /daemon/gvfsbackendftp.c | |
parent | 07fc7a65258bce9c3ad950f9adc0e6c66e2b0835 (diff) | |
download | gvfs-5620bd8acb05c0a4eb93a792b25c349c5c6efebd.tar.gz |
ftp: Implement backups for replace
https://bugzilla.gnome.org/show_bug.cgi?id=621917
Diffstat (limited to 'daemon/gvfsbackendftp.c')
-rw-r--r-- | daemon/gvfsbackendftp.c | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/daemon/gvfsbackendftp.c b/daemon/gvfsbackendftp.c index 72586afe..5fe056be 100644 --- a/daemon/gvfsbackendftp.c +++ b/daemon/gvfsbackendftp.c @@ -976,25 +976,71 @@ do_replace (GVfsBackend *backend, { GVfsBackendFtp *ftp = G_VFS_BACKEND_FTP (backend); GVfsFtpTask task = G_VFS_FTP_TASK_INIT (ftp, G_VFS_JOB (job)); - GVfsFtpFile *file; + GVfsFtpFile *file, *backupfile = NULL; + static const GVfsFtpErrorFunc rnfr_handlers[] = { error_550_permission_or_not_found, + NULL }; + + file = g_vfs_ftp_file_new_from_gvfs (ftp, filename); if (make_backup) { - /* FIXME: implement! */ - g_set_error_literal (&task.error, - G_IO_ERROR, - G_IO_ERROR_CANT_CREATE_BACKUP, - _("backups not supported yet")); - g_vfs_ftp_task_done (&task); - return; + GFileInfo *info; + char *backup_path = g_strconcat (filename, "~", NULL); + backupfile = g_vfs_ftp_file_new_from_gvfs (ftp, backup_path); + g_free (backup_path); + + info = g_vfs_ftp_dir_cache_lookup_file (ftp->dir_cache, &task, file, FALSE); + + if (info) + { + guint ret; + + g_object_unref (info); + + ret = g_vfs_ftp_task_send (&task, + G_VFS_FTP_PASS_550, + "DELE %s", g_vfs_ftp_file_get_ftp_path (backupfile)); + if (!ret) + goto err_backup; + g_vfs_ftp_dir_cache_purge_file (ftp->dir_cache, backupfile); + + ret = g_vfs_ftp_task_send_and_check (&task, + G_VFS_FTP_PASS_300 | G_VFS_FTP_FAIL_200, + rnfr_handlers, + file, + NULL, + "RNFR %s", g_vfs_ftp_file_get_ftp_path (file)); + if (!ret) + goto err_backup; + + ret = g_vfs_ftp_task_send (&task, + 0, + "RNTO %s", g_vfs_ftp_file_get_ftp_path (backupfile)); + if (!ret) + goto err_backup; + + g_vfs_ftp_dir_cache_purge_file (ftp->dir_cache, file); + } + g_vfs_ftp_file_free (backupfile); } - file = g_vfs_ftp_file_new_from_gvfs (ftp, filename); do_start_write (&task, flags, "STOR %s", g_vfs_ftp_file_get_ftp_path (file)); g_vfs_ftp_dir_cache_purge_file (ftp->dir_cache, file); g_vfs_ftp_file_free (file); g_vfs_ftp_task_done (&task); + + return; + +err_backup: + g_vfs_ftp_file_free (file); + g_vfs_ftp_file_free (backupfile); + g_vfs_ftp_task_clear_error (&task); + g_set_error_literal (&task.error, + G_IO_ERROR, + G_IO_ERROR_CANT_CREATE_BACKUP, + _("Backup file creation failed")); + g_vfs_ftp_task_done (&task); } static void |