]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
DVR: Improve dvr_storage check and initialization
authorJaroslav Kysela <perex@perex.cz>
Wed, 13 May 2015 18:42:46 +0000 (20:42 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 14 May 2015 06:47:41 +0000 (08:47 +0200)
src/dvr/dvr_config.c
src/dvr/dvr_rec.c

index cdc3a837c066a6e8ac4435fab5196d72da933373..62bb984b20bf5166bb9032ac3fab865036ea36bf 100644 (file)
@@ -257,6 +257,43 @@ dvr_config_destroy(dvr_config_t *cfg, int delconf)
   free(cfg);
 }
 
+/**
+ *
+ */
+
+static void
+dvr_config_storage_check(dvr_config_t *cfg)
+{
+  char buf[PATH_MAX];
+  struct stat st;
+  const char *homedir;
+
+  if(cfg->dvr_storage != NULL && cfg->dvr_storage[0])
+    return;
+
+  /* Try to figure out a good place to put them videos */
+
+  homedir = getenv("HOME");
+
+  if(homedir != NULL) {
+    snprintf(buf, sizeof(buf), "%s/Videos", homedir);
+    if(stat(buf, &st) == 0 && S_ISDIR(st.st_mode))
+      cfg->dvr_storage = strdup(buf);
+
+    else if(stat(homedir, &st) == 0 && S_ISDIR(st.st_mode))
+      cfg->dvr_storage = strdup(homedir);
+    else
+      cfg->dvr_storage = strdup(getcwd(buf, sizeof(buf)));
+  }
+
+  tvhlog(LOG_WARNING, "dvr",
+         "Output directory for video recording is not yet configured "
+         "for DVR configuration \"%s\". "
+         "Defaulting to to \"%s\". "
+         "This can be changed from the web user interface.",
+         cfg->dvr_config_name, cfg->dvr_storage);
+}
+
 /**
  *
  */
@@ -282,6 +319,7 @@ dvr_config_save(dvr_config_t *cfg)
 
   lock_assert(&global_lock);
 
+  dvr_config_storage_check(cfg);
   idnode_save(&cfg->dvr_id, m);
   hts_settings_save(m, "dvr/config/%s", idnode_uuid_as_str(&cfg->dvr_id));
   htsmsg_destroy(m);
@@ -753,9 +791,6 @@ dvr_config_init(void)
 {
   htsmsg_t *m, *l;
   htsmsg_field_t *f;
-  char buf[500];
-  const char *homedir;
-  struct stat st;
   dvr_config_t *cfg;
 
   dvr_iov_max = sysconf(_SC_IOV_MAX);
@@ -777,31 +812,8 @@ dvr_config_init(void)
   cfg = dvr_config_find_by_name_default(NULL);
   assert(cfg);
 
-  LIST_FOREACH(cfg, &dvrconfigs, config_link) {
-    if(cfg->dvr_storage == NULL || !strlen(cfg->dvr_storage)) {
-      /* Try to figure out a good place to put them videos */
-
-      homedir = getenv("HOME");
-
-      if(homedir != NULL) {
-        snprintf(buf, sizeof(buf), "%s/Videos", homedir);
-        if(stat(buf, &st) == 0 && S_ISDIR(st.st_mode))
-          cfg->dvr_storage = strdup(buf);
-        
-        else if(stat(homedir, &st) == 0 && S_ISDIR(st.st_mode))
-          cfg->dvr_storage = strdup(homedir);
-        else
-          cfg->dvr_storage = strdup(getcwd(buf, sizeof(buf)));
-      }
-
-      tvhlog(LOG_WARNING, "dvr",
-             "Output directory for video recording is not yet configured "
-             "for DVR configuration \"%s\". "
-             "Defaulting to to \"%s\". "
-             "This can be changed from the web user interface.",
-             cfg->dvr_config_name, cfg->dvr_storage);
-    }
-  }
+  LIST_FOREACH(cfg, &dvrconfigs, config_link)
+    dvr_config_storage_check(cfg);
 }
 
 void
index 62b3301d9e2ff81d2fd62cb59cb6751ba71478e5..617a3a2a97cd407c0c7f46f0225a1e4053449b30 100644 (file)
@@ -204,6 +204,8 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
     return -1;
 
   cfg = de->de_config;
+  if (cfg->dvr_storage == NULL || cfg->dvr_storage == '\0')
+    return -1;
   strncpy(path, cfg->dvr_storage, sizeof(path));
   path[sizeof(path)-1] = '\0';