aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2012-02-20 14:45:43 +0100
committerBjörn Gustavsson <[email protected]>2012-09-17 12:00:17 +0200
commit67b0f0c042fe833a666fa2f6d9b882a1c66998db (patch)
treed2b33c11487d75139eb651debf9121251dc180b5 /lib/stdlib/src
parentb58ce62a0cf296ca8cd8cd77b053bc70ecf28758 (diff)
downloadotp-67b0f0c042fe833a666fa2f6d9b882a1c66998db.tar.gz
otp-67b0f0c042fe833a666fa2f6d9b882a1c66998db.tar.bz2
otp-67b0f0c042fe833a666fa2f6d9b882a1c66998db.zip
Allow ** in filelib:wildcard
Two adjacent * used as a single pattern will match all files and zero or more directories and subdirectories.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/filelib.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/stdlib/src/filelib.erl b/lib/stdlib/src/filelib.erl
index 6b19713609..318f3b87b8 100644
--- a/lib/stdlib/src/filelib.erl
+++ b/lib/stdlib/src/filelib.erl
@@ -301,6 +301,8 @@ do_wildcard_2([File|Rest], Pattern, Result, Mod) ->
do_wildcard_2([], _, Result, _Mod) ->
Result.
+do_wildcard_3(Base, [[double_star]|Rest], Result, Mod) ->
+ lists:sort(do_double_star(current, [Base], Rest, Result, Mod, true));
do_wildcard_3(Base, [Pattern|Rest], Result, Mod) ->
case do_list_dir(Base, Mod) of
{ok, Files0} ->
@@ -334,6 +336,8 @@ wildcard_5([question|Rest1], [_|Rest2]) ->
wildcard_5(Rest1, Rest2);
wildcard_5([accept], _) ->
true;
+wildcard_5([double_star], _) ->
+ true;
wildcard_5([star|Rest], File) ->
do_star(Rest, File);
wildcard_5([{one_of, Ordset}|Rest], [C|File]) ->
@@ -354,6 +358,21 @@ wildcard_5([], [_|_]) ->
wildcard_5([_|_], []) ->
false.
+do_double_star(Base, [H|T], Rest, Result, Mod, Root) ->
+ Full = join(Base, H),
+ Result1 = case do_list_dir(Full, Mod) of
+ {ok, Files} ->
+ do_double_star(Full, Files, Rest, Result, Mod, false);
+ _ -> Result
+ end,
+ Result2 = case Root andalso Rest == [] of
+ true -> Result1;
+ false -> do_wildcard_3(Full, Rest, Result1, Mod)
+ end,
+ do_double_star(Base, T, Rest, Result2, Mod, Root);
+do_double_star(_Base, [], _Rest, Result, _Mod, _Root) ->
+ Result.
+
do_star(Pattern, [X|Rest]) ->
case wildcard_5(Pattern, [X|Rest]) of
true -> true;
@@ -425,6 +444,10 @@ compile_part([$}|Rest], true, Result) ->
{ok, $}, lists:reverse(Result), Rest};
compile_part([$?|Rest], Upto, Result) ->
compile_part(Rest, Upto, [question|Result]);
+compile_part([$*,$*], Upto, Result) ->
+ compile_part([], Upto, [double_star|Result]);
+compile_part([$*,$*|Rest], Upto, Result) ->
+ compile_part(Rest, Upto, [star|Result]);
compile_part([$*], Upto, Result) ->
compile_part([], Upto, [accept|Result]);
compile_part([$*|Rest], Upto, Result) ->