[Pkg-wmaker-commits] [wmforecast] 26/63: fixed bug where wmforecastrc was not created when its directory didn't exist yet

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 17 11:20:34 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmforecast.

commit 74d1a007f9536adc1386a48a08a6f93a860a17f9
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date:   Thu May 8 22:15:49 2014 -0500

    fixed bug where wmforecastrc was not created when its directory didn't exist yet
---
 ChangeLog    |  8 ++++++++
 wmforecast.c | 35 ++++++++++++++++++++++++-----------
 2 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 28b62f9..3395c29 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-05-08  Doug Torrance <dtorrance at monmouthcollege.edu>
+	* wmforecast.c (getPreferencesDirectory): new function to get directory
+	  of wmforecastrc file
+	* wmforecast.c (getPreferencesFilename): now uses getPreferencesDirectory
+	* wmforecast.c (savePreferences): now calls mkdir to create the directory
+	  containing wmforecastrc; this fixes a bug where the wmforecastrc file
+	  was not created when the directory did not exist yet
+
 2014-05-07  Doug Torrance <dtorrance at monmouthcollege.edu>
 	* wmforecast.c (Dockapp): combined with old UpdateData struct to better
 	  facilitate new feature:
diff --git a/wmforecast.c b/wmforecast.c
index 0276315..d6f000c 100755
--- a/wmforecast.c
+++ b/wmforecast.c
@@ -19,12 +19,14 @@
 #include <config.h>
 #endif
 
-#include <WINGs/WINGs.h>
-#include <stdio.h>
-#include <string.h>
 #include <curl/curl.h>
-#include <libxml/tree.h>
 #include <getopt.h>
+#include <libgen.h>
+#include <libxml/tree.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <WINGs/WINGs.h>
 
 #define color(c) WMCreateNamedColor(screen,c,True)
 
@@ -506,14 +508,22 @@ char *WMGetPLStringForKey(WMPropList *propList, char *key)
 		return NULL;
 }
 
+char *getPreferencesDirectory()
+{
+	char *dir;
+	dir = getenv("XDG_CONFIG_DIR");
+	if (!dir)
+		dir = wstrconcat(getenv("HOME"), "/.config");
+	dir = wstrconcat(dir, "/wmforecast");
+	return dir;
+}
+
 char *getPreferencesFilename()
 {
 	char *filename;
 
-	filename = getenv("XDG_CONFIG_DIR");
-	if (!filename)
-		filename = wstrconcat(getenv("HOME"), "/.config");
-	filename = wstrappend(filename, "/wmforecast/wmforecastrc");
+	filename = getPreferencesDirectory();
+	filename = wstrappend(filename, "/wmforecastrc");
 
 	return filename;
 }
@@ -675,6 +685,7 @@ static void closePreferences(WMWidget *widget, void *data)
 
 static void savePreferences(WMWidget *widget, void *data)
 {
+	char *dir;
 	char *filename;
 	char *prefsString;
 	Dockapp *d = (Dockapp *)data;
@@ -717,12 +728,14 @@ static void savePreferences(WMWidget *widget, void *data)
 	object = WMCreatePLString(WMGetTextFieldText(d->prefsWindow->interval));
 	WMPutInPLDictionary(prefsPL, key, object);
 	
+	// since WMWritePropListToFile only writes to files in 
+	// GNUSTEP_USER_ROOT, we need to write our own version
 	prefsString = WMGetPropListDescription(prefsPL, True);
 
-	filename = getPreferencesFilename();
+	dir = getPreferencesDirectory();
+	mkdir(dir, 0777);
 
-	// since WMWritePropListToFile only writes to files in 
-	// GNUSTEP_USER_ROOT, we need to write our own version
+	filename = getPreferencesFilename();
 	file = fopen(filename, "w");
 	if (file)
 	{

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmforecast.git



More information about the Pkg-wmaker-commits mailing list