diff options
author | Michael Vetter <jubalh@iodoru.org> | 2021-06-10 16:51:28 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2021-06-10 16:51:28 +0200 |
commit | 242381cfd012edbba3f502aaa287aa4a3806dddf (patch) | |
tree | 207ea06e1acc2dc7762e32a9c9fd90a8353fe29a /src/command | |
parent | d80d3dd5aa0cd2afafbd29246a2cefb7d0611560 (diff) | |
download | profani-tty-242381cfd012edbba3f502aaa287aa4a3806dddf.tar.gz |
editor: Use datadir instead of tmp dir
See https://github.com/profanity-im/profanity/issues/1521#issue-860017824
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_funcs.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 8282a134..0e2deba9 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9409,12 +9409,19 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args) return TRUE; } - // build temp file name. Example: /tmp/profanity-f2f271dd-98c8-4118-8d47-3bd49c8e2e63.md - char* uuid = xmpp_uuid_gen(ctx); - char* filename = g_strdup_printf("%s%s%s.md", g_get_tmp_dir(), "/profanity-", uuid); - if (uuid) { - xmpp_free(ctx, uuid); + // create editor dir if not present + char *jid = connection_get_barejid(); + gchar *path = files_get_account_data_path(DIR_EDITOR, jid); + if (g_mkdir_with_parents(path, S_IRWXU) != 0) { + cons_show_error("Failed to create directory at '%s' with error '%s'", path, strerror(errno)); + free(jid); + g_free(path); + return TRUE; } + // build temp file name. Example: /home/user/.local/share/profanity/editor/jid/compose.md + char* filename = g_strdup_printf("%s/compose.md", path); + free(jid); + g_free(path); // Check if file exists and create file if (g_file_test(filename, G_FILE_TEST_EXISTS)) { @@ -9424,9 +9431,10 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args) GError* creation_error = NULL; GFile* file = g_file_new_for_path(filename); - GFileOutputStream* fos = g_file_create(file, - G_FILE_CREATE_PRIVATE, NULL, - &creation_error); + GFileOutputStream* fos = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, &creation_error); + + free(filename); + if (creation_error) { cons_show_error("Editor: could not create temp file"); return TRUE; |