[nautilus/wip/rishi/gfile-google: 1/2] file-operations: Let directory creation/copy/move work on Google Drive



commit 06aa532fe0f40d06e19c7c100fa4fffae8f71675
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Jun 25 10:27:31 2015 +0200

    file-operations: Let directory creation/copy/move work on Google Drive
    
    Immediately check if the newly created directory is volatile or not,
    and if it is then switch to using the "real" persistent URI.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751481

 libnautilus-private/nautilus-file-operations.c |   70 +++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 1 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index e031589..893e727 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -3697,6 +3697,47 @@ is_dir (GFile *file)
        return res;
 }
 
+static GFile*
+map_possibly_volatile_file_to_real (GFile *volatile_file,
+                                   Cancellable *cancellable,
+                                   GError **error)
+{
+       GFile *real_file = NULL;
+
+#ifdef G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE
+       GFileInfo *info = NULL;
+
+       info = g_file_query_info (volatile_file,
+                                 G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK","
+                                 G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE","
+                                 G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
+                                 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                 cancellable,
+                                 error);
+       if (info == NULL) {
+               return NULL;
+       } else {
+               gboolean is_volatile;
+
+               is_volatile = g_file_info_get_attribute_boolean (info,
+                                                                G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE);
+               if (is_volatile) {
+                       const gchar *target;
+
+                       target = g_file_info_get_symlink_target (info);
+                       real_file = g_file_resolve_relative_path (volatile_file, target);
+               }
+       }
+
+       g_clear_object (&info);
+#endif /* G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE */
+
+       if (real_file == NULL)
+               real_file = g_object_ref (volatile_file);
+
+       return real_file;
+}
+
 static void copy_move_file (CopyMoveJob *job,
                            GFile *src,
                            GFile *dest_dir,
@@ -3729,6 +3770,7 @@ create_dest_dir (CommonJob *job,
        char *primary, *secondary, *details;
        int response;
        gboolean handled_invalid_filename;
+       gboolean res;
 
        handled_invalid_filename = *dest_fs_type != NULL;
 
@@ -3737,7 +3779,21 @@ create_dest_dir (CommonJob *job,
           copying the attributes, because we need to be sure we can write to it */
        
        error = NULL;
-       if (!g_file_make_directory (*dest, job->cancellable, &error)) {
+       res = g_file_make_directory (*dest, job->cancellable, &error);
+
+       if (res) {
+               GFile *real;
+
+               real = map_possibly_volatile_file_to_real (*dest, job->cancellable, &error);
+               if (real == NULL) {
+                       res = FALSE;
+               } else {
+                       g_object_unref (*dest);
+                       *dest = real;
+               }
+       }
+
+       if (!res) {
                if (IS_IO_ERROR (error, CANCELLED)) {
                        g_error_free (error);
                        return CREATE_DEST_DIR_FAILED;
@@ -6382,6 +6438,18 @@ create_job (GIOSchedulerJob *io_job,
                                             common->cancellable,
                                             &error);
 
+               if (res) {
+                       GFile *real;
+
+                       real = map_possibly_volatile_file_to_real (dest, common->cancellable, &error);
+                       if (real == NULL) {
+                               res = FALSE;
+                       } else {
+                               g_object_unref (dest);
+                               dest = real;
+                       }
+               }
+
                if (res && common->undo_info != NULL) {
                        nautilus_file_undo_info_create_set_data (NAUTILUS_FILE_UNDO_INFO_CREATE 
(common->undo_info),
                                                                 dest, NULL, 0);


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