Commit 2bdc1938 authored by Sébastien Wilmet's avatar Sébastien Wilmet

Backport latexila_utils_create_parent_directories()

parent 86fe192f
......@@ -241,4 +241,5 @@ latexila_utils_str_replace
latexila_utils_file_query_exists_async
latexila_utils_file_query_exists_finish
latexila_utils_show_uri
latexila_utils_create_parent_directories
</SECTION>
......@@ -336,3 +336,49 @@ latexila_utils_show_uri (GdkScreen *screen,
g_free (extension);
}
}
/**
* latexila_utils_create_parent_directories:
* @file: a file
* @error: (out) (optional): a location to a %NULL #GError, or %NULL.
*
* Synchronously creates parent directories of @file, so that @file can be
* saved.
*
* Returns: whether the directories are correctly created. %FALSE is returned on
* error.
*/
gboolean
latexila_utils_create_parent_directories (GFile *file,
GError **error)
{
GFile *parent;
GError *my_error = NULL;
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
parent = g_file_get_parent (file);
if (parent == NULL)
return TRUE;
g_file_make_directory_with_parents (parent, NULL, &my_error);
g_object_unref (parent);
if (my_error != NULL)
{
if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
{
g_error_free (my_error);
return TRUE;
}
else
{
g_propagate_error (error, my_error);
return FALSE;
}
}
return TRUE;
}
......@@ -52,6 +52,9 @@ void latexila_utils_show_uri (GdkScreen *s
guint32 timestamp,
GError **error);
gboolean latexila_utils_create_parent_directories (GFile *file,
GError **error);
G_END_DECLS
#endif /* __LATEXILA_UTILS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment