diff options
author | Tomas Abrahamsson <tomas.abrahamsson@gmail.com> | 2014-12-31 03:46:13 +0100 |
---|---|---|
committer | Tomas Abrahamsson <tomas.abrahamsson@gmail.com> | 2015-01-24 22:11:04 +0100 |
commit | a04530124ffa16c50205695d35f9274107e2fa42 (patch) | |
tree | e93b3c5de16b057257e9df5dba38a99390398f18 /src/rebar_utils.erl | |
parent | 83156cc1efa5021229dcb2dc4e360c7c4b3d77b5 (diff) | |
download | rebar-a04530124ffa16c50205695d35f9274107e2fa42.tar.gz |
Add rebar_utils:find_files_by_ext/2,3
This finds files by extension, avoiding resource fork files
in Mac OS X.
Diffstat (limited to 'src/rebar_utils.erl')
-rw-r--r-- | src/rebar_utils.erl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index a04798e..aa29364 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -34,6 +34,8 @@ sh_send/3, find_files/2, find_files/3, + find_files_by_ext/2, + find_files_by_ext/3, now_str/0, ensure_dir/1, beam_to_mod/2, @@ -160,6 +162,28 @@ find_files(Dir, Regex, Recursive) -> filelib:fold_files(Dir, Regex, Recursive, fun(F, Acc) -> [F | Acc] end, []). +%% Find files by extension, for example ".erl", avoiding resource fork +%% files in OS X. Such files are named for example src/._xyz.erl +%% Such files may also appear with network filesystems on OS X. +%% +%% The Ext is really a regexp, with any leading dot implicitly +%% escaped, and anchored at the end of the string. +%% +find_files_by_ext(Dir, Ext) -> + find_files_by_ext(Dir, Ext, true). + +find_files_by_ext(Dir, Ext, Recursive) -> + %% Convert simple extension to proper regex + EscapeDot = case Ext of + "." ++ _ -> + "\\"; + _ -> + %% allow for other suffixes, such as _pb.erl + "" + end, + ExtRe = "^[^._].*" ++ EscapeDot ++ Ext ++ [$$], + find_files(Dir, ExtRe, Recursive). + now_str() -> {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:local_time(), lists:flatten(io_lib:format("~4b/~2..0b/~2..0b ~2..0b:~2..0b:~2..0b", |