mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-22 07:36:21 +00:00
Use files_get_account_data_path instead of duplicate code
We often had a use case where we want the account specific data dir. Let's create a function for this instead of doing it by hand each time.
This commit is contained in:
@@ -161,30 +161,26 @@ p_gpg_close(void)
|
||||
void
|
||||
p_gpg_on_connect(const char *const barejid)
|
||||
{
|
||||
char *pgpdir = files_get_data_path(DIR_PGP);
|
||||
GString *pubsfile = g_string_new(pgpdir);
|
||||
free(pgpdir);
|
||||
gchar *account_dir = str_replace(barejid, "@", "_at_");
|
||||
g_string_append(pubsfile, "/");
|
||||
g_string_append(pubsfile, account_dir);
|
||||
free(account_dir);
|
||||
gchar* pubsfile = files_get_account_data_path(DIR_PGP, barejid);
|
||||
|
||||
// mkdir if doesn't exist for account
|
||||
errno = 0;
|
||||
int res = g_mkdir_with_parents(pubsfile->str, S_IRWXU);
|
||||
int res = g_mkdir_with_parents(pubsfile, S_IRWXU);
|
||||
if (res == -1) {
|
||||
char *errmsg = strerror(errno);
|
||||
if (errmsg) {
|
||||
log_error("Error creating directory: %s, %s", pubsfile->str, errmsg);
|
||||
log_error("Error creating directory: %s, %s", pubsfile, errmsg);
|
||||
} else {
|
||||
log_error("Error creating directory: %s", pubsfile->str);
|
||||
log_error("Error creating directory: %s", pubsfile);
|
||||
}
|
||||
}
|
||||
|
||||
// create or read publickeys
|
||||
g_string_append(pubsfile, "/pubkeys");
|
||||
pubsloc = pubsfile->str;
|
||||
g_string_free(pubsfile, FALSE);
|
||||
GString *pubtmp = g_string_new(pubsfile);
|
||||
g_string_append(pubtmp, "/pubkeys");
|
||||
pubsloc = pubtmp->str;
|
||||
g_string_free(pubtmp, FALSE);
|
||||
g_free(pubsfile);
|
||||
|
||||
if (g_file_test(pubsloc, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(pubsloc, S_IRUSR | S_IWUSR);
|
||||
|
||||
Reference in New Issue
Block a user