summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2013-03-20 09:11:14 -0700
committerPhilip Langdale <philipl@overt.org>2013-03-30 16:25:53 -0700
commitd31ebff2b2d9a44f380ada8887c77dfdee770eb5 (patch)
treee21181d8400c4c9cf2491806f4501168d2a5bbb8
parent30ca34dfd2a4c2f86a906d9bdea75adf8d4a73f4 (diff)
downloadgvfs-d31ebff2b2d9a44f380ada8887c77dfdee770eb5.tar.gz
MTP: Handle overwriting of files in do_push correctly.
If a file copy is requested without OVERWRITE but the destination exists, return G_IO_ERROR_EXISTS. If OVERWRITE is requested, then delete the destination before the push. https://bugzilla.gnome.org/show_bug.cgi?id=696163
-rw-r--r--daemon/gvfsbackendmtp.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index 212aff6d..ba260b64 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -1513,7 +1513,29 @@ do_push (GVfsBackend *backend,
LIBMTP_mtpdevice_t *device;
device = G_VFS_BACKEND_MTP (backend)->device;
- CacheEntry *entry = get_cache_entry (G_VFS_BACKEND_MTP (backend), dir_name);
+ CacheEntry *entry = get_cache_entry (G_VFS_BACKEND_MTP (backend), destination);
+ if (entry != NULL && entry->id != -1) {
+ if (flags & G_FILE_COPY_OVERWRITE) {
+ DEBUG ("(I) Removing destination.");
+ int ret = LIBMTP_Delete_Object (device, entry->id);
+ if (ret != 0) {
+ fail_job (G_VFS_JOB (job), device);
+ goto exit;
+ }
+ g_hash_table_foreach (G_VFS_BACKEND_MTP (backend)->monitors,
+ emit_delete_event,
+ (char *)destination);
+ remove_cache_entry (G_VFS_BACKEND_MTP (backend),
+ destination);
+ } else {
+ g_vfs_job_failed_literal (G_VFS_JOB (job),
+ G_IO_ERROR, G_IO_ERROR_EXISTS,
+ _("File already exists"));
+ goto exit;
+ }
+ }
+
+ entry = get_cache_entry (G_VFS_BACKEND_MTP (backend), dir_name);
if (!entry) {
g_vfs_job_failed_literal (G_VFS_JOB (job),
G_IO_ERROR, G_IO_ERROR_NOT_FOUND,