Skip to content

Commit

Permalink
Move all settings into a settings/ directory in showtime's persistent…
Browse files Browse the repository at this point in the history
… storage path.

Showtime will automatically upgrade the previous directory structure to this new structure.
  • Loading branch information
andoma committed Jul 18, 2011
1 parent cac754c commit 760ae2d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/arch/arch_posix.c
Expand Up @@ -346,7 +346,7 @@ arch_set_default_paths(int argc, char **argv)


snprintf(buf, sizeof(buf), "%s/.hts/showtime", homedir);
showtime_settings_path = strdup(buf);
showtime_persistent_path = strdup(buf);
}

int64_t
Expand Down
2 changes: 1 addition & 1 deletion src/arch/arch_ps3.c
Expand Up @@ -397,7 +397,7 @@ arch_set_default_paths(int argc, char **argv)
return;
x++;
strcpy(x, "settings");
showtime_settings_path = strdup(buf);
showtime_persistent_path = strdup(buf);
strcpy(x, "cache");
showtime_cache_path = strdup(buf);
}
Expand Down
38 changes: 36 additions & 2 deletions src/htsmsg/htsmsg_store.c
Expand Up @@ -34,7 +34,10 @@
#include "htsmsg_store.h"
#include "misc/callout.h"

extern char *showtime_settings_path;
#define SETTINGS_STORE_DELAY 2 // seconds

extern char *showtime_persistent_path;
static char *showtime_settings_path;

LIST_HEAD(pending_store_list, pending_store);

Expand Down Expand Up @@ -186,7 +189,37 @@ pending_store_fire(struct callout *c, void *opaque)
void
htsmsg_store_init(void)
{
char p1[PATH_MAX], p2[PATH_MAX];

hts_mutex_init(&pending_store_mutex);

if(showtime_persistent_path == NULL)
return;

snprintf(p1, sizeof(p1), "%s/settings",
showtime_persistent_path);

showtime_settings_path = strdup(p1);

if(!mkdir(p1, 0700)) {
DIR *dir;
struct dirent *d;

if((dir = opendir(showtime_persistent_path)) != NULL) {
while((d = readdir(dir)) != NULL) {
if(d->d_name[0] == '.')
continue;

snprintf(p1, sizeof(p1), "%s/%s",
showtime_persistent_path, d->d_name);

snprintf(p2, sizeof(p2), "%s/settings/%s",
showtime_persistent_path, d->d_name);

rename(p1, p2);
}
}
}
}


Expand Down Expand Up @@ -225,7 +258,8 @@ htsmsg_store_save(htsmsg_t *record, const char *pathfmt, ...)
break;

if(!callout_isarmed(&pending_store_callout))
callout_arm(&pending_store_callout, pending_store_fire, NULL, 10);
callout_arm(&pending_store_callout, pending_store_fire, NULL,
SETTINGS_STORE_DELAY);

if(ps == NULL) {
ps = malloc(sizeof(pending_store_t));
Expand Down
18 changes: 10 additions & 8 deletions src/main.c
Expand Up @@ -76,7 +76,7 @@ static int ffmpeglog;
static int showtime_retcode = 1;
const char *showtime_logtarget = SHOWTIME_DEFAULT_LOGTARGET;
char *showtime_cache_path;
char *showtime_settings_path;
char *showtime_persistent_path;

static int
fflockmgr(void **_mtx, enum AVLockOp op)
Expand Down Expand Up @@ -291,8 +291,6 @@ main(int argc, char **argv)
/* Architecture specific init */
arch_init();

htsmsg_store_init();

/* Try to create cache path */
if(showtime_cache_path != NULL &&
(r = makedirs(showtime_cache_path)) != 0) {
Expand All @@ -305,13 +303,17 @@ main(int argc, char **argv)
blobcache_init();

/* Try to create settings path */
if(showtime_settings_path != NULL &&
(r = makedirs(showtime_settings_path)) != 0) {
TRACE(TRACE_ERROR, "settings", "Unable to create settings path %s -- %s",
showtime_settings_path, strerror(r));
showtime_settings_path = NULL;
if(showtime_persistent_path != NULL &&
(r = makedirs(showtime_persistent_path)) != 0) {
TRACE(TRACE_ERROR, "settings",
"Unable to create path for persistent storage %s -- %s",
showtime_persistent_path, strerror(r));
showtime_persistent_path = NULL;
}

/* Initialize htsmsg_store() */
htsmsg_store_init();

/* Initialize keyring */
keyring_init();

Expand Down
2 changes: 1 addition & 1 deletion src/showtime.h
Expand Up @@ -150,7 +150,7 @@ void *shutdown_hook_add(void (*fn)(void *opaque, int exitcode), void *opaque,
#define SHOWTIME_EXIT_POWEROFF 11

extern char *showtime_cache_path;
extern char *showtime_settings_path;
extern char *showtime_persistent_path;


/* From version.c */
Expand Down

0 comments on commit 760ae2d

Please sign in to comment.