mirror of
https://github.com/irssi/irssi.git
synced 2026-08-21 17:42:49 +02:00
xdg: add helper function to ensure dir exist
This commit is contained in:
parent
5c59b96ddd
commit
d5bcf150c1
1 changed files with 19 additions and 36 deletions
|
|
@ -762,48 +762,31 @@ static CONFIG_REC *parse_configfile(const char *fname)
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_configfile(void)
|
static void init_ensure_dir(const char *dname, int dmode)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
char *str;
|
|
||||||
|
|
||||||
if (stat(get_irssi_dir(), &statbuf) != 0) {
|
if (stat(dname, &statbuf) != 0) {
|
||||||
/* irssi folder not found, create it. */
|
/* directory not present */
|
||||||
if (g_mkdir_with_parents(get_irssi_dir(), 0700) != 0) {
|
if (g_mkdir_with_parents(dname, dmode) != 0) {
|
||||||
g_error("Couldn't create %s directory: %s",
|
g_error("Couldn't create %s directory: %s", dname, g_strerror(errno));
|
||||||
get_irssi_dir(), g_strerror(errno));
|
|
||||||
}
|
}
|
||||||
} else if (!S_ISDIR(statbuf.st_mode)) {
|
} else if (!S_ISDIR(statbuf.st_mode)) {
|
||||||
g_error("%s is not a directory.\n"
|
g_error("%s is not a directory. \n"
|
||||||
"You should remove it with command: rm %s",
|
"You should remove it with command: rm %s",
|
||||||
get_irssi_dir(), get_irssi_dir());
|
dname, dname);
|
||||||
}
|
}
|
||||||
/* check XDG path, if it is being used */
|
}
|
||||||
if (get_irssi_dir() != get_irssi_cache_dir()) {
|
|
||||||
if (stat(get_irssi_cache_dir(), &statbuf) != 0) {
|
static void init_configfile(void)
|
||||||
if (g_mkdir_with_parents(get_irssi_cache_dir(), 0700) != 0) {
|
{
|
||||||
g_error("Couldn't create %s directory: %s",
|
char *str;
|
||||||
get_irssi_cache_dir(), g_strerror(errno));
|
|
||||||
}
|
init_ensure_dir(get_irssi_dir(), 0700); /* XDG_DATA_HOME or ~/.irssi*/
|
||||||
}
|
if (get_irssi_dir() != get_irssi_cache_dir() &&
|
||||||
else if (!S_ISDIR(statbuf.st_mode)) {
|
get_irssi_dir() != get_irssi_runtime_dir()) {
|
||||||
g_error("%s is not a directory.\n"
|
init_ensure_dir(get_irssi_cache_dir(), 0700); /* XDG_CACHE_HOME */
|
||||||
"You should remove it with command: rm %s",
|
init_ensure_dir(get_irssi_runtime_dir(), 0700); /* XDG_RUNTIME_HOME */
|
||||||
get_irssi_cache_dir(), get_irssi_cache_dir());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (get_irssi_dir() != get_irssi_runtime_dir()) {
|
|
||||||
if (stat(get_irssi_runtime_dir(), &statbuf) != 0) {
|
|
||||||
if (g_mkdir_with_parents(get_irssi_runtime_dir(), 0700) != 0) {
|
|
||||||
g_error("Couldn't create %s directory: %s",
|
|
||||||
get_irssi_runtime_dir(), g_strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!S_ISDIR(statbuf.st_mode)) {
|
|
||||||
g_error("%s is not a directory.\n"
|
|
||||||
"You should remove it with command: rm %s",
|
|
||||||
get_irssi_runtime_dir(), get_irssi_runtime_dir());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mainconfig = parse_configfile(NULL);
|
mainconfig = parse_configfile(NULL);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue