[snappy] snappy: don't assume config folder is available



commit a8269be8ac223a6b1e98098969ff3b52b02e086e
Author: Luis de Bethencourt <luis debethencourt com>
Date:   Fri Aug 10 19:05:39 2012 +0100

    snappy: don't assume config folder is available
    
    If history file can't be open error properly. If the config folder
    isn't available create it.

 src/gst_engine.c |   13 +++++++++++++
 src/snappy.c     |   19 +++++++++++--------
 2 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/src/gst_engine.c b/src/gst_engine.c
index 8437e99..a09a82b 100644
--- a/src/gst_engine.c
+++ b/src/gst_engine.c
@@ -360,6 +360,19 @@ remove_uri_unfinished_playback (GstEngine * engine, gchar * uri)
 
   /* Config file path */
   config_dir = g_get_user_config_dir ();
+
+  /* Self config directory, i.e. .config/snappy/ */
+  struct stat st_self;
+  if ( 0 != stat(g_strdup_printf("%s/snappy", config_dir), &st_self)) {
+     if ( 0 != mkdir( g_strdup_printf("%s/snappy", config_dir), 0777))
+       perror("Failed to create ~/.config/snappy/ directory");
+  }
+  else if (!S_ISDIR(st_self.st_mode)) {
+     errno = ENOTDIR;
+     perror("~/config/snappy/ already exists");
+  }
+
+  /* History file */
   path = g_strdup_printf ("%s/snappy/history", config_dir);
 
   /* Remove key from history file */
diff --git a/src/snappy.c b/src/snappy.c
index d8d499c..5df3994 100644
--- a/src/snappy.c
+++ b/src/snappy.c
@@ -110,16 +110,19 @@ process_args (int argc, char *argv[],
   /* Recently viewed uris */
   if (recent) {
     gchar **recent = NULL;
-
-    g_print ("These are the recently viewed URIs: \n\n");
-
     recent = get_recently_viewed ();
 
-    for (c = 0; recent[c] != NULL; c++) {
-      if (c < 9)
-        g_print ("0%d: %s \n", c + 1, recent[c]);
-      else
-        g_print ("%d: %s \n", c + 1, recent[c]);
+    if (recent) {
+      g_print ("These are the recently viewed URIs: \n\n");
+
+      for (c = 0; recent[c] != NULL; c++) {
+        if (c < 9)
+          g_print ("0%d: %s \n", c + 1, recent[c]);
+        else
+          g_print ("%d: %s \n", c + 1, recent[c]);
+      }
+    } else {
+      g_print ("ERROR: Can't find history of recently viewed URIs\n");
     }
 
     return NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]