To: vim_dev@googlegroups.com Subject: Patch 8.2.0947 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0947 Problem: Readdirex() doesn't handle broken link properly. Solution: Small fixes to readdirex(). (Christian Brabandt, closes #6226, closes #6213) Files: src/fileio.c, src/testdir/test_functions.vim *** ../vim-8.2.0946/src/fileio.c 2020-06-02 22:19:45.306490745 +0200 --- src/fileio.c 2020-06-10 15:53:08.291536423 +0200 *************** *** 4544,4550 **** int ret, link = FALSE; varnumber_T size; char_u permbuf[] = "---------"; ! char_u *q; struct passwd *pw; struct group *gr; --- 4544,4550 ---- int ret, link = FALSE; varnumber_T size; char_u permbuf[] = "---------"; ! char_u *q = NULL; struct passwd *pw; struct group *gr; *************** *** 4563,4568 **** --- 4563,4571 ---- { link = TRUE; ret = mch_stat(p, &st); + if (ret < 0) + q = (char_u*)"link"; + } vim_free(p); *************** *** 4617,4623 **** goto theend; if (dict_add_number(item, "time", -1) == FAIL) goto theend; ! if (dict_add_string(item, "type", (char_u*)"") == FAIL) goto theend; if (dict_add_string(item, "perm", (char_u*)"") == FAIL) goto theend; --- 4620,4626 ---- goto theend; if (dict_add_number(item, "time", -1) == FAIL) goto theend; ! if (dict_add_string(item, "type", q == NULL ? (char_u*)"" : q) == FAIL) goto theend; if (dict_add_string(item, "perm", (char_u*)"") == FAIL) goto theend; *************** *** 4719,4724 **** --- 4722,4732 ---- ignore = wp[0] == L'.' && (wp[1] == NUL || (wp[1] == L'.' && wp[2] == NUL)); + if (ignore) + { + ok = FindNextFileW(hFind, &wfd); + continue; + } # ifdef FEAT_EVAL if (withattr) item = (void*)create_readdirex_item(&wfd); *************** *** 4787,4792 **** --- 4795,4802 ---- ignore = p[0] == '.' && (p[1] == NUL || (p[1] == '.' && p[2] == NUL)); + if (ignore) + continue; # ifdef FEAT_EVAL if (withattr) item = (void*)create_readdirex_item(path, p); *** ../vim-8.2.0946/src/testdir/test_functions.vim 2020-06-10 15:45:54.496849260 +0200 --- src/testdir/test_functions.vim 2020-06-10 15:53:08.291536423 +0200 *************** *** 1912,1917 **** --- 1912,1927 ---- \ ->map({-> v:val.name}) 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') endfunc *** ../vim-8.2.0946/src/version.c 2020-06-10 15:45:54.496849260 +0200 --- src/version.c 2020-06-10 15:55:13.307150503 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 947, /**/ -- "Shoot for the moon. Even if you miss, you'll land among the stars." /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///