ges-formatter: Check if directory of URI is writeable
authorPaul Lange <palango@gmx.de>
Fri, 20 Jul 2012 12:19:01 +0000 (14:19 +0200)
committerThibault Saunier <thibault.saunier@collabora.com>
Mon, 19 Aug 2013 19:18:06 +0000 (15:18 -0400)
https://bugzilla.gnome.org/show_bug.cgi?id=679941

ges/ges-formatter.c

index bab0e0e..7d0751b 100644 (file)
@@ -276,6 +276,10 @@ ges_formatter_can_load_uri (const gchar * uri, GError ** error)
 gboolean
 ges_formatter_can_save_uri (const gchar * uri, GError ** error)
 {
+  GFile *file = NULL;
+  GFile *dir = NULL;
+  GFileInfo *info = NULL;
+
   if (!(gst_uri_is_valid (uri))) {
     GST_ERROR ("%s invalid uri!", uri);
     return FALSE;
@@ -288,6 +292,39 @@ ges_formatter_can_save_uri (const gchar * uri, GError ** error)
     return FALSE;
   }
 
+  /* Check if URI or parent directory is writeable */
+  file = g_file_new_for_uri (uri);
+
+  if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL)
+      == G_FILE_TYPE_DIRECTORY) {
+    dir = file;
+  } else {
+    dir = g_file_get_parent (file);
+
+    if (dir == NULL)
+      return FALSE;
+  }
+
+  info = g_file_query_info (dir, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+      G_FILE_QUERY_INFO_NONE, NULL, error);
+
+  if (error && *error != NULL) {
+    GST_ERROR ("Unable to write to directory: %s", (*error)->message);
+
+    return FALSE;
+  } else {
+    gboolean writeable = g_file_info_get_attribute_boolean (info,
+        G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+    if (!writeable) {
+      GST_ERROR ("Unable to write to directory");
+      return FALSE;
+    }
+  }
+
+  g_object_unref (file);
+  g_object_unref (dir);
+  g_object_unref (info);
+
   /* TODO: implement file format registry */
   /* TODO: search through the registry and chose a GESFormatter class that can
    * handle the URI.*/