Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: Improve dvr_storage check and initialization
  • Loading branch information
perexg committed May 14, 2015
1 parent 231274e commit f8e5548
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
68 changes: 40 additions & 28 deletions src/dvr/dvr_config.c
Expand Up @@ -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);
}

/**
*
*/
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/dvr/dvr_rec.c
Expand Up @@ -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';

Expand Down

0 comments on commit f8e5548

Please sign in to comment.