mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 00:03:02 +01:00
put chatlogs in their own directory
This commit is contained in:
parent
3cbe61e111
commit
c14f2a3fcd
@ -29,6 +29,7 @@
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "toxic.h"
|
||||
#include "configdir.h"
|
||||
|
||||
/* get the user's home directory */
|
||||
@ -38,9 +39,8 @@ void get_home_dir(char *home, int size)
|
||||
struct passwd *pwdbuf;
|
||||
const char *hmstr;
|
||||
char buf[NSS_BUFLEN_PASSWD];
|
||||
int rc;
|
||||
|
||||
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
|
||||
int rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
|
||||
|
||||
if (rc == 0) {
|
||||
hmstr = pwd.pw_dir;
|
||||
@ -102,30 +102,45 @@ char *get_user_config_dir(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates the config directory.
|
||||
* Creates the config and chatlog directories.
|
||||
*/
|
||||
int create_user_config_dir(char *path)
|
||||
int create_user_config_dirs(char *path)
|
||||
{
|
||||
int mkdir_err;
|
||||
|
||||
mkdir_err = mkdir(path, 0700);
|
||||
struct stat buf;
|
||||
int mkdir_err = mkdir(path, 0700);
|
||||
|
||||
if (mkdir_err && (errno != EEXIST || stat(path, &buf) || !S_ISDIR(buf.st_mode))) {
|
||||
if (mkdir_err && (errno != EEXIST || stat(path, &buf) || !S_ISDIR(buf.st_mode)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1);
|
||||
char *logpath = malloc(strlen(path) + strlen(LOGDIR) + 1);
|
||||
|
||||
if (fullpath == NULL || logpath == NULL)
|
||||
exit_toxic_err("failed in load_data_structures", FATALERR_MEMORY);
|
||||
|
||||
strcpy(fullpath, path);
|
||||
strcat(fullpath, CONFIGDIR);
|
||||
|
||||
strcpy(logpath, path);
|
||||
strcat(logpath, LOGDIR);
|
||||
|
||||
mkdir_err = mkdir(fullpath, 0700);
|
||||
|
||||
if (mkdir_err && (errno != EEXIST || stat(fullpath, &buf) || !S_ISDIR(buf.st_mode))) {
|
||||
free(fullpath);
|
||||
free(logpath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mkdir_err = mkdir(logpath, 0700);
|
||||
|
||||
if (mkdir_err && (errno != EEXIST || stat(logpath, &buf) || !S_ISDIR(buf.st_mode))) {
|
||||
free(fullpath);
|
||||
free(logpath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(logpath);
|
||||
free(fullpath);
|
||||
return 0;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#endif
|
||||
|
||||
#define CONFIGDIR "/tox/"
|
||||
#define LOGDIR "/tox/chatlogs/"
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
@ -35,6 +36,6 @@
|
||||
|
||||
char *get_user_config_dir(void);
|
||||
void get_home_dir(char *home, int size);
|
||||
int create_user_config_dir(char *path);
|
||||
int create_user_config_dirs(char *path);
|
||||
|
||||
#endif /* #define _configdir_h */
|
||||
|
@ -43,7 +43,7 @@ void init_logging_session(char *name, const char *key, struct chatlog *log)
|
||||
name = UNKNOWN_NAME;
|
||||
|
||||
char *user_config_dir = get_user_config_dir();
|
||||
int path_len = strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(name);
|
||||
int path_len = strlen(user_config_dir) + strlen(LOGDIR) + strlen(name);
|
||||
|
||||
/* use first 4 digits of key as log ident. If no key use a timestamp */
|
||||
char ident[32];
|
||||
@ -66,7 +66,7 @@ void init_logging_session(char *name, const char *key, struct chatlog *log)
|
||||
}
|
||||
|
||||
char log_path[MAX_STR_SIZE];
|
||||
snprintf(log_path, MAX_STR_SIZE, "%s%s%s-%s.log", user_config_dir, CONFIGDIR, name, ident);
|
||||
snprintf(log_path, MAX_STR_SIZE, "%s%s%s-%s.log", user_config_dir, LOGDIR, name, ident);
|
||||
|
||||
free(user_config_dir);
|
||||
|
||||
|
@ -571,7 +571,7 @@ static int init_data_files(void)
|
||||
return 0;
|
||||
|
||||
char *user_config_dir = get_user_config_dir();
|
||||
int config_err = create_user_config_dir(user_config_dir);
|
||||
int config_err = create_user_config_dirs(user_config_dir);
|
||||
|
||||
if (DATA_FILE == NULL ) {
|
||||
if (config_err) {
|
||||
|
Loading…
Reference in New Issue
Block a user