mirror of
https://github.com/transmission/transmission
synced 2025-03-10 06:02:57 +00:00
Instead of storing files specific to the gtk frontend directly
in ~/.transmission/, store them in a gtk subdirectory.
This commit is contained in:
parent
c6afb1c534
commit
6e9f6ec11e
1 changed files with 44 additions and 27 deletions
71
gtk/conf.c
71
gtk/conf.c
|
@ -42,11 +42,15 @@
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define FILE_LOCK "gtk_lock"
|
#define CONF_SUBDIR "gtk"
|
||||||
#define FILE_PREFS "gtk_prefs"
|
#define FILE_LOCK "lock"
|
||||||
#define FILE_PREFS_TMP "gtk_prefs.tmp"
|
#define FILE_PREFS "prefs"
|
||||||
#define FILE_STATE "gtk_state"
|
#define FILE_PREFS_TMP "prefs.tmp"
|
||||||
#define FILE_STATE_TMP "gtk_state.tmp"
|
#define FILE_STATE "state"
|
||||||
|
#define FILE_STATE_TMP "state.tmp"
|
||||||
|
#define OLD_FILE_LOCK "gtk_lock" /* remove this after next release */
|
||||||
|
#define OLD_FILE_PREFS "gtk_prefs"
|
||||||
|
#define OLD_FILE_STATE "gtk_state"
|
||||||
#define PREF_SEP_KEYVAL '\t'
|
#define PREF_SEP_KEYVAL '\t'
|
||||||
#define PREF_SEP_LINE '\n'
|
#define PREF_SEP_LINE '\n'
|
||||||
#define STATE_SEP '\n'
|
#define STATE_SEP '\n'
|
||||||
|
@ -59,6 +63,7 @@ static char *
|
||||||
getstateval(struct cf_torrentstate *state, char *line);
|
getstateval(struct cf_torrentstate *state, char *line);
|
||||||
|
|
||||||
static char *confdir = NULL;
|
static char *confdir = NULL;
|
||||||
|
static char *old_confdir = NULL;
|
||||||
static GTree *prefs = NULL;
|
static GTree *prefs = NULL;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -99,37 +104,29 @@ lockfile(const char *file, char **errstr) {
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
cf_init(const char *dir, char **errstr) {
|
cf_init(const char *dir, char **errstr) {
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
*errstr = NULL;
|
*errstr = NULL;
|
||||||
confdir = g_strdup(dir);
|
old_confdir = g_strdup(dir);
|
||||||
|
confdir = g_build_filename(dir, CONF_SUBDIR, NULL);
|
||||||
|
|
||||||
if(0 > stat(dir, &sb)) {
|
if(mkdir_p(confdir, 0777))
|
||||||
if(ENOENT != errno)
|
|
||||||
*errstr = g_strdup_printf(_("Failed to check the directory %s:\n%s"),
|
|
||||||
dir, strerror(errno));
|
|
||||||
else {
|
|
||||||
if(0 == mkdir(dir, 0777))
|
|
||||||
return TRUE;
|
|
||||||
else
|
|
||||||
*errstr = g_strdup_printf(_("Failed to create the directory %s:\n%s"),
|
|
||||||
dir, strerror(errno));
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(S_IFDIR & sb.st_mode)
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
*errstr = g_strdup_printf(_("%s is not a directory"), dir);
|
*errstr = g_strdup_printf(_("Failed to create the directory %s:\n%s"),
|
||||||
|
confdir, strerror(errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
cf_lock(char **errstr) {
|
cf_lock(char **errstr) {
|
||||||
char *path = g_build_filename(confdir, FILE_LOCK, NULL);
|
char *path = g_build_filename(old_confdir, OLD_FILE_LOCK, NULL);
|
||||||
int fd = lockfile(path, errstr);
|
int fd = lockfile(path, errstr);
|
||||||
|
|
||||||
|
if(0 <= fd) {
|
||||||
|
g_free(path);
|
||||||
|
path = g_build_filename(confdir, FILE_LOCK, NULL);
|
||||||
|
fd = lockfile(path, errstr);
|
||||||
|
}
|
||||||
|
|
||||||
g_free(path);
|
g_free(path);
|
||||||
return 0 <= fd;
|
return 0 <= fd;
|
||||||
}
|
}
|
||||||
|
@ -137,6 +134,7 @@ cf_lock(char **errstr) {
|
||||||
gboolean
|
gboolean
|
||||||
cf_loadprefs(char **errstr) {
|
cf_loadprefs(char **errstr) {
|
||||||
char *path = g_build_filename(confdir, FILE_PREFS, NULL);
|
char *path = g_build_filename(confdir, FILE_PREFS, NULL);
|
||||||
|
char *oldpath;
|
||||||
GIOChannel *io;
|
GIOChannel *io;
|
||||||
GError *err;
|
GError *err;
|
||||||
char *line, *sep;
|
char *line, *sep;
|
||||||
|
@ -157,7 +155,15 @@ cf_loadprefs(char **errstr) {
|
||||||
if(!g_error_matches(err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
|
if(!g_error_matches(err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
|
||||||
*errstr = g_strdup_printf(
|
*errstr = g_strdup_printf(
|
||||||
_("Failed to open the file %s for reading:\n%s"), path, err->message);
|
_("Failed to open the file %s for reading:\n%s"), path, err->message);
|
||||||
goto done;
|
else {
|
||||||
|
g_error_free(err);
|
||||||
|
err = NULL;
|
||||||
|
oldpath = g_build_filename(old_confdir, OLD_FILE_PREFS, NULL);
|
||||||
|
io = g_io_channel_new_file(oldpath, "r", &err);
|
||||||
|
g_free(oldpath);
|
||||||
|
}
|
||||||
|
if(NULL != err)
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
g_io_channel_set_line_term(io, &term, 1);
|
g_io_channel_set_line_term(io, &term, 1);
|
||||||
|
|
||||||
|
@ -193,6 +199,7 @@ cf_loadprefs(char **errstr) {
|
||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
if(NULL != io)
|
if(NULL != io)
|
||||||
g_io_channel_unref(io);
|
g_io_channel_unref(io);
|
||||||
|
g_free(path);
|
||||||
return NULL == *errstr;
|
return NULL == *errstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,6 +313,7 @@ writefile_traverse(gpointer key, gpointer value, gpointer data) {
|
||||||
GList *
|
GList *
|
||||||
cf_loadstate(char **errstr) {
|
cf_loadstate(char **errstr) {
|
||||||
char *path = g_build_filename(confdir, FILE_STATE, NULL);
|
char *path = g_build_filename(confdir, FILE_STATE, NULL);
|
||||||
|
char *oldpath;
|
||||||
GIOChannel *io;
|
GIOChannel *io;
|
||||||
GError *err;
|
GError *err;
|
||||||
char term = STATE_SEP;
|
char term = STATE_SEP;
|
||||||
|
@ -320,7 +328,15 @@ cf_loadstate(char **errstr) {
|
||||||
if(!g_error_matches(err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
|
if(!g_error_matches(err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
|
||||||
*errstr = g_strdup_printf(
|
*errstr = g_strdup_printf(
|
||||||
_("Failed to open the file %s for reading:\n%s"), path, err->message);
|
_("Failed to open the file %s for reading:\n%s"), path, err->message);
|
||||||
goto done;
|
else {
|
||||||
|
g_error_free(err);
|
||||||
|
err = NULL;
|
||||||
|
oldpath = g_build_filename(old_confdir, OLD_FILE_STATE, NULL);
|
||||||
|
io = g_io_channel_new_file(oldpath, "r", &err);
|
||||||
|
g_free(oldpath);
|
||||||
|
}
|
||||||
|
if(NULL != err)
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
g_io_channel_set_line_term(io, &term, 1);
|
g_io_channel_set_line_term(io, &term, 1);
|
||||||
|
|
||||||
|
@ -365,6 +381,7 @@ cf_loadstate(char **errstr) {
|
||||||
g_list_free(ret);
|
g_list_free(ret);
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
}
|
}
|
||||||
|
g_free(path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue