From 82e07617ae5ffd57b0c21c0fa2b9c2c06777f6ba Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 21 Jul 2011 18:24:20 +0300 Subject: [PATCH] Changed interface of function mc_symlink() ...to handle vfs_path_t object as parameter. Signed-off-by: Slava Zanko --- lib/vfs/interface.c | 22 +++++++++------------- lib/vfs/vfs.h | 2 +- src/filemanager/cmd.c | 13 +++++++++++-- src/filemanager/file.c | 30 +++++++++++++++++------------- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index fa3d41db7..0b74d7a39 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -256,34 +256,30 @@ MC_NAMEOP (mknod, (const vfs_path_t *vpath, mode_t mode, dev_t dev), (vpath, mod /* --------------------------------------------------------------------------------------------- */ int -mc_symlink (const char *name1, const char *path) +mc_symlink (const vfs_path_t *vpath1, const vfs_path_t *vpath2) { int result = -1; - vfs_path_t *vpath1, *vpath2; - vpath1 = vfs_path_from_str (path); if (vpath1 == NULL) return -1; - vpath2 = vfs_path_from_str_flags (name1, VPF_NO_CANON); - - if (vpath2 != NULL) + if (vpath1 != NULL) { - vfs_path_element_t *path_element = vfs_path_get_by_index (vpath1, -1); + vfs_path_element_t *path_element; + + path_element = vfs_path_get_by_index (vpath2, -1); if (vfs_path_element_valid (path_element)) { result = - path_element->class->symlink != - NULL ? path_element->class->symlink (vpath2, vpath1) : -1; + path_element->class->symlink != NULL ? + path_element->class->symlink (vpath1, vpath2) : -1; if (result == -1) errno = - path_element->class->symlink != - NULL ? vfs_ferrno (path_element->class) : E_NOTSUPP; + path_element->class->symlink != NULL ? + vfs_ferrno (path_element->class) : E_NOTSUPP; } } - vfs_path_free (vpath1); - vfs_path_free (vpath2); return result; } diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index aac6ec55c..7568776fd 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -291,7 +291,7 @@ int mc_mkdir (const vfs_path_t * vpath, mode_t mode); int mc_rmdir (const vfs_path_t * vpath); int mc_fstat (int fd, struct stat *buf); int mc_lstat (const vfs_path_t * vpath, struct stat *buf); -int mc_symlink (const char *name1, const char *name2); +int mc_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2); int mc_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2); int mc_chmod (const vfs_path_t * vpath, mode_t mode); int mc_chown (const vfs_path_t * vpath, uid_t owner, gid_t group); diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index c8debbeea..454eae4c7 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -458,6 +458,7 @@ do_link (link_type_t link_type, const char *fname) { char *s; char *d; + vfs_path_t *src_vpath; /* suggest the full path for symlink, and either the full or relative path to the file it points to */ @@ -478,8 +479,12 @@ do_link (link_type_t link_type, const char *fname) if (!dest || !*dest || !src || !*src) goto cleanup; save_cwds_stat (); - if (-1 == mc_symlink (dest, src)) + + dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON); + src_vpath = vfs_path_from_str (src); + if (mc_symlink (dest_vpath, src_vpath) == -1) message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno)); + vfs_path_free (src_vpath); } update_panels (UP_OPTIMIZE, UP_KEEPSEL); @@ -1353,9 +1358,13 @@ edit_symlink_cmd (void) } else { - if (-1 == mc_symlink (dest, p)) + vfs_path_t *dest_vpath; + + dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON); + if (mc_symlink (dest_vpath, p_vpath) == -1) message (D_ERROR, MSG_ERROR, _("edit symlink: %s"), unix_error_string (errno)); + vfs_path_free(dest_vpath); } update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); diff --git a/src/filemanager/file.c b/src/filemanager/file.c index d1682146b..d25b15542 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -372,11 +372,13 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) int len; FileProgressStatus return_status; struct stat sb; + vfs_path_t *src_vpath; + vfs_path_t *dst_vpath; gboolean dst_is_symlink; + vfs_path_t *link_target_vpath = NULL; - vfs_path_t *src_vpath = vfs_path_from_str (src_path); - vfs_path_t *dst_vpath = vfs_path_from_str (dst_path); - + src_vpath = vfs_path_from_str (src_path); + dst_vpath = vfs_path_from_str (dst_path); dst_is_symlink = (mc_lstat (dst_vpath, &sb) == 0) && S_ISLNK (sb.st_mode); retry_src_readlink: @@ -393,7 +395,7 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) if (return_status == FILE_RETRY) goto retry_src_readlink; } - return return_status; + goto ret; } link_target[len] = 0; @@ -442,13 +444,14 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) g_free (q); } } + link_target_vpath = vfs_path_from_str_flags (link_target, VPF_NO_CANON); + retry_dst_symlink: - if (mc_symlink (link_target, dst_path) == 0) + if (mc_symlink (link_target_vpath, dst_vpath) == 0) { /* Success */ - vfs_path_free (src_vpath); - vfs_path_free (dst_vpath); - return FILE_CONT; + return_status = FILE_CONT; + goto ret; } /* * if dst_exists, it is obvious that this had failed. @@ -457,13 +460,11 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) if (dst_is_symlink) { if (mc_unlink (dst_vpath) == 0) - if (mc_symlink (link_target, dst_path) == 0) + if (mc_symlink (link_target_vpath, dst_vpath) == 0) { /* Success */ - vfs_path_free (src_vpath); - vfs_path_free (dst_vpath); - - return FILE_CONT; + return_status = FILE_CONT; + goto ret; } } if (ctx->skip_all) @@ -476,8 +477,11 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) if (return_status == FILE_RETRY) goto retry_dst_symlink; } + + ret: vfs_path_free (src_vpath); vfs_path_free (dst_vpath); + vfs_path_free (link_target_vpath); return return_status; } -- 2.11.4.GIT