SF.net SVN: geany: [2000] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Thu Nov 1 11:49:29 UTC 2007


Revision: 2000
          http://geany.svn.sourceforge.net/geany/?rev=2000&view=rev
Author:   eht16
Date:     2007-11-01 04:49:29 -0700 (Thu, 01 Nov 2007)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/src/document.c
    trunk/src/main.c
    trunk/src/symbols.c
    trunk/tagmanager/include/tm_workspace.h
    trunk/tagmanager/tm_project.c
    trunk/tagmanager/tm_workspace.c

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2007-10-31 16:41:01 UTC (rev 1999)
+++ trunk/src/document.c	2007-11-01 11:49:29 UTC (rev 2000)
@@ -1725,7 +1725,10 @@
 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 @@
 #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;

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2007-10-31 16:41:01 UTC (rev 1999)
+++ trunk/src/main.c	2007-11-01 11:49:29 UTC (rev 2000)
@@ -277,7 +277,7 @@
 	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;
 

Modified: trunk/src/symbols.c
===================================================================
--- trunk/src/symbols.c	2007-10-31 16:41:01 UTC (rev 1999)
+++ trunk/src/symbols.c	2007-11-01 11:49:29 UTC (rev 2000)
@@ -92,7 +92,8 @@
 	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 @@
 	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 @@
 			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);

Modified: trunk/tagmanager/include/tm_workspace.h
===================================================================
--- trunk/tagmanager/include/tm_workspace.h	2007-10-31 16:41:01 UTC (rev 1999)
+++ trunk/tagmanager/include/tm_workspace.h	2007-11-01 11:49:29 UTC (rev 2000)
@@ -56,7 +56,7 @@
  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 @@
  \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

Modified: trunk/tagmanager/tm_project.c
===================================================================
--- trunk/tagmanager/tm_project.c	2007-10-31 16:41:01 UTC (rev 1999)
+++ trunk/tagmanager/tm_project.c	2007-11-01 11:49:29 UTC (rev 2000)
@@ -98,7 +98,12 @@
 		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 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;
 

Modified: trunk/tagmanager/tm_workspace.c
===================================================================
--- trunk/tagmanager/tm_workspace.c	2007-10-31 16:41:01 UTC (rev 1999)
+++ trunk/tagmanager/tm_workspace.c	2007-11-01 11:49:29 UTC (rev 2000)
@@ -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 @@
 	}
 }
 
-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 @@
 	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 @@
 	}
 }
 
-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 @@
 	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,


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list