about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-06-10 16:51:28 +0200
committerMichael Vetter <jubalh@iodoru.org>2021-06-10 16:51:28 +0200
commit242381cfd012edbba3f502aaa287aa4a3806dddf (patch)
tree207ea06e1acc2dc7762e32a9c9fd90a8353fe29a
parentd80d3dd5aa0cd2afafbd29246a2cefb7d0611560 (diff)
downloadprofani-tty-242381cfd012edbba3f502aaa287aa4a3806dddf.tar.gz
editor: Use datadir instead of tmp dir
See
https://github.com/profanity-im/profanity/issues/1521#issue-860017824
-rw-r--r--src/command/cmd_funcs.c24
-rw-r--r--src/config/files.h1
2 files changed, 17 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;
diff --git a/src/config/files.h b/src/config/files.h
index 42499663..a6b5a730 100644
--- a/src/config/files.h
+++ b/src/config/files.h
@@ -58,6 +58,7 @@
 #define DIR_PLUGINS   "plugins"
 #define DIR_DATABASE  "database"
 #define DIR_DOWNLOADS "downloads"
+#define DIR_EDITOR    "editor"
 
 void files_create_directories(void);