Re: Working directory



Err.. to answer my own question, no it isn't. Not even close.

So I realized that sending a patch without actually testing it is kind of stupid, so I did test it... and now I need help.

I figured out that I had to unquote the location of the executable before getting its directory, and that prepending a "cd <whatever>;" to a command doesn't work.

I tried using chdir() before it executing it instead, but that's no good either. Anybody have a clue how I could do this?

Thanks,
Yury

From: "Yury Sulsky" <ysulsky hotmail com>
To: nautilus-list gnome org
Subject: Working directory
Date: Fri, 28 Mar 2003 17:21:10 -0500

Hi,

I've found that some applications (such as eclipse - http://www.eclipse.org) expect to have their working directory be set to the directory that the executable resides in. This behaviour is also good for launching files (e.g. if I use nautilus to open ~/music/song.mp3, nautilus should open my mp3 player with working directory ~/music), so I've attached a diff that attempts to do this.

Warning: I haven't tried to compile this, and I don't know if this is the correct way to go about it (in short, I have no clue what I'm doing).

The way it works is it modifies nautilus_launch_application and nautilus_launch_application_from_command in libnautilus-private/nautilus-program-choosing.c:

nautilus_launch_application prepends a "cd [file's directory]; " to the command passed to nautilus_launch_application_from_command, and the latter prepends "cd [executable's directory]; " if no arguments were passed to it.

Is this even remotely correct?

Thanks,
Yury


_________________________________________________________________

<< working_dir.diff >>


_________________________________________________________________

Index: libnautilus-private/nautilus-program-choosing.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-program-choosing.c,v
retrieving revision 1.64
diff -u -r1.64 nautilus-program-choosing.c
--- libnautilus-private/nautilus-program-choosing.c 7 Nov 2002 19:20:40 -0000 1.64 +++ libnautilus-private/nautilus-program-choosing.c 31 Mar 2003 05:41:04 -0000
@@ -45,6 +45,7 @@
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <stdlib.h>
+#include <unistd.h>

typedef struct {
	NautilusFile *file;
@@ -545,8 +546,22 @@
	char      *parameter;
	char      *uri_scheme, *uri;

+	uri = NULL;
	uri_scheme = nautilus_file_get_uri_scheme (file);

+	if (eel_strcasecmp (uri_scheme, "file") != 0) {
+		char *local_file;
+		char *working_directory;
+
+		uri = nautilus_file_get_uri (file);
+		local_file = gnome_vfs_get_local_path_from_uri (uri);
+		working_directory = g_path_get_dirname (local_file);
+		chdir (working_directory);
+
+		g_free (working_directory);
+		g_free (local_file);
+	}
+
	/* If the program can open URIs, always use a URI. This
	 * prevents any possible ambiguity for cases where a path
	 * would looks like a URI.
@@ -567,9 +582,8 @@
		}
		parameter = nautilus_file_get_uri (file);
	} else {
-		uri = nautilus_file_get_uri (file);
+		if (!uri) uri = nautilus_file_get_uri (file);
		parameter = gnome_vfs_get_local_path_from_uri (uri);
-		g_free (uri);

		if (parameter == NULL) {
			/* This application can't deal with this URI,
@@ -587,6 +601,7 @@
			return;
		}
	}
+	if (uri) g_free (uri);
	g_free (uri_scheme);

	screen = gtk_window_get_screen (parent_window);
@@ -620,13 +635,31 @@
					  gboolean use_terminal)
{
	char *full_command;
-	char *quoted_parameter;
+	char *quoted_parameter;

	if (parameter != NULL) {
		quoted_parameter = g_shell_quote (parameter);
		full_command = g_strconcat (command_string, " ", quoted_parameter, NULL);
		g_free (quoted_parameter);
	} else {
+		char  *unquoted_command_string;
+		char  *working_directory;
+		char **command_string_parts;
+
+		unquoted_command_string = g_shell_unquote (command_string, NULL);
+		command_string_parts = g_strsplit (unquoted_command_string, " ", 2);
+		working_directory = g_path_get_dirname (command_string_parts[0]);
+
+		g_free (unquoted_command_string);
+		g_strfreev (command_string_parts);
+
+		chdir (working_directory);
+		g_free (working_directory);
+
		full_command = g_strdup (command_string);
	}




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