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
...@@ -1726,6 +1726,9 @@ void document_update_tag_list(gint idx, gboolean update) ...@@ -1726,6 +1726,9 @@ void document_update_tag_list(gint idx, gboolean update)
{ {
gboolean success = FALSE; 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 the filetype doesn't have a tag parser or it is a new file
if (idx == -1 || doc_list[idx].file_type == NULL || if (idx == -1 || doc_list[idx].file_type == NULL ||
! filetype_has_tags(doc_list[idx].file_type) || ! doc_list[idx].file_name) ! 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) ...@@ -1748,7 +1751,12 @@ void document_update_tag_list(gint idx, gboolean update)
#endif #endif
if (doc_list[idx].tm_file) 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) if (update)
tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE); tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE);
success = TRUE; success = TRUE;
......
...@@ -277,7 +277,7 @@ static void main_init(void) ...@@ -277,7 +277,7 @@ static void main_init(void)
prefs.tab_order_ltr = FALSE; prefs.tab_order_ltr = FALSE;
main_status.quitting = FALSE; main_status.quitting = FALSE;
app->ignore_callback = 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(); ui_prefs.recent_queue = g_queue_new();
main_status.opening_session_files = FALSE; main_status.opening_session_files = FALSE;
......
...@@ -92,7 +92,8 @@ void symbols_global_tags_loaded(gint file_type_idx) ...@@ -92,7 +92,8 @@ void symbols_global_tags_loaded(gint file_type_idx)
TagFileInfo *tfi; TagFileInfo *tfi;
gint tag_type; 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); load_user_tags(file_type_idx);
...@@ -273,7 +274,7 @@ static TMTag *find_workspace_tag(const gchar *tag_name, gint type) ...@@ -273,7 +274,7 @@ static TMTag *find_workspace_tag(const gchar *tag_name, gint type)
const GPtrArray *tags; const GPtrArray *tags;
TMTag *tmtag; 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++) 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 ...@@ -897,7 +898,7 @@ int symbols_generate_global_tags(int argc, char **argv, gboolean want_preprocess
command = NULL; // don't preprocess command = NULL; // don't preprocess
geany_debug("Generating %s tags file.", ft->name); 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), (const char **) (argv + 2),
argc - 2, tags_file, ft->lang); argc - 2, tags_file, ft->lang);
g_free(command); g_free(command);
......
...@@ -56,7 +56,7 @@ typedef struct _TMWorkspace ...@@ -56,7 +56,7 @@ typedef struct _TMWorkspace
a workspace is created. Subsequent calls to the function will return the a workspace is created. Subsequent calls to the function will return the
created workspace. 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. /*! Adds a work object (source file or project) to the workspace.
\param work_object The work object to add to the project. \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); ...@@ -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. \param lang The language to use for the tags file.
\return TRUE on success, FALSE on failure. \return TRUE on success, FALSE on failure.
*/ */
gboolean tm_workspace_create_global_tags(const char *pre_process, const char **includes gboolean tm_workspace_create_global_tags(const char *config_dir, const char *pre_process,
, int includes_count, const char *tags_file, int lang); const char **includes, int includes_count, const char *tags_file, int lang);
/*! Recreates the tag array of the workspace by collecting the tags of /*! 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 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 ...@@ -98,7 +98,12 @@ gboolean tm_project_init(TMProject *project, const char *dir
g_free(project->dir); g_free(project->dir);
return FALSE; 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); tm_project_open(project, force);
if (!project->file_list || (0 == project->file_list->len)) if (!project->file_list || (0 == project->file_list->len))
tm_project_autoscan(project); tm_project_autoscan(project);
...@@ -152,7 +157,8 @@ gboolean tm_project_add_file(TMProject *project, const char *file_name ...@@ -152,7 +157,8 @@ gboolean tm_project_add_file(TMProject *project, const char *file_name
,gboolean update) ,gboolean update)
{ {
TMWorkObject *source_file; 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; char *path;
gboolean exists = FALSE; gboolean exists = FALSE;
......
...@@ -20,15 +20,6 @@ ...@@ -20,15 +20,6 @@
# include <glob.h> # include <glob.h>
#endif #endif
#include <glib/gstdio.h> #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_tag.h"
#include "tm_workspace.h" #include "tm_workspace.h"
...@@ -38,13 +29,11 @@ ...@@ -38,13 +29,11 @@
static TMWorkspace *theWorkspace = NULL; static TMWorkspace *theWorkspace = NULL;
guint workspace_class_id = 0; guint workspace_class_id = 0;
static gboolean tm_create_workspace(void) static gboolean tm_create_workspace(const gchar *config_dir)
{ {
#ifdef G_OS_WIN32 /// TODO check whether the created file is really necessary at all
char *file_name = g_strdup_printf("%s_%s_%ld.%d", P_tmpdir, PACKAGE, time(NULL), getpid()); gchar *file_name = g_strdup_printf("%s%ctagmanager_%ld.%d",
#else config_dir, G_DIR_SEPARATOR, time(NULL), getpid());
char *file_name = g_strdup_printf("%s/%s_%ld.%d", P_tmpdir, PACKAGE, time(NULL), getpid());
#endif
workspace_class_id = tm_work_object_register(tm_workspace_free, tm_workspace_update workspace_class_id = tm_work_object_register(tm_workspace_free, tm_workspace_update
, tm_workspace_find_object); , tm_workspace_find_object);
...@@ -97,17 +86,20 @@ void tm_workspace_free(gpointer workspace) ...@@ -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) if (NULL == theWorkspace)
tm_create_workspace(); tm_create_workspace(config_dir);
return theWorkspace; return theWorkspace;
} }
gboolean tm_workspace_add_object(TMWorkObject *work_object) gboolean tm_workspace_add_object(TMWorkObject *work_object)
{ {
// theWorkspace should already have been created otherwise something went wrong
if (NULL == theWorkspace) if (NULL == theWorkspace)
tm_create_workspace(); return FALSE;
if (NULL == theWorkspace->work_objects) if (NULL == theWorkspace->work_objects)
theWorkspace->work_objects = g_ptr_array_new(); theWorkspace->work_objects = g_ptr_array_new();
g_ptr_array_add(theWorkspace->work_objects, work_object); 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) ...@@ -149,7 +141,7 @@ gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode)
if (NULL == (fp = g_fopen(tags_file, "r"))) if (NULL == (fp = g_fopen(tags_file, "r")))
return FALSE; return FALSE;
if (NULL == theWorkspace) if (NULL == theWorkspace)
tm_create_workspace(); return FALSE;
if (NULL == theWorkspace->global_tags) if (NULL == theWorkspace->global_tags)
theWorkspace->global_tags = g_ptr_array_new(); theWorkspace->global_tags = g_ptr_array_new();
while (NULL != (tag = tm_tag_new_from_file(NULL, fp, mode))) while (NULL != (tag = tm_tag_new_from_file(NULL, fp, mode)))
...@@ -248,8 +240,8 @@ static gint get_global_tag_type_mask(gint lang) ...@@ -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 gboolean tm_workspace_create_global_tags(const char *config_dir, const char *pre_process,
, int includes_count, const char *tags_file, int lang) const char **includes, int includes_count, const char *tags_file, int lang)
{ {
#ifdef HAVE_GLOB_H #ifdef HAVE_GLOB_H
glob_t globbuf; glob_t globbuf;
...@@ -264,14 +256,14 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i ...@@ -264,14 +256,14 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i
GHashTable *includes_files_hash; GHashTable *includes_files_hash;
GList *includes_files = NULL; GList *includes_files = NULL;
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
char *temp_file = g_strdup_printf("%s_%d_%ld_1.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", P_tmpdir, getpid(), time(NULL)); char *temp_file2 = g_strdup_printf("%s\\_%d_%ld_2.cpp", config_dir, getpid(), time(NULL));
#else #else
char *temp_file = g_strdup_printf("%s/%d_%ld_1.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", P_tmpdir, getpid(), time(NULL)); char *temp_file2 = g_strdup_printf("%s/%d_%ld_2.cpp", config_dir, getpid(), time(NULL));
#endif #endif
if (NULL == (fp = g_fopen(temp_file, "w"))) if (NULL == theWorkspace || NULL == (fp = g_fopen(temp_file, "w")))
return FALSE; return FALSE;
includes_files_hash = g_hash_table_new_full (tm_file_inode_hash, 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