[gnome-builder/gnome-builder-3-30] buffers: create the directory tree before saving



commit 2670d7f62c75c5979633e7ec16694dcf7b833140
Author: Christian Hergert <chergert redhat com>
Date:   Sun Oct 7 23:38:48 2018 -0700

    buffers: create the directory tree before saving
    
    In case the user moved the directory out from under Builder, we should
    recreate all of the directories needed to be able to save the file.
    
    It would be nice to make this async in the future, but there is not
    currently a variant of this API that is async.
    
    Fixes #659

 src/libide/buffers/ide-buffer-manager.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/src/libide/buffers/ide-buffer-manager.c b/src/libide/buffers/ide-buffer-manager.c
index fc969e8ec..2f37d38e9 100644
--- a/src/libide/buffers/ide-buffer-manager.c
+++ b/src/libide/buffers/ide-buffer-manager.c
@@ -1166,6 +1166,24 @@ ide_buffer_manager_save_file_async (IdeBufferManager     *self,
       IDE_EXIT;
     }
 
+  /*
+   * In-case the directory for the file does not exist yet, or has been moved
+   * since we saved things locally, create the directory chain.
+   */
+  {
+    GFile *gfile = ide_file_get_file (file);
+    g_autoptr(GFile) parent = g_file_get_parent (gfile);
+    g_autoptr(GError) error = NULL;
+
+    /* It would be nice to do this async in the future... */
+    if (!g_file_make_directory_with_parents (parent, cancellable, &error) &&
+        !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+      {
+        ide_task_return_error (task, g_steal_pointer (&error));
+        IDE_EXIT;
+      }
+  }
+
   context = ide_object_get_context (IDE_OBJECT (self));
   ide_context_hold_for_object (context, task);
 


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