changeset 1637:80ba6b99478f

make sure that a directory exists on saving desktop files
author nadvornik
date Wed, 10 Jun 2009 20:45:24 +0000
parents c0f6a98c9204
children ceafe3731568
files src/desktop_file.c
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/desktop_file.c	Wed Jun 10 20:26:47 2009 +0000
+++ b/src/desktop_file.c	Wed Jun 10 20:45:24 2009 +0000
@@ -59,6 +59,7 @@
 
 static gboolean editor_window_save(EditorWindow *ew)
 {
+	gchar *dir;
 	gchar *path;
 	gchar *text;
 	GtkTextIter start, end;
@@ -75,9 +76,16 @@
 	gtk_text_buffer_get_bounds(ew->buffer, &start, &end);
 	text = gtk_text_buffer_get_text(ew->buffer, &start, &end, FALSE);
 
-	path = g_build_filename(get_rc_dir(), "applications", name, NULL);
+	dir = g_build_filename(get_rc_dir(), "applications", NULL);
+	path = g_build_filename(dir, name, NULL);
 
-	if (!g_file_set_contents(path, text, -1, &error)) 
+	if (!recursive_mkdir_if_not_exists(dir, 0755))
+		{
+		file_util_warning_dialog(_("Can't save"), _("Could not create directory"), GTK_STOCK_DIALOG_ERROR, NULL);
+		ret = FALSE;
+		}
+
+	if (ret && !g_file_set_contents(path, text, -1, &error)) 
 		{
 		file_util_warning_dialog(_("Can't save"), error->message, GTK_STOCK_DIALOG_ERROR, NULL);
 		g_error_free(error);
@@ -85,6 +93,7 @@
 		}
 	
 	g_free(path);
+	g_free(dir);
 	g_free(text);
 	layout_editors_reload_all();
 	return ret;