From b1dc778b3d803b08bf98c56f58b2aa6be5cc4074 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 20 Apr 2012 14:03:53 +0300 Subject: [PATCH] Ticket #2779: Active VFS directories list contain incorrect current path 1) login to any ftp or fish resource 2) select ftp/fish entry and change current path 3) go back to old path 4) press Ctrl+X A (open "Active VFS directories" dialog) Expected result: should be correct path to current VFS path Actual result: path is incorrect. Signed-off-by: Slava Zanko --- lib/vfs/direntry.c | 3 +++ lib/vfs/interface.c | 34 +++++++++++++++++++++++---- lib/vfs/path.c | 29 +++++++++++++++++++++++ lib/vfs/path.h | 2 ++ src/vfs/fish/fish.c | 22 +---------------- src/vfs/ftpfs/ftpfs.c | 65 +-------------------------------------------------- 6 files changed, 65 insertions(+), 90 deletions(-) diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index ad7c729f7..565878570 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -1067,6 +1067,9 @@ vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flag path_element = vfs_path_get_by_index (vpath, -1); subclass = ((struct vfs_s_subclass *) path_element->class->data); + if (subclass == NULL) + return NULL; + vpath_archive = vfs_path_clone (vpath); vfs_path_remove_element_by_index (vpath_archive, -1); diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index ae72b2e66..02b6628b3 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -58,6 +58,7 @@ #include "utilvfs.h" #include "path.h" #include "gc.h" +#include "xdirentry.h" extern GString *vfs_str_buffer; extern struct vfs_class *current_vfs; @@ -696,12 +697,35 @@ mc_chdir (const vfs_path_t * vpath) /* Sometimes we assume no trailing slash on cwd */ path_element = vfs_path_get_by_index (vfs_get_raw_current_dir (), -1); - if (vfs_path_element_valid (path_element) && (*path_element->path != '\0')) + if (vfs_path_element_valid (path_element)) { - char *p; - p = strchr (path_element->path, 0) - 1; - if (*p == PATH_SEP && p > path_element->path) - *p = 0; + if (*path_element->path != '\0') + { + char *p; + + p = strchr (path_element->path, 0) - 1; + if (p != NULL && *p == PATH_SEP && p != path_element->path) + *p = '\0'; + } +#ifdef ENABLE_VFS_NET + { + struct vfs_s_subclass *subclass; + + subclass = (struct vfs_s_subclass *) path_element->class->data; + if (subclass != NULL) + { + struct vfs_s_super *super = NULL; + + (void) vfs_s_get_path (vpath, &super, 0); + if (super != NULL && super->path_element != NULL) + { + g_free (super->path_element->path); + super->path_element->path = g_strdup (path_element->path); + } + } + } +#endif /* ENABLE_VFS_NET */ + } return 0; diff --git a/lib/vfs/path.c b/lib/vfs/path.c index ee1ec6364..3d8036309 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -1442,6 +1442,35 @@ vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep /* --------------------------------------------------------------------------------------------- */ /** + * Build pretty string representation of one path_element_t object + * + * @param element path element + * + * @return newly allocated string + */ + +char * +vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element) +{ + char *url_params; + GString *pretty_path; + + pretty_path = g_string_new (element->class->prefix); + g_string_append (pretty_path, VFS_PATH_URL_DELIMITER); + + url_params = vfs_path_build_url_params_str (element, FALSE); + g_string_append (pretty_path, url_params); + g_free (url_params); + + if (*element->path != PATH_SEP) + g_string_append_c (pretty_path, PATH_SEP); + + g_string_append (pretty_path, element->path); + return g_string_free (pretty_path, FALSE); +} + +/* --------------------------------------------------------------------------------------------- */ +/** * Compare two path objects as strings * * @param vpath1 first path object diff --git a/lib/vfs/path.h b/lib/vfs/path.h index 30f6298ed..98db436aa 100644 --- a/lib/vfs/path.h +++ b/lib/vfs/path.h @@ -83,6 +83,8 @@ char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error); vfs_path_t *vfs_path_deserialize (const char *data, GError ** error); char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password); +char *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element); + size_t vfs_path_len (const vfs_path_t * vpath); int vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2); int vfs_path_ncmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len); diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index f0e38bcb4..f18d9ff53 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -404,18 +404,6 @@ fish_info (struct vfs_class *me, struct vfs_s_super *super) /* --------------------------------------------------------------------------------------------- */ -/* The returned directory should always contain a trailing slash */ - -static char * -fish_getcwd (struct vfs_class *me, struct vfs_s_super *super) -{ - if (fish_command (me, super, WANT_STRING, "#PWD\npwd; echo '### 200'\n") == COMPLETE) - return g_strconcat (reply_str, "/", (char *) NULL); - ERRNOR (EIO, NULL); -} - - -/* --------------------------------------------------------------------------------------------- */ static void fish_open_archive_pipeopen (struct vfs_s_super *super) @@ -555,8 +543,6 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) if (fish_info (me, super)) SUP->scr_env = fish_set_env (SUP->host_flags); - vfs_print_message (_("fish: Setting up current directory...")); - super->path_element->path = fish_getcwd (me, super); vfs_print_message (_("fish: Connected, home %s."), super->path_element->path); #if 0 super->name = @@ -843,8 +829,6 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) reply_code = fish_decode_reply (buffer + 4, 0); if (reply_code == COMPLETE) { - g_free (super->path_element->path); - super->path_element->path = g_strdup (remote_path); vfs_print_message (_("%s: done."), me->name); return 0; } @@ -1584,11 +1568,7 @@ fish_fill_names (struct vfs_class *me, fill_names_f func) } break; } - - name = - g_strconcat (vfs_fish_ops.prefix, VFS_PATH_URL_DELIMITER, - super->path_element->user, "@", super->path_element->host, flags, "/", - super->path_element->path, (char *) NULL); + name = vfs_path_element_build_pretty_path_str (super->path_element); func (name); g_free (name); } diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index b04492507..384a5387e 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -262,7 +262,6 @@ static const char *netrcp; c) strip trailing "/." */ -static char *ftpfs_get_current_directory (struct vfs_class *me, struct vfs_s_super *super); static int ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, const char *remote_path); static int ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, @@ -961,10 +960,6 @@ ftpfs_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) } while (retry_seconds != 0); - super->path_element->path = ftpfs_get_current_directory (me, super); - if (super->path_element->path == NULL) - super->path_element->path = g_strdup (PATH_SEP_STR); - return 0; } @@ -1017,57 +1012,6 @@ ftpfs_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_super } /* --------------------------------------------------------------------------------------------- */ -/* The returned directory should always contain a trailing slash */ - -static char * -ftpfs_get_current_directory (struct vfs_class *me, struct vfs_s_super *super) -{ - char buf[BUF_8K], *bufp, *bufq; - - if (ftpfs_command (me, super, NONE, "PWD") == COMPLETE && - ftpfs_get_reply (me, SUP->sock, buf, sizeof (buf)) == COMPLETE) - { - bufp = NULL; - for (bufq = buf; *bufq; bufq++) - if (*bufq == '"') - { - if (!bufp) - { - bufp = bufq + 1; - } - else - { - *bufq = 0; - if (*bufp) - { - if (*(bufq - 1) != '/') - { - *bufq++ = '/'; - *bufq = 0; - } - if (*bufp == '/') - return g_strdup (bufp); - else - { - /* If the remote server is an Amiga a leading slash - might be missing. MC needs it because it is used - as separator between hostname and path internally. */ - return g_strconcat ("/", bufp, (char *) NULL); - } - } - else - { - ftpfs_errno = EIO; - return NULL; - } - } - } - } - ftpfs_errno = EIO; - return NULL; -} - -/* --------------------------------------------------------------------------------------------- */ /* Setup Passive PASV FTP connection */ static int @@ -2070,11 +2014,7 @@ ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, const cha if (r != COMPLETE) ftpfs_errno = EIO; else - { - g_free (super->path_element->path); - super->path_element->path = g_strdup (remote_path); SUP->cwd_deferred = 0; - } return r; } @@ -2247,10 +2187,7 @@ ftpfs_fill_names (struct vfs_class *me, fill_names_f func) const struct vfs_s_super *super = (const struct vfs_s_super *) iter->data; char *name; - name = - g_strconcat (vfs_ftpfs_ops.prefix, VFS_PATH_URL_DELIMITER, super->path_element->user, - "@", super->path_element->host, "/", super->path_element->path, - (char *) NULL); + name = vfs_path_element_build_pretty_path_str (super->path_element); func (name); g_free (name); } -- 2.11.4.GIT