Kaydet (Commit) 991a6c78 authored tarafından Enrico Tröger's avatar Enrico Tröger

Create tagmanager status file in configuration directory, not in a guessed…

Create tagmanager status file in configuration directory, not in a guessed temporary directory to ensure having write access. Fix crashes if status file can't be written.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2000 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst deb7a04d
......@@ -1725,7 +1725,10 @@ void document_set_font(gint idx, const gchar *font_name, gint size)
void document_update_tag_list(gint idx, gboolean update)
{
gboolean success = FALSE;
if (app->tm_workspace == NULL)
return;
// if the filetype doesn't have a tag parser or it is a new file
if (idx == -1 || doc_list[idx].file_type == NULL ||
! filetype_has_tags(doc_list[idx].file_type) || ! doc_list[idx].file_name)
......@@ -1748,7 +1751,12 @@ void document_update_tag_list(gint idx, gboolean update)
#endif
if (doc_list[idx].tm_file)
{
tm_workspace_add_object(doc_list[idx].tm_file);
if (!tm_workspace_add_object(doc_list[idx].tm_file))
{
tm_work_object_free(doc_list[idx].tm_file);
doc_list[idx].tm_file = NULL;
return;
}
if (update)
tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE);
success = TRUE;
......
......@@ -277,7 +277,7 @@ static void main_init(void)
prefs.tab_order_ltr = FALSE;
main_status.quitting = FALSE;
app->ignore_callback = FALSE;
app->tm_workspace = tm_get_workspace();
app->tm_workspace = tm_get_workspace(app->configdir);
ui_prefs.recent_queue = g_queue_new();
main_status.opening_session_files = FALSE;
......
......@@ -92,7 +92,8 @@ void symbols_global_tags_loaded(gint file_type_idx)
TagFileInfo *tfi;
gint tag_type;
if (cl_options.ignore_global_tags) return;
if (cl_options.ignore_global_tags || app->tm_workspace == NULL)
return;
load_user_tags(file_type_idx);
......@@ -273,7 +274,7 @@ static TMTag *find_workspace_tag(const gchar *tag_name, gint type)
const GPtrArray *tags;
TMTag *tmtag;
if (app->tm_workspace->work_objects != NULL)
if (app->tm_workspace != NULL && app->tm_workspace->work_objects != NULL)
{
for (j = 0; j < app->tm_workspace->work_objects->len; j++)
{
......@@ -897,7 +898,7 @@ int symbols_generate_global_tags(int argc, char **argv, gboolean want_preprocess
command = NULL; // don't preprocess
geany_debug("Generating %s tags file.", ft->name);
status = tm_workspace_create_global_tags(command,
status = tm_workspace_create_global_tags(app->configdir, command,
(const char **) (argv + 2),
argc - 2, tags_file, ft->lang);
g_free(command);
......
......@@ -56,7 +56,7 @@ typedef struct _TMWorkspace
a workspace is created. Subsequent calls to the function will return the
created workspace.
*/
const TMWorkspace *tm_get_workspace(void);
const TMWorkspace *tm_get_workspace(const gchar *config_dir);
/*! Adds a work object (source file or project) to the workspace.
\param work_object The work object to add to the project.
......@@ -103,8 +103,8 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode);
\param lang The language to use for the tags file.
\return TRUE on success, FALSE on failure.
*/
gboolean tm_workspace_create_global_tags(const char *pre_process, const char **includes
, int includes_count, const char *tags_file, int lang);
gboolean tm_workspace_create_global_tags(const char *config_dir, const char *pre_process,
const char **includes, int includes_count, const char *tags_file, int lang);
/*! Recreates the tag array of the workspace by collecting the tags of
all member work objects. You shouldn't have to call this directly since
......
......@@ -98,7 +98,12 @@ gboolean tm_project_init(TMProject *project, const char *dir
g_free(project->dir);
return FALSE;
}
tm_workspace_add_object(TM_WORK_OBJECT(project));
if (! tm_workspace_add_object(TM_WORK_OBJECT(project)))
{
g_warning("Unable to init project file %s", path);
g_free(project->dir);
return FALSE;
}
tm_project_open(project, force);
if (!project->file_list || (0 == project->file_list->len))
tm_project_autoscan(project);
......@@ -152,7 +157,8 @@ gboolean tm_project_add_file(TMProject *project, const char *file_name
,gboolean update)
{
TMWorkObject *source_file;
const TMWorkObject *workspace = TM_WORK_OBJECT(tm_get_workspace());
/// TODO if this will be ever used, pass app->config_dir instead of NULL
const TMWorkObject *workspace = TM_WORK_OBJECT(tm_get_workspace(NULL));
char *path;
gboolean exists = FALSE;
......
......@@ -20,15 +20,6 @@
# include <glob.h>
#endif
#include <glib/gstdio.h>
// handling of P_tmpdir, should be something like /tmp, take the root directory under Win32,
// and assume /tmp on non-Win32 systems where P_tmpdir is not set
#ifndef P_tmpdir
# ifdef G_OS_WIN32
# define P_tmpdir "\\"
# else
# define P_tmpdir "/tmp"
# endif
#endif
#include "tm_tag.h"
#include "tm_workspace.h"
......@@ -38,13 +29,11 @@
static TMWorkspace *theWorkspace = NULL;
guint workspace_class_id = 0;
static gboolean tm_create_workspace(void)
static gboolean tm_create_workspace(const gchar *config_dir)
{
#ifdef G_OS_WIN32
char *file_name = g_strdup_printf("%s_%s_%ld.%d", P_tmpdir, PACKAGE, time(NULL), getpid());
#else
char *file_name = g_strdup_printf("%s/%s_%ld.%d", P_tmpdir, PACKAGE, time(NULL), getpid());
#endif
/// TODO check whether the created file is really necessary at all
gchar *file_name = g_strdup_printf("%s%ctagmanager_%ld.%d",
config_dir, G_DIR_SEPARATOR, time(NULL), getpid());
workspace_class_id = tm_work_object_register(tm_workspace_free, tm_workspace_update
, tm_workspace_find_object);
......@@ -97,17 +86,20 @@ void tm_workspace_free(gpointer workspace)
}
}
const TMWorkspace *tm_get_workspace(void)
const TMWorkspace *tm_get_workspace(const gchar *config_dir)
{
if (NULL == config_dir)
return NULL;
if (NULL == theWorkspace)
tm_create_workspace();
tm_create_workspace(config_dir);
return theWorkspace;
}
gboolean tm_workspace_add_object(TMWorkObject *work_object)
{
// theWorkspace should already have been created otherwise something went wrong
if (NULL == theWorkspace)
tm_create_workspace();
return FALSE;
if (NULL == theWorkspace->work_objects)
theWorkspace->work_objects = g_ptr_array_new();
g_ptr_array_add(theWorkspace->work_objects, work_object);
......@@ -149,7 +141,7 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode)
if (NULL == (fp = g_fopen(tags_file, "r")))
return FALSE;
if (NULL == theWorkspace)
tm_create_workspace();
return FALSE;
if (NULL == theWorkspace->global_tags)
theWorkspace->global_tags = g_ptr_array_new();
while (NULL != (tag = tm_tag_new_from_file(NULL, fp, mode)))
......@@ -248,8 +240,8 @@ static gint get_global_tag_type_mask(gint lang)
}
}
gboolean tm_workspace_create_global_tags(const char *pre_process, const char **includes
, int includes_count, const char *tags_file, int lang)
gboolean tm_workspace_create_global_tags(const char *config_dir, const char *pre_process,
const char **includes, int includes_count, const char *tags_file, int lang)
{
#ifdef HAVE_GLOB_H
glob_t globbuf;
......@@ -264,14 +256,14 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i
GHashTable *includes_files_hash;
GList *includes_files = NULL;
#ifdef G_OS_WIN32
char *temp_file = g_strdup_printf("%s_%d_%ld_1.cpp", P_tmpdir, getpid(), time(NULL));
char *temp_file2 = g_strdup_printf("%s_%d_%ld_2.cpp", P_tmpdir, getpid(), time(NULL));
char *temp_file = g_strdup_printf("%s\\_%d_%ld_1.cpp", config_dir, getpid(), time(NULL));
char *temp_file2 = g_strdup_printf("%s\\_%d_%ld_2.cpp", config_dir, getpid(), time(NULL));
#else
char *temp_file = g_strdup_printf("%s/%d_%ld_1.cpp", P_tmpdir, getpid(), time(NULL));
char *temp_file2 = g_strdup_printf("%s/%d_%ld_2.cpp", P_tmpdir, getpid(), time(NULL));
char *temp_file = g_strdup_printf("%s/%d_%ld_1.cpp", config_dir, getpid(), time(NULL));
char *temp_file2 = g_strdup_printf("%s/%d_%ld_2.cpp", config_dir, getpid(), time(NULL));
#endif
if (NULL == (fp = g_fopen(temp_file, "w")))
if (NULL == theWorkspace || NULL == (fp = g_fopen(temp_file, "w")))
return FALSE;
includes_files_hash = g_hash_table_new_full (tm_file_inode_hash,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment