gboolean
rb_uri_create_parent_dirs (const char *uri, GError **error)
{
	GFile *file;
	GFile *parent;
	gboolean ret;
#if !GLIB_CHECK_VERSION(2,17,1)
	GError *l_error = NULL;
#endif

	file = g_file_new_for_uri (uri);
	parent = g_file_get_parent (file);
	g_object_unref (file);
	if (parent == NULL) {
		/* now what? */
		return TRUE;
	}

#if GLIB_CHECK_VERSION(2,17,1)
	ret = check_file_is_directory (parent, error);
	if (ret == FALSE && *error == NULL) {
		ret = g_file_make_directory_with_parents (parent, NULL, error);
	}
#else
	ret = create_parent_dirs (parent, &l_error);

	if (l_error != NULL) {
		g_propagate_error (error, l_error);
	}
#endif
	g_object_unref (parent);
	return ret;
}
Exemplo n.º 2
0
/**
 * rb_uri_create_parent_dirs:
 * @uri: a URI for which to create parent directories
 * @error: returns error information
 *
 * Ensures that all parent directories of @uri exist so that
 * @uri itself can be created directly.
 *
 * Return value: %TRUE if successful
 */
gboolean
rb_uri_create_parent_dirs (const char *uri, GError **error)
{
	GFile *file;
	GFile *parent;
	gboolean ret;

	/* ignore internal URI schemes */
	if (g_str_has_prefix (uri, "xrb")) {
		return TRUE;
	}

	file = g_file_new_for_uri (uri);
	parent = g_file_get_parent (file);
	g_object_unref (file);
	if (parent == NULL) {
		/* now what? */
		return TRUE;
	}

	ret = check_file_is_directory (parent, error);
	if (ret == FALSE && *error == NULL) {
		ret = g_file_make_directory_with_parents (parent, NULL, error);
	}

	g_object_unref (parent);
	return ret;
}
static gboolean
create_parent_dirs (GFile *file, GError **error)
{
	gboolean ret;
	GFile *parent;

	ret = check_file_is_directory (file, error);
	if (ret == TRUE || *error != NULL) {
		return ret;
	}

	parent = g_file_get_parent (file);
	ret = create_parent_dirs (parent, error);
	g_object_unref (parent);
	if (ret == FALSE) {
		return FALSE;
	}

	return g_file_make_directory (file, NULL, error);
}