[gnome-terminal] Fix for relative paths in --load/save-config file



commit 39365fe263988fb209738350cc21cf24bce07a3f
Author: Christian Persch <chpe gnome org>
Date:   Mon Aug 24 13:41:03 2009 +0200

    Fix for relative paths in --load/save-config file
    
    When using a relative path to the config file, resolve it against the
    passed working directory, instead of implicitly resolving it against the
    factory's cwd which is $HOME.

 src/terminal-options.c |    2 +-
 src/terminal-util.c    |   33 +++++++++++++++++++++++++++++++++
 src/terminal-util.h    |    2 ++
 src/terminal.c         |   15 +++++++++++++--
 4 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/src/terminal-options.c b/src/terminal-options.c
index d5cb121..c2cd535 100644
--- a/src/terminal-options.c
+++ b/src/terminal-options.c
@@ -501,7 +501,7 @@ option_load_save_config_cb (const gchar *option_name,
       return FALSE;
     }
 
-  options->config_file = g_strdup (value);
+  options->config_file = terminal_util_resolve_relative_path (options->default_working_dir, value);
   options->load_config = strcmp (option_name, "--load-config") == 0;
   options->save_config = strcmp (option_name, "--save-config") == 0;
 
diff --git a/src/terminal-util.c b/src/terminal-util.c
index 5813468..4b12a9a 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -261,6 +261,39 @@ terminal_util_open_url (GtkWidget *parent,
 }
 
 /**
+ * terminal_util_resolve_relative_path:
+ * @path:
+ * @relative_path:
+ *
+ * Returns: a newly allocate string
+ */
+char *
+terminal_util_resolve_relative_path (const char *path,
+                                     const char *relative_path)
+{
+  GFile *file, *resolved_file;
+  char *resolved_path = NULL;
+
+  g_return_val_if_fail (relative_path != NULL, NULL);
+
+  if (path == NULL)
+    return g_strdup (relative_path);
+
+  file = g_file_new_for_path (path);
+  resolved_file = g_file_resolve_relative_path (file, relative_path);
+  g_object_unref (file);
+
+  if (resolved_file == NULL)
+    return NULL;
+
+  resolved_path = g_file_get_path (resolved_file);
+  g_object_unref (resolved_file);
+
+  g_print ("resolved %s + %s => %s\n", path, relative_path, resolved_path);
+  return resolved_path;
+}
+
+/**
  * terminal_util_transform_uris_to_quoted_fuse_paths:
  * @uris:
  *
diff --git a/src/terminal-util.h b/src/terminal-util.h
index 5480634..3df86c6 100644
--- a/src/terminal-util.h
+++ b/src/terminal-util.h
@@ -46,6 +46,8 @@ void terminal_util_open_url (GtkWidget *parent,
                              TerminalURLFlavour flavor,
                              guint32 user_time);
 
+char *terminal_util_resolve_relative_path (const char *path,
+                                           const char *relative_path);
 
 void terminal_util_transform_uris_to_quoted_fuse_paths (char **uris);
 
diff --git a/src/terminal.c b/src/terminal.c
index 01dfa8d..fbc92bd 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -253,6 +253,7 @@ main (int argc, char **argv)
   guint32 request_name_ret;
   GError *error = NULL;
   const char *home_dir;
+  char *working_directory;
   int ret = EXIT_SUCCESS;
 
   setlocale (LC_ALL, "");
@@ -275,7 +276,9 @@ main (int argc, char **argv)
 
   startup_id = g_getenv ("DESKTOP_STARTUP_ID");
 
-  options = terminal_options_parse (NULL,
+  working_directory = g_get_current_dir ();
+
+  options = terminal_options_parse (working_directory,
                                     NULL,
                                     startup_id,
                                     NULL,
@@ -288,6 +291,9 @@ main (int argc, char **argv)
                                     egg_sm_client_get_option_group (),
 #endif
                                     NULL);
+
+  g_free (working_directory);
+
   if (!options)
     {
       g_printerr (_("Failed to parse arguments: %s\n"), error->message);
@@ -362,7 +368,6 @@ main (int argc, char **argv)
   /* Forward to the existing factory and exit */
   if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
     {
-      char *working_directory;
       char **env;
       const char *evalue;
       GPtrArray *env_ptr_array;
@@ -547,6 +552,12 @@ terminal_factory_handle_arguments (TerminalFactory *terminal_factory,
   if (arg_error)
     goto out;
 
+  _terminal_debug_print (TERMINAL_DEBUG_FACTORY,
+                         "Factory invoked with working-dir='%s' display='%s' startup-id='%s'\n",
+                         working_directory ? working_directory : "(null)",
+                         display_name ? display_name : "(null)",
+                         startup_id ? startup_id : "(null)");
+
   /* Copy the arguments since terminal_options_parse potentially modifies the array */
   argv_copy = (char **) g_memdup (argv, (argc + 1) * sizeof (char *));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]