Changed interface of function mc_symlink()

...to handle vfs_path_t object as parameter.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-07-21 18:24:20 +03:00
parent 890f1f9242
commit 82e07617ae
4 changed files with 38 additions and 29 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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 ();

View File

@ -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;
}