mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 14:58:18 +00:00
Change prefix from os_*
to path_*
This commit is contained in:

committed by
Thiago de Arruda

parent
aa7218b646
commit
6fb58d1c5c
@@ -2418,7 +2418,7 @@ void buflist_altfpos(win_T *win)
|
||||
|
||||
/*
|
||||
* Return TRUE if 'ffname' is not the same file as current file.
|
||||
* Fname must have a full path (expanded by os_get_absolute_path()).
|
||||
* Fname must have a full path (expanded by path_get_absolute_path()).
|
||||
*/
|
||||
int otherfile(char_u *ffname)
|
||||
{
|
||||
|
@@ -8562,7 +8562,7 @@ static void f_eventhandler(typval_T *argvars, typval_T *rettv)
|
||||
*/
|
||||
static void f_executable(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
rettv->vval.v_number = os_can_exe(get_tv_string(&argvars[0]));
|
||||
rettv->vval.v_number = path_can_exe(get_tv_string(&argvars[0]));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -12617,7 +12617,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
||||
q[-1] = NUL;
|
||||
q = path_tail(p);
|
||||
}
|
||||
if (q > p && !os_is_absolute_path(buf)) {
|
||||
if (q > p && !path_is_absolute_path(buf)) {
|
||||
/* symlink is relative to directory of argument */
|
||||
cpy = alloc((unsigned)(STRLEN(p) + STRLEN(buf) + 1));
|
||||
if (cpy != NULL) {
|
||||
|
@@ -3964,7 +3964,7 @@ expand_shellcmd (
|
||||
flags |= EW_FILE | EW_EXEC;
|
||||
|
||||
/* For an absolute name we don't use $PATH. */
|
||||
if (os_is_absolute_path(pat))
|
||||
if (path_is_absolute_path(pat))
|
||||
path = (char_u *)" ";
|
||||
else if ((pat[0] == '.' && (vim_ispathsep(pat[1])
|
||||
|| (pat[1] == '.' && vim_ispathsep(pat[2])))))
|
||||
|
@@ -4670,7 +4670,7 @@ void shorten_fnames(int force)
|
||||
&& !path_with_url(buf->b_fname)
|
||||
&& (force
|
||||
|| buf->b_sfname == NULL
|
||||
|| os_is_absolute_path(buf->b_sfname))) {
|
||||
|| path_is_absolute_path(buf->b_sfname))) {
|
||||
vim_free(buf->b_sfname);
|
||||
buf->b_sfname = NULL;
|
||||
p = shorten_fname(buf->b_ffname, dirname);
|
||||
|
@@ -3381,7 +3381,7 @@ int resolve_symlink(char_u *fname, char_u *buf)
|
||||
* portion of the filename (if any) and the path the symlink
|
||||
* points to.
|
||||
*/
|
||||
if (os_is_absolute_path(buf))
|
||||
if (path_is_absolute_path(buf))
|
||||
STRCPY(tmp, buf);
|
||||
else {
|
||||
char_u *tail;
|
||||
|
@@ -1418,7 +1418,7 @@ int flags; /* EW_* flags */
|
||||
continue;
|
||||
|
||||
/* Skip files that are not executable if we check for that. */
|
||||
if (!dir && (flags & EW_EXEC) && !os_can_exe((*file)[i]))
|
||||
if (!dir && (flags & EW_EXEC) && !path_can_exe((*file)[i]))
|
||||
continue;
|
||||
|
||||
p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir));
|
||||
|
24
src/path.c
24
src/path.c
@@ -656,7 +656,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
|
||||
else if (path_with_url(buf))
|
||||
/* URL can't be used here */
|
||||
continue;
|
||||
else if (!os_is_absolute_path(buf)) {
|
||||
else if (!path_is_absolute_path(buf)) {
|
||||
/* Expand relative path to their full path equivalent */
|
||||
len = (int)STRLEN(curdir);
|
||||
if (len + (int)STRLEN(buf) + 3 > MAXPATHL)
|
||||
@@ -794,7 +794,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
|
||||
break;
|
||||
}
|
||||
|
||||
if (os_is_absolute_path(path)) {
|
||||
if (path_is_absolute_path(path)) {
|
||||
/*
|
||||
* Last resort: shorten relative to curdir if possible.
|
||||
* 'possible' means:
|
||||
@@ -1090,7 +1090,7 @@ gen_expand_wildcards (
|
||||
*/
|
||||
if (mch_has_exp_wildcard(p)) {
|
||||
if ((flags & EW_PATH)
|
||||
&& !os_is_absolute_path(p)
|
||||
&& !path_is_absolute_path(p)
|
||||
&& !(p[0] == '.'
|
||||
&& (vim_ispathsep(p[1])
|
||||
|| (p[1] == '.' && vim_ispathsep(p[2]))))
|
||||
@@ -1229,7 +1229,7 @@ addfile (
|
||||
return;
|
||||
|
||||
/* If the file isn't executable, may not add it. Do accept directories. */
|
||||
if (!isdir && (flags & EW_EXEC) && !os_can_exe(f))
|
||||
if (!isdir && (flags & EW_EXEC) && !path_can_exe(f))
|
||||
return;
|
||||
|
||||
/* Make room for another item in the file list. */
|
||||
@@ -1532,7 +1532,7 @@ int path_with_url(char_u *fname)
|
||||
*/
|
||||
int vim_isAbsName(char_u *name)
|
||||
{
|
||||
return path_with_url(name) != 0 || os_is_absolute_path(name);
|
||||
return path_with_url(name) != 0 || path_is_absolute_path(name);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1557,7 +1557,7 @@ vim_FullName (
|
||||
|
||||
url = path_with_url(fname);
|
||||
if (!url)
|
||||
retval = os_get_absolute_path(fname, buf, len, force);
|
||||
retval = path_get_absolute_path(fname, buf, len, force);
|
||||
if (url || retval == FAIL) {
|
||||
/* something failed; use the file name (truncate when too long) */
|
||||
vim_strncpy(buf, fname, len - 1);
|
||||
@@ -1947,7 +1947,7 @@ int match_suffix(char_u *fname)
|
||||
///
|
||||
/// @param directory Directory name, relative to current directory.
|
||||
/// @return `FAIL` for failure, `OK` for success.
|
||||
int os_full_dir_name(char *directory, char *buffer, int len)
|
||||
int path_full_dir_name(char *directory, char *buffer, int len)
|
||||
{
|
||||
int SUCCESS = 0;
|
||||
int retval = OK;
|
||||
@@ -2031,7 +2031,7 @@ int append_path(char *path, const char *to_append, int max_len)
|
||||
/// @param len Length of `buf`.
|
||||
/// @param force Also expand when `fname` is already absolute.
|
||||
/// @return `FAIL` for failure, `OK` for success.
|
||||
static int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
|
||||
static int path_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
|
||||
{
|
||||
char_u *p;
|
||||
*buf = NUL;
|
||||
@@ -2040,7 +2040,7 @@ static int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
|
||||
char *end_of_path = (char *) fname;
|
||||
|
||||
// expand it if forced or not an absolute path
|
||||
if (force || !os_is_absolute_path(fname)) {
|
||||
if (force || !path_is_absolute_path(fname)) {
|
||||
if ((p = vim_strrchr(fname, '/')) != NULL) {
|
||||
STRNCPY(relative_directory, fname, p-fname);
|
||||
relative_directory[p-fname] = NUL;
|
||||
@@ -2050,14 +2050,14 @@ static int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
|
||||
end_of_path = (char *) fname;
|
||||
}
|
||||
|
||||
if (FAIL == os_full_dir_name(relative_directory, (char *) buf, len)) {
|
||||
if (FAIL == path_full_dir_name(relative_directory, (char *) buf, len)) {
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
return append_path((char *) buf, (char *) end_of_path, len);
|
||||
}
|
||||
|
||||
int os_is_absolute_path(const char_u *fname)
|
||||
int path_is_absolute_path(const char_u *fname)
|
||||
{
|
||||
return *fname == '/' || *fname == '~';
|
||||
}
|
||||
@@ -2065,7 +2065,7 @@ int os_is_absolute_path(const char_u *fname)
|
||||
bool os_can_exe(const char_u *name)
|
||||
{
|
||||
// If it's an absolute or relative path don't need to use $PATH.
|
||||
if (os_is_absolute_path(name) ||
|
||||
if (path_is_absolute_path(name) ||
|
||||
(name[0] == '.' && (name[1] == '/' ||
|
||||
(name[1] == '.' && name[2] == '/')))) {
|
||||
return is_executable(name);
|
||||
|
@@ -92,7 +92,7 @@ int match_suffix(char_u *fname);
|
||||
///
|
||||
/// @param directory Directory name, relative to current directory.
|
||||
/// @return `FAIL` for failure, `OK` for success.
|
||||
int os_full_dir_name(char *directory, char *buffer, int len);
|
||||
int path_full_dir_name(char *directory, char *buffer, int len);
|
||||
|
||||
// Append to_append to path with a slash in between.
|
||||
int append_path(char *path, const char *to_append, int max_len);
|
||||
@@ -101,7 +101,7 @@ int append_path(char *path, const char *to_append, int max_len);
|
||||
///
|
||||
/// This just checks if the file name starts with '/' or '~'.
|
||||
/// @return `TRUE` if "fname" is absolute.
|
||||
int os_is_absolute_path(const char_u *fname);
|
||||
int path_is_absolute_path(const char_u *fname);
|
||||
|
||||
/// Check if the given path represents an executable file.
|
||||
///
|
||||
@@ -111,6 +111,6 @@ int os_is_absolute_path(const char_u *fname);
|
||||
/// - is absolute.
|
||||
///
|
||||
/// @return `FALSE` otherwise.
|
||||
int os_can_exe(const char_u *name);
|
||||
int path_can_exe(const char_u *name);
|
||||
|
||||
#endif
|
||||
|
@@ -4202,7 +4202,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
|
||||
*/
|
||||
eap->argt |= (XFILE | NOSPC);
|
||||
separate_nextcmd(eap);
|
||||
if (*eap->arg == '<' || *eap->arg == '$' || os_is_absolute_path(eap->arg)) {
|
||||
if (*eap->arg == '<' || *eap->arg == '$' || path_is_absolute_path(eap->arg)) {
|
||||
/* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
|
||||
* file. Need to expand the file name first. In other cases
|
||||
* ":runtime!" is used. */
|
||||
|
@@ -61,12 +61,12 @@ describe 'fs function', ->
|
||||
buf = cstr (len-1), ''
|
||||
eq FAIL, (os_dirname buf, (len-1))
|
||||
|
||||
describe 'os_full_dir_name', ->
|
||||
ffi.cdef 'int os_full_dir_name(char *directory, char *buffer, int len);'
|
||||
describe 'path_full_dir_name', ->
|
||||
ffi.cdef 'int path_full_dir_name(char *directory, char *buffer, int len);'
|
||||
|
||||
os_full_dir_name = (directory, buffer, len) ->
|
||||
path_full_dir_name = (directory, buffer, len) ->
|
||||
directory = to_cstr directory
|
||||
fs.os_full_dir_name directory, buffer, len
|
||||
fs.path_full_dir_name directory, buffer, len
|
||||
|
||||
before_each ->
|
||||
-- Create empty string buffer which will contain the resulting path.
|
||||
@@ -74,7 +74,7 @@ describe 'fs function', ->
|
||||
export buffer = cstr len, ''
|
||||
|
||||
it 'returns the absolute directory name of a given relative one', ->
|
||||
result = os_full_dir_name '..', buffer, len
|
||||
result = path_full_dir_name '..', buffer, len
|
||||
eq OK, result
|
||||
old_dir = lfs.currentdir!
|
||||
lfs.chdir '..'
|
||||
@@ -83,14 +83,14 @@ describe 'fs function', ->
|
||||
eq expected, (ffi.string buffer)
|
||||
|
||||
it 'returns the current directory name if the given string is empty', ->
|
||||
eq OK, (os_full_dir_name '', buffer, len)
|
||||
eq OK, (path_full_dir_name '', buffer, len)
|
||||
eq lfs.currentdir!, (ffi.string buffer)
|
||||
|
||||
it 'fails if the given directory does not exist', ->
|
||||
eq FAIL, os_full_dir_name('does_not_exist', buffer, len)
|
||||
eq FAIL, path_full_dir_name('does_not_exist', buffer, len)
|
||||
|
||||
it 'works with a normal relative dir', ->
|
||||
result = os_full_dir_name('unit-test-directory', buffer, len)
|
||||
result = path_full_dir_name('unit-test-directory', buffer, len)
|
||||
eq lfs.currentdir! .. '/unit-test-directory', (ffi.string buffer)
|
||||
eq OK, result
|
||||
|
||||
|
@@ -12,7 +12,7 @@ char_u *path_tail(char_u *fname);
|
||||
char_u *path_tail_with_sep(char_u *fname);
|
||||
char_u *path_next_component(char_u *fname);
|
||||
int is_executable(char_u *name);
|
||||
int os_can_exe(char_u *name);
|
||||
int path_can_exe(char_u *name);
|
||||
]]
|
||||
|
||||
|
||||
@@ -249,41 +249,41 @@ describe 'more path function', ->
|
||||
eq OK, (path.append_path path1, to_append, 7)
|
||||
eq '/path2', (ffi.string path1)
|
||||
|
||||
describe 'os_is_absolute_path', ->
|
||||
ffi.cdef 'int os_is_absolute_path(char *fname);'
|
||||
describe 'path_is_absolute_path', ->
|
||||
ffi.cdef 'int path_is_absolute_path(char *fname);'
|
||||
|
||||
os_is_absolute_path = (filename) ->
|
||||
path_is_absolute_path = (filename) ->
|
||||
filename = to_cstr filename
|
||||
path.os_is_absolute_path filename
|
||||
path.path_is_absolute_path filename
|
||||
|
||||
it 'returns true if filename starts with a slash', ->
|
||||
eq OK, os_is_absolute_path '/some/directory/'
|
||||
eq OK, path_is_absolute_path '/some/directory/'
|
||||
|
||||
it 'returns true if filename starts with a tilde', ->
|
||||
eq OK, os_is_absolute_path '~/in/my/home~/directory'
|
||||
eq OK, path_is_absolute_path '~/in/my/home~/directory'
|
||||
|
||||
it 'returns false if filename starts not with slash nor tilde', ->
|
||||
eq FAIL, os_is_absolute_path 'not/in/my/home~/directory'
|
||||
eq FAIL, path_is_absolute_path 'not/in/my/home~/directory'
|
||||
|
||||
describe 'os_can_exe', ->
|
||||
os_can_exe = (name) ->
|
||||
path.os_can_exe (to_cstr name)
|
||||
describe 'path_can_exe', ->
|
||||
path_can_exe = (name) ->
|
||||
path.path_can_exe (to_cstr name)
|
||||
|
||||
it 'returns false when given a directory', ->
|
||||
eq FALSE, (os_can_exe './unit-test-directory')
|
||||
eq FALSE, (path_can_exe './unit-test-directory')
|
||||
|
||||
it 'returns false when given a regular file without executable bit set', ->
|
||||
eq FALSE, (os_can_exe 'unit-test-directory/test.file')
|
||||
eq FALSE, (path_can_exe 'unit-test-directory/test.file')
|
||||
|
||||
it 'returns false when the given file does not exists', ->
|
||||
eq FALSE, (os_can_exe 'does-not-exist.file')
|
||||
eq FALSE, (path_can_exe 'does-not-exist.file')
|
||||
|
||||
it 'returns true when given an executable inside $PATH', ->
|
||||
eq TRUE, (os_can_exe executable_name)
|
||||
eq TRUE, (path_can_exe executable_name)
|
||||
|
||||
it 'returns true when given an executable relative to the current dir', ->
|
||||
old_dir = lfs.currentdir!
|
||||
lfs.chdir directory
|
||||
relative_executable = './' .. executable_name
|
||||
eq TRUE, (os_can_exe relative_executable)
|
||||
eq TRUE, (path_can_exe relative_executable)
|
||||
lfs.chdir old_dir
|
||||
|
Reference in New Issue
Block a user