Index: modules/sftp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/sftp-method.c,v
retrieving revision 1.47
diff -u -p -r1.47 sftp-method.c
--- modules/sftp-method.c	16 Jul 2006 09:57:23 -0000	1.47
+++ modules/sftp-method.c	12 Aug 2006 12:48:45 -0000
@@ -84,6 +84,7 @@ static guint max_req = 8;
 
 typedef struct {
 	gchar         *hash_name;
+	gchar	      *home_path;
 	gint           in_fd;
 	gint           out_fd;
 	gint           tty_fd;
@@ -155,13 +158,19 @@ G_LOCK_DEFINE_STATIC (sftp_connection_ta
 #  define DEBUG(x)
 #endif
 
-#define URI_TO_PATH(uri,path) \
+#define URI_TO_PATH(connection,uri,path) \
 	path = gnome_vfs_unescape_string (gnome_vfs_uri_get_path (uri), NULL); \
 	if (path == NULL || !strcmp (path, "")) { \
 		g_free (path); \
 		path = g_strdup ("/"); \
+	} else if (connection->home_path != NULL && (g_str_has_prefix (path, "/~/") || strcmp (path, "/~"))) { /* IETF paper "URI Scheme for SSH and SFTP" */ \
+		char *old_path = path; \
+		path = g_strconcat (connection->home_path, "/", old_path + 2, NULL); \
+		g_free (old_path); \
 	}
 
+static GnomeVFSResult get_real_path (SftpConnection *conn, const gchar *path, gchar **realpath);
+
 static GnomeVFSResult do_check_same_fs (GnomeVFSMethod  *method,
 					GnomeVFSURI     *a,
 					GnomeVFSURI     *b,
@@ -1431,6 +1445,16 @@ sftp_connect (SftpConnection **connectio
 
 		DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Version is %d",
 			      (*connection)->version));
+
+		res = get_real_path ((*connection), ".", &((*connection)->home_path));
+		if (res != GNOME_VFS_OK) {
+			DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Failed to get home path: %s",
+				      gnome_vfs_result_to_string (res)));
+			res = GNOME_VFS_OK;
+		} else {
+			DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got home path: %s",
+				      (*connection)->home_path));
+		}
 	}
 
  bail:
@@ -1704,8 +1728,6 @@ sftp_connection_unref (SftpConnection *c
 
 /* Portions of the below functions inspired by functions in OpenSSH sftp-client.c */
 
-#if 0
-
 static GnomeVFSResult
 get_real_path (SftpConnection *conn, const gchar *path, gchar **realpath)
 {
@@ -1770,8 +1792,6 @@ get_real_path (SftpConnection *conn, con
 	return GNOME_VFS_OK;
 }
 
-#endif /* 0 */
-
 static GnomeVFSResult 
 do_open (GnomeVFSMethod        *method,
 	 GnomeVFSMethodHandle **method_handle,
@@ -1796,7 +1816,7 @@ do_open (GnomeVFSMethod        *method,
 	res = sftp_get_connection (&conn, uri);
 	if (res != GNOME_VFS_OK) return res;
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 
 	id = sftp_connection_get_id (conn);
 
@@ -1874,7 +1894,7 @@ do_create (GnomeVFSMethod        *method
 	res = sftp_get_connection (&conn, uri);
 	if (res != GNOME_VFS_OK) return res;
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 
 	id = sftp_connection_get_id (conn);
 
@@ -2613,7 +2633,7 @@ do_get_file_info (GnomeVFSMethod        
 	res = sftp_get_connection (&conn, uri);
 	if (res != GNOME_VFS_OK) return res;
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 	res = get_file_info_for_path (conn, path, file_info, options);
 	g_free (path);
 
@@ -2673,7 +2693,7 @@ do_open_directory (GnomeVFSMethod       
 
 	id = sftp_connection_get_id (conn);
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 
 	DEBUG (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s: Opening %s", G_GNUC_FUNCTION, path));
 
@@ -2910,7 +2930,7 @@ do_make_directory (GnomeVFSMethod  *meth
 
 	id = sftp_connection_get_id (conn);
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 
 	memset (&info, 0, sizeof (GnomeVFSFileInfo));
 	iobuf_send_string_request_with_file_info (conn->out_fd, id, SSH2_FXP_MKDIR,
@@ -2947,7 +2967,7 @@ do_remove_directory (GnomeVFSMethod  *me
 
 	id = sftp_connection_get_id (conn);
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 	iobuf_send_string_request (conn->out_fd, id, SSH2_FXP_RMDIR, path, strlen (path));
 	g_free (path);
 
@@ -2984,8 +3004,8 @@ do_move (GnomeVFSMethod  *method,
 	res = sftp_get_connection (&conn, old_uri);
 	if (res != GNOME_VFS_OK) return res;
 
-	URI_TO_PATH (old_uri, old_path);
-	URI_TO_PATH (new_uri, new_path);
+	URI_TO_PATH (conn, old_uri, old_path);
+	URI_TO_PATH (conn, new_uri, new_path);
 
 	id = sftp_connection_get_id (conn);
 
@@ -3039,7 +3059,7 @@ do_rename (GnomeVFSMethod  *method,
 	res = sftp_get_connection (&conn, old_uri);
 	if (res != GNOME_VFS_OK) return res;
 
-	URI_TO_PATH (old_uri, old_path);
+	URI_TO_PATH (conn, old_uri, old_path);
 
 	old_dirname = g_path_get_dirname (old_path);
 
@@ -3089,7 +3109,7 @@ do_unlink (GnomeVFSMethod  *method,
 
 	id = sftp_connection_get_id (conn);
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 	iobuf_send_string_request (conn->out_fd, id, SSH2_FXP_REMOVE, path, strlen (path));
 	g_free (path);
 
@@ -3164,7 +3184,7 @@ do_set_file_info (GnomeVFSMethod        
 
 		id = sftp_connection_get_id (conn);
 
-		URI_TO_PATH (uri, path);
+		URI_TO_PATH (conn, uri, path);
 		iobuf_send_string_request_with_file_info (conn->out_fd, id, SSH2_FXP_SETSTAT,
 							  path, strlen (path), info, mask);
 		g_free (path);
@@ -3207,7 +3227,7 @@ do_create_symlink (GnomeVFSMethod   *met
 		return GNOME_VFS_ERROR_NOT_SUPPORTED;
 	}
 
-	URI_TO_PATH (uri, path);
+	URI_TO_PATH (conn, uri, path);
 
 	real_target = NULL;
 
@@ -3223,7 +3243,7 @@ do_create_symlink (GnomeVFSMethod   *met
 			return GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM;
 		}
 
-		URI_TO_PATH (target_uri, real_target);
+		URI_TO_PATH (conn, target_uri, real_target);
 		gnome_vfs_uri_unref (target_uri);
 	}
 
