Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:18
erlang
0593-Fix-filelib-wildcard-1-2-for-not-a-directo...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0593-Fix-filelib-wildcard-1-2-for-not-a-directory.patch of Package erlang
From f7bc9fc284a46b906dba5c935628855adbc7a258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Wed, 3 Jun 2020 13:29:24 +0200 Subject: [PATCH] Fix filelib:wildcard/1,2 for "not-a-directory/.." --- lib/stdlib/src/filelib.erl | 38 +++++++++++++++++++++++++++---- lib/stdlib/test/filelib_SUITE.erl | 2 ++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/stdlib/src/filelib.erl b/lib/stdlib/src/filelib.erl index 565f00b0a5..7f8c282a79 100644 --- a/lib/stdlib/src/filelib.erl +++ b/lib/stdlib/src/filelib.erl @@ -268,9 +268,9 @@ do_wildcard(Pattern, Cwd, Mod) -> lists:sort(Files). do_wildcard_1({exists,File}, Mod) -> - case eval_read_link_info(File, Mod) of - {ok,_} -> [File]; - _ -> [] + case exists(File, Mod) of + true -> [File]; + false -> [] end; do_wildcard_1([Base|Rest], Mod) -> do_wildcard_2([Base], Rest, [], Mod). @@ -562,6 +562,36 @@ wrap_escapes([]) -> badpattern(Reason) -> error({badpattern,Reason}). +exists(File, Mod) -> + case eval_read_link_info(File, Mod) of + {error, _} -> + false; + {ok, _Info} -> + case os:type() of + {win32,_} -> + do_exists(filename:split(File), Mod, []); + _ -> + true + end + end. + +do_exists([P,".."|Ps], Mod, Acc) -> + %% On Windows, "pathname/.." will seem to exist even if pathname + %% does not refer to a directory. + Path = case Acc of + [] -> P; + _ -> filename:join(lists:reverse(Acc, [P])) + end, + case eval_read_link_info(Path, Mod) of + {ok, #file_info{type=directory}} -> + do_exists(Ps, Mod, Acc); + _ -> + false + end; +do_exists([P|Ps], Mod, Acc) -> + do_exists(Ps, Mod, [P|Acc]); +do_exists([], _, _) -> true. + eval_read_file_info(File, file) -> file:read_file_info(File); eval_read_file_info(File, erl_prim_loader) -> diff --git a/lib/stdlib/test/filelib_SUITE.erl b/lib/stdlib/test/filelib_SUITE.erl index 367dd6b407..203ba2c31e 100644 --- a/lib/stdlib/test/filelib_SUITE.erl +++ b/lib/stdlib/test/filelib_SUITE.erl @@ -123,6 +123,8 @@ wcc(Wc, Error) -> {'EXIT',{{badpattern,Error}, [{filelib,wildcard,2,_}|_]}} = (catch filelib:wildcard(Wc, ".")). +disable_prefix_opt([_,$:|_]=Wc) -> + Wc; disable_prefix_opt([C|Wc]) when $a =< C, C =< $z; C =:= $@ -> %% There is an optimization for patterns that have a literal prefix %% (such as "lib/compiler/ebin/*"). Test that we'll get the same result -- 2.26.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor