editor: Use datadir instead of tmp dir
See https://github.com/profanity-im/profanity/issues/1521#issue-860017824
This commit is contained in:
@@ -9409,12 +9409,19 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// build temp file name. Example: /tmp/profanity-f2f271dd-98c8-4118-8d47-3bd49c8e2e63.md
|
// create editor dir if not present
|
||||||
char* uuid = xmpp_uuid_gen(ctx);
|
char *jid = connection_get_barejid();
|
||||||
char* filename = g_strdup_printf("%s%s%s.md", g_get_tmp_dir(), "/profanity-", uuid);
|
gchar *path = files_get_account_data_path(DIR_EDITOR, jid);
|
||||||
if (uuid) {
|
if (g_mkdir_with_parents(path, S_IRWXU) != 0) {
|
||||||
xmpp_free(ctx, uuid);
|
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
|
// Check if file exists and create file
|
||||||
if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
|
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;
|
GError* creation_error = NULL;
|
||||||
GFile* file = g_file_new_for_path(filename);
|
GFile* file = g_file_new_for_path(filename);
|
||||||
GFileOutputStream* fos = g_file_create(file,
|
GFileOutputStream* fos = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, &creation_error);
|
||||||
G_FILE_CREATE_PRIVATE, NULL,
|
|
||||||
&creation_error);
|
free(filename);
|
||||||
|
|
||||||
if (creation_error) {
|
if (creation_error) {
|
||||||
cons_show_error("Editor: could not create temp file");
|
cons_show_error("Editor: could not create temp file");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
#define DIR_PLUGINS "plugins"
|
#define DIR_PLUGINS "plugins"
|
||||||
#define DIR_DATABASE "database"
|
#define DIR_DATABASE "database"
|
||||||
#define DIR_DOWNLOADS "downloads"
|
#define DIR_DOWNLOADS "downloads"
|
||||||
|
#define DIR_EDITOR "editor"
|
||||||
|
|
||||||
void files_create_directories(void);
|
void files_create_directories(void);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user