[anjuta] bgo #586428 - paths with symlinks do not get 'real' absolute paths
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] bgo #586428 - paths with symlinks do not get 'real' absolute paths
- Date: Mon, 7 Jun 2010 15:54:14 +0000 (UTC)
commit e8291133ecacbcf0528a8f7c910718df8676cd18
Author: Sébastien Granjoux <seb sfo free fr>
Date: Mon Jun 7 17:41:54 2010 +0200
bgo #586428 - paths with symlinks do not get 'real' absolute paths
libanjuta/anjuta-utils.c | 88 ++++++++++++++++++++++++-
libanjuta/anjuta-utils.h | 4 +-
plugins/build-basic-autotools/build-options.c | 5 +-
plugins/build-basic-autotools/plugin.c | 14 +++--
plugins/class-gen/generator.c | 2 +-
plugins/debug-manager/start.c | 2 +-
plugins/gbf-am/gbf-am-project.c | 2 +-
plugins/gbf-mkfile/gbf-mkfile-project.c | 4 +-
plugins/gdb/debugger.c | 78 +++++++++++++---------
plugins/search/search-replace_backend.c | 2 +-
plugins/tools/execute.c | 2 +-
src/main.c | 3 +-
12 files changed, 156 insertions(+), 50 deletions(-)
---
diff --git a/libanjuta/anjuta-utils.c b/libanjuta/anjuta-utils.c
index c56e0aa..3490813 100644
--- a/libanjuta/anjuta-utils.c
+++ b/libanjuta/anjuta-utils.c
@@ -772,6 +772,92 @@ anjuta_util_get_real_path (const gchar *path)
return NULL;
}
+/**
+ * anjuta_util_get_current_dir:
+ *
+ * Get current working directory, unlike g_get_current_dir, keeps symbolic links
+ * in path name.
+ *
+ * Returns: The current working directory.
+ */
+gchar*
+anjuta_util_get_current_dir (void)
+{
+ const gchar *pwd;
+
+ pwd = g_getenv ("PWD");
+ if (pwd != NULL)
+ {
+ return g_strdup (pwd);
+ }
+ else
+ {
+ return g_get_current_dir ();
+ }
+}
+
+static gboolean
+is_valid_scheme_character (char c)
+{
+ return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
+}
+
+/* Following RFC 2396, valid schemes are built like:
+ * scheme = alpha *( alpha | digit | "+" | "-" | "." )
+ */
+static gboolean
+has_valid_scheme (const char *uri)
+{
+ const char *p;
+
+ p = uri;
+
+ if (!g_ascii_isalpha (*p))
+ return FALSE;
+
+ do {
+ p++;
+ } while (is_valid_scheme_character (*p));
+
+ return *p == ':';
+}
+
+/**
+ * anjuta_util_file_new_for_commandline_arg:
+ *
+ * @arg: URI or relative or absolute file path
+ *
+ * Create a new file corresponding to arg, unlike g_file_new_for_commandline_arg,
+ * keeps symbolic links in path name.
+ *
+ * Returns: A new GFile object
+ */
+GFile *
+anjuta_util_file_new_for_commandline_arg (const gchar *arg)
+{
+ GFile *file;
+ char *filename;
+ char *current_dir;
+
+ g_return_val_if_fail (arg != NULL, NULL);
+
+ if (g_path_is_absolute (arg))
+ return g_file_new_for_path (arg);
+
+ if (has_valid_scheme (arg))
+ return g_file_new_for_uri (arg);
+
+ current_dir = anjuta_util_get_current_dir ();
+ filename = g_build_filename (current_dir, arg, NULL);
+ g_free (current_dir);
+
+ file = g_file_new_for_path (filename);
+ g_free (filename);
+
+ return file;
+}
+
+
/* Dedup a list of paths - duplicates are removed from the tail.
** Useful for deduping Recent Files and Recent Projects */
GList*
@@ -2313,7 +2399,7 @@ anjuta_utils_drop_get_files (GtkSelectionData *selection_data)
for (i = 0; uris[i] != NULL; i++)
{
- GFile* file = g_file_new_for_commandline_arg (uris[0]);
+ GFile* file = g_file_new_for_uri (uris[0]);
files = g_slist_append(files, file);
}
diff --git a/libanjuta/anjuta-utils.h b/libanjuta/anjuta-utils.h
index baf65a0..031c895 100644
--- a/libanjuta/anjuta-utils.h
+++ b/libanjuta/anjuta-utils.h
@@ -111,6 +111,8 @@ pid_t anjuta_util_execute_terminal_shell (const gchar *dir, const gchar *command
gchar* anjuta_util_escape_quotes(const gchar* str);
gchar* anjuta_util_get_real_path (const gchar *path);
+gchar* anjuta_util_get_current_dir (void);
+GFile *anjuta_util_file_new_for_commandline_arg (const gchar *arg);
gchar* anjuta_util_uri_get_dirname (const gchar *uri);
gchar* anjuta_util_replace_home_dir_with_tilde (const gchar *uri);
@@ -226,4 +228,4 @@ ANJUTA_TYPE_END
G_END_DECLS
-#endif
\ No newline at end of file
+#endif
diff --git a/plugins/build-basic-autotools/build-options.c b/plugins/build-basic-autotools/build-options.c
index 6c10be2..2e39a79 100644
--- a/plugins/build-basic-autotools/build-options.c
+++ b/plugins/build-basic-autotools/build-options.c
@@ -197,9 +197,8 @@ build_gtk_file_chooser_create_and_set_uri (GtkFileChooser *chooser, const gchar
g_error_free (error);
}
g_object_unref (dir);
-
- gtk_file_chooser_set_current_folder_uri (chooser, uri);
- return gtk_file_chooser_set_uri (chooser, uri);
+
+ return gtk_file_chooser_set_current_folder_uri (chooser, uri);
}
/* Do not delete the automatically created folder */
diff --git a/plugins/build-basic-autotools/plugin.c b/plugins/build-basic-autotools/plugin.c
index c3d0770..a4081f3 100644
--- a/plugins/build-basic-autotools/plugin.c
+++ b/plugins/build-basic-autotools/plugin.c
@@ -1322,10 +1322,6 @@ build_execute_command_in_context (BuildContext* context, GError **err)
/* Send options to make */
if (strcmp (build_program_get_basename (context->program), "make") == 0)
{
- if (!anjuta_preferences_get_bool (prefs , PREF_TRANSLATE_MESSAGE))
- {
- build_program_add_env (context->program, "LANGUAGE", "C");
- }
if (anjuta_preferences_get_bool (prefs , PREF_PARALLEL_MAKE))
{
gchar *arg = g_strdup_printf ("-j%d", anjuta_preferences_get_int (prefs , PREF_PARALLEL_MAKE_JOB));
@@ -1338,6 +1334,14 @@ build_execute_command_in_context (BuildContext* context, GError **err)
}
}
+ /* Set a current working directory which can contains symbolic links */
+ build_program_add_env (context->program, "PWD", context->program->work_dir);
+
+ if (!anjuta_preferences_get_bool (prefs , PREF_TRANSLATE_MESSAGE))
+ {
+ build_program_add_env (context->program, "LANGUAGE", "C");
+ }
+
build_program_override (context->program, context->environment);
if (context->message_view)
@@ -2040,7 +2044,7 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, const gcha
build_dir = g_file_get_path (file);
g_object_unref (file);
-
+
args = build_configuration_get_args (config);
if (run_autogen)
diff --git a/plugins/class-gen/generator.c b/plugins/class-gen/generator.c
index 22d6344..242a510 100644
--- a/plugins/class-gen/generator.c
+++ b/plugins/class-gen/generator.c
@@ -77,7 +77,7 @@ cg_generator_make_absolute (const gchar *path)
}
else
{
- current_dir = g_get_current_dir ();
+ current_dir = anjuta_util_get_current_dir ();
abs_path = g_build_filename (current_dir, path, NULL);
g_free (current_dir);
}
diff --git a/plugins/debug-manager/start.c b/plugins/debug-manager/start.c
index 6ff9ac7..da77373 100644
--- a/plugins/debug-manager/start.c
+++ b/plugins/debug-manager/start.c
@@ -188,7 +188,7 @@ get_source_directories (AnjutaPlugin *plugin)
GFile *file;
return NULL;
- cwd = g_get_current_dir();
+ cwd = anjuta_util_get_current_dir();
file = g_file_new_for_path (cwd);
search_dirs = g_list_prepend (search_dirs, g_file_get_uri (file));
g_object_unref (file);
diff --git a/plugins/gbf-am/gbf-am-project.c b/plugins/gbf-am/gbf-am-project.c
index f114962..67bf5a2 100644
--- a/plugins/gbf-am/gbf-am-project.c
+++ b/plugins/gbf-am/gbf-am-project.c
@@ -434,7 +434,7 @@ uri_normalize (const gchar *path_or_uri, const gchar *base_uri)
{
GFile *file;
- file = g_file_new_for_commandline_arg (path_or_uri);
+ file = anjuta_util_file_new_for_commandline_arg (path_or_uri);
normalized_uri = g_file_get_uri (file);
g_object_unref (file);
}
diff --git a/plugins/gbf-mkfile/gbf-mkfile-project.c b/plugins/gbf-mkfile/gbf-mkfile-project.c
index e88a896..7e90e47 100644
--- a/plugins/gbf-mkfile/gbf-mkfile-project.c
+++ b/plugins/gbf-mkfile/gbf-mkfile-project.c
@@ -424,7 +424,7 @@ uri_normalize (const gchar *path_or_uri, const gchar *base_uri)
{
GFile *file;
- file = g_file_new_for_commandline_arg (path_or_uri);
+ file = anjuta_util_file_new_for_commandline_arg (path_or_uri);
normalized_uri = g_file_get_uri (file);
g_object_unref (file);
}
@@ -2759,7 +2759,7 @@ impl_probe (GbfProject *_project,
/* use _for_commandline_arg to resolve eventually relative path against
* current directory
*/
- file = g_file_new_for_commandline_arg (path);
+ file = anjuta_util_file_new_for_commandline_arg (path);
root_path = g_file_get_path (file);
g_object_unref (file);
if (root_path != NULL && g_file_test (root_path, G_FILE_TEST_IS_DIR)) {
diff --git a/plugins/gdb/debugger.c b/plugins/gdb/debugger.c
index 96b20c7..61cc3f4 100644
--- a/plugins/gdb/debugger.c
+++ b/plugins/gdb/debugger.c
@@ -40,6 +40,7 @@
#include <libanjuta/anjuta-launcher.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/anjuta-marshal.h>
+#include <libanjuta/anjuta-utils.h>
#include <libanjuta/interfaces/ianjuta-debugger-breakpoint.h>
#include <libanjuta/interfaces/ianjuta-debugger-register.h>
#include <libanjuta/interfaces/ianjuta-debugger-memory.h>
@@ -1087,10 +1088,50 @@ debugger_handle_post_execution (Debugger *debugger)
}
}
+static const gchar *
+debugger_parse_filename (const GDBMIValue *frame)
+{
+ const GDBMIValue *filename, *fullname;
+ const gchar *file_str = NULL;
+
+ /* Get filename from file if possible to keep symbolic links */
+ filename = gdbmi_value_hash_lookup (frame, "file");
+ if (filename)
+ {
+ file_str = gdbmi_value_literal_get (filename);
+ if (!g_path_is_absolute (file_str))
+ {
+ /* Path is not absolute */
+ file_str = NULL;
+ }
+ }
+
+ /* Try fullname value to get an absolute path */
+ if (file_str == NULL)
+ {
+ fullname = gdbmi_value_hash_lookup (frame, "fullname");
+ if (fullname)
+ {
+ file_str = gdbmi_value_literal_get (fullname);
+ }
+ else
+ {
+ if (filename)
+ {
+ file_str = gdbmi_value_literal_get (filename);
+ }
+ }
+ }
+
+ if ((file_str != NULL) && (*file_str == '\0')) file_str = NULL;
+
+ return file_str;
+}
+
static void
debugger_process_frame (Debugger *debugger, const GDBMIValue *val)
{
- const GDBMIValue *file, *line, *frame, *addr, *fullname, *thread;
+ const GDBMIValue *line, *frame, *addr, *thread;
const gchar *file_str = NULL;
guint line_num = 0;
gulong addr_num = 0;
@@ -1107,21 +1148,7 @@ debugger_process_frame (Debugger *debugger, const GDBMIValue *val)
frame = gdbmi_value_hash_lookup (val, "frame");
if (frame)
{
- fullname = gdbmi_value_hash_lookup (frame, "fullname");
- if (fullname)
- {
- file_str = gdbmi_value_literal_get (fullname);
- if (*file_str == '\0') file_str = NULL;
- }
- else
- {
- file = gdbmi_value_hash_lookup (frame, "file");
- if (file)
- {
- file_str = gdbmi_value_literal_get (file);
- if (*file_str == '\0') file_str = NULL;
- }
- }
+ file_str = debugger_parse_filename (frame);
if (file_str != NULL)
{
@@ -1404,13 +1431,7 @@ parse_breakpoint (IAnjutaDebuggerBreakpointItem* bp, const GDBMIValue *brkpnt)
bp->id = strtoul (value, NULL, 10);
}
- literal = gdbmi_value_hash_lookup (brkpnt, "fullname");
- if (literal == NULL) literal = gdbmi_value_hash_lookup (brkpnt, "file");
- if (literal)
- {
- value = gdbmi_value_literal_get (literal);
- bp->file = (gchar *)value;
- }
+ bp->file = (gchar *)debugger_parse_filename (brkpnt);
literal = gdbmi_value_hash_lookup (brkpnt, "line");
if (literal)
@@ -1827,7 +1848,7 @@ debugger_get_source_path (Debugger *debugger, const gchar *file)
{
/* The file could be found nowhere. Use current directory */
gchar *cwd;
- cwd = g_get_current_dir ();
+ cwd = anjuta_util_get_current_dir ();
path = g_build_filename (cwd, file, NULL);
g_free (cwd);
}
@@ -3089,13 +3110,8 @@ parse_frame (IAnjutaDebuggerFrame *frame, const GDBMIValue *frame_hash)
else
frame->level = 0;
- literal = gdbmi_value_hash_lookup (frame_hash, "fullname");
- if (literal == NULL)
- literal = gdbmi_value_hash_lookup (frame_hash, "file");
- if (literal)
- frame->file = (gchar *)gdbmi_value_literal_get (literal);
- else
- frame->file = NULL;
+
+ frame->file = (gchar *)debugger_parse_filename (frame_hash);
literal = gdbmi_value_hash_lookup (frame_hash, "line");
if (literal)
diff --git a/plugins/search/search-replace_backend.c b/plugins/search/search-replace_backend.c
index 9aa2781..7254a2c 100644
--- a/plugins/search/search-replace_backend.c
+++ b/plugins/search/search-replace_backend.c
@@ -805,7 +805,7 @@ create_search_entries (Search *s)
{
if (SR_PROJECT == s->range.type)
s->range.type = SR_FILES;
- dir = g_get_current_dir();
+ dir = anjuta_util_get_current_dir();
}
files = get_project_file_list();
diff --git a/plugins/tools/execute.c b/plugins/tools/execute.c
index 61c4827..0b53c5d 100644
--- a/plugins/tools/execute.c
+++ b/plugins/tools/execute.c
@@ -814,7 +814,7 @@ atp_execution_context_execute (ATPExecutionContext* this,
/* Change working directory */
if (this->directory != NULL)
{
- prev_dir = g_get_current_dir();
+ prev_dir = anjuta_util_get_current_dir();
chdir (this->directory);
}
/* Execute */
diff --git a/src/main.c b/src/main.c
index 6304cdb..8bf08ec 100644
--- a/src/main.c
+++ b/src/main.c
@@ -209,8 +209,7 @@ main (int argc, char *argv[])
gchar** filename;
for (filename = anjuta_filenames; *filename != NULL; filename++)
{
- GFile* file = g_file_new_for_commandline_arg(*filename);
-
+ GFile* file = anjuta_util_file_new_for_commandline_arg(*filename);
g_free (*filename);
*filename = g_file_get_uri (file);
g_object_unref (file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]