mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 8.2.0947: readdirex() doesn't handle broken link properly
Problem: Readdirex() doesn't handle broken link properly. Solution: Small fixes to readdirex(). (Christian Brabandt, closes #6226, closes #6213)
This commit is contained in:
14
src/fileio.c
14
src/fileio.c
@@ -4544,7 +4544,7 @@ create_readdirex_item(char_u *path, char_u *name)
|
|||||||
int ret, link = FALSE;
|
int ret, link = FALSE;
|
||||||
varnumber_T size;
|
varnumber_T size;
|
||||||
char_u permbuf[] = "---------";
|
char_u permbuf[] = "---------";
|
||||||
char_u *q;
|
char_u *q = NULL;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
struct group *gr;
|
struct group *gr;
|
||||||
|
|
||||||
@@ -4563,6 +4563,9 @@ create_readdirex_item(char_u *path, char_u *name)
|
|||||||
{
|
{
|
||||||
link = TRUE;
|
link = TRUE;
|
||||||
ret = mch_stat(p, &st);
|
ret = mch_stat(p, &st);
|
||||||
|
if (ret < 0)
|
||||||
|
q = (char_u*)"link";
|
||||||
|
|
||||||
}
|
}
|
||||||
vim_free(p);
|
vim_free(p);
|
||||||
|
|
||||||
@@ -4617,7 +4620,7 @@ create_readdirex_item(char_u *path, char_u *name)
|
|||||||
goto theend;
|
goto theend;
|
||||||
if (dict_add_number(item, "time", -1) == FAIL)
|
if (dict_add_number(item, "time", -1) == FAIL)
|
||||||
goto theend;
|
goto theend;
|
||||||
if (dict_add_string(item, "type", (char_u*)"") == FAIL)
|
if (dict_add_string(item, "type", q == NULL ? (char_u*)"" : q) == FAIL)
|
||||||
goto theend;
|
goto theend;
|
||||||
if (dict_add_string(item, "perm", (char_u*)"") == FAIL)
|
if (dict_add_string(item, "perm", (char_u*)"") == FAIL)
|
||||||
goto theend;
|
goto theend;
|
||||||
@@ -4719,6 +4722,11 @@ readdir_core(
|
|||||||
ignore = wp[0] == L'.' &&
|
ignore = wp[0] == L'.' &&
|
||||||
(wp[1] == NUL ||
|
(wp[1] == NUL ||
|
||||||
(wp[1] == L'.' && wp[2] == NUL));
|
(wp[1] == L'.' && wp[2] == NUL));
|
||||||
|
if (ignore)
|
||||||
|
{
|
||||||
|
ok = FindNextFileW(hFind, &wfd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
# ifdef FEAT_EVAL
|
# ifdef FEAT_EVAL
|
||||||
if (withattr)
|
if (withattr)
|
||||||
item = (void*)create_readdirex_item(&wfd);
|
item = (void*)create_readdirex_item(&wfd);
|
||||||
@@ -4787,6 +4795,8 @@ readdir_core(
|
|||||||
ignore = p[0] == '.' &&
|
ignore = p[0] == '.' &&
|
||||||
(p[1] == NUL ||
|
(p[1] == NUL ||
|
||||||
(p[1] == '.' && p[2] == NUL));
|
(p[1] == '.' && p[2] == NUL));
|
||||||
|
if (ignore)
|
||||||
|
continue;
|
||||||
# ifdef FEAT_EVAL
|
# ifdef FEAT_EVAL
|
||||||
if (withattr)
|
if (withattr)
|
||||||
item = (void*)create_readdirex_item(path, p);
|
item = (void*)create_readdirex_item(path, p);
|
||||||
|
@@ -1912,6 +1912,16 @@ func Test_readdirex()
|
|||||||
\ ->map({-> v:val.name})
|
\ ->map({-> v:val.name})
|
||||||
call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt'])
|
call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt'])
|
||||||
|
|
||||||
|
" report brocken link correctly
|
||||||
|
if has("unix")
|
||||||
|
call writefile([], 'Xdir/abc.txt')
|
||||||
|
call system("ln -s Xdir/abc.txt Xdir/link")
|
||||||
|
call delete('Xdir/abc.txt')
|
||||||
|
let files = readdirex('Xdir', 'readdirex("Xdir", "1") != []')
|
||||||
|
\ ->map({-> v:val.name .. '_' .. v:val.type})
|
||||||
|
call sort(files)->assert_equal(
|
||||||
|
\ ['bar.txt_file', 'dir_dir', 'foo.txt_file', 'link_link'])
|
||||||
|
endif
|
||||||
eval 'Xdir'->delete('rf')
|
eval 'Xdir'->delete('rf')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
947,
|
||||||
/**/
|
/**/
|
||||||
946,
|
946,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user