Change resolve() to resolve symbolic links on Windows

This commit is contained in:
erw7
2020-03-25 15:50:55 +09:00
parent a8f7841924
commit f61331e184
2 changed files with 28 additions and 1 deletions

View File

@@ -6709,7 +6709,10 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->v_type = VAR_STRING;
const char *fname = tv_get_string(&argvars[0]);
#ifdef WIN32
char *const v = os_resolve_shortcut(fname);
char *v = os_resolve_shortcut(fname);
if (v == NULL) {
v = os_realpath(fname, v);
}
rettv->vval.v_string = (char_u *)(v == NULL ? xstrdup(fname) : v);
#else
# ifdef HAVE_READLINK

View File

@@ -1147,6 +1147,30 @@ bool os_fileid_equal_fileinfo(const FileID *file_id,
&& file_id->device_id == file_info->stat.st_dev;
}
/// Return the canonicalized absolute pathname.
///
/// @param[in] name Filename to be canonicalized.
/// @param[out] buf Buffer to store the canonicalized values. A minimum length
// of MAXPATHL+1 is required. If it is NULL, memory is
// allocated. In that case, the caller should deallocate this
// buffer.
///
/// @return pointer to the buf on success, or NULL.
char *os_realpath(const char *name, char *buf)
FUNC_ATTR_NONNULL_ARG(1)
{
uv_fs_t request;
int result = uv_fs_realpath(&fs_loop, &request, name, NULL);
if (result == kLibuvSuccess) {
if (buf == NULL) {
buf = xmallocz(MAXPATHL);
}
xstrlcpy(buf, request.ptr, MAXPATHL + 1);
}
uv_fs_req_cleanup(&request);
return result == kLibuvSuccess ? buf : NULL;
}
#ifdef WIN32
# include <shlobj.h>