[gvfs] mtp: do_open_for_read() should fail on a directory



commit 4fff3674b9c909a5d2838bdbc96ba98724d10d56
Author: Rok Mandeljc <rok mandeljc gmail com>
Date:   Mon Aug 4 21:15:33 2014 +0200

    mtp: do_open_for_read() should fail on a directory
    
    This is a fix for bug #729628: the GIO open-read-write-close
    fallback for copy/move operation on MTP volumes works correctly
    for files, but fails for directories - in particular, it creates
    a file with the destination name, then fails with "libmtp error:
    Unknown error." This happens because the fallback first attempts
    to open the source as a file, and if it succeeds, proceeds to
    create destination file and copy the contents via series of
    reads/writes.
    
    For directories, do_open_for_read() should fail with
    G_IO_ERROR_IS_DIRECTORY, which in tun causes GIO to create the
    destination as directory, and then copy its contents over.
    
    Signed-off-by: Rok Mandeljc <rok mandeljc gmail com>

 daemon/gvfsbackendmtp.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index 4d5cbf8..92c6d87 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -1921,6 +1921,14 @@ do_open_for_read (GVfsBackend *backend,
     goto exit;
   }
 
+  if (file->filetype == LIBMTP_FILETYPE_FOLDER) {
+    LIBMTP_destroy_file_t (file);
+    g_vfs_job_failed_literal (G_VFS_JOB (job),
+                              G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
+                             _("Can't open directory"));
+    goto exit;
+  }
+
   RWHandle *handle = g_new0(RWHandle, 1);
   handle->handle_type = HANDLE_FILE;
   handle->id = entry->id;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]