Skip to content

Commit

Permalink
Check if files exist before loading them into GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
iliastsi committed Sep 5, 2012
1 parent 3b6e775 commit 12a4ee2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/gui.erl
Expand Up @@ -820,7 +820,8 @@ loadPrefs(Options) ->
false -> continue;
{'files', Files} ->
AbsFiles = lists:map(fun filename:absname/1, Files),
addListItems(?MODULE_LIST, AbsFiles)
ErlFiles = lists:filter(fun util:is_erl_source/1, AbsFiles),
addListItems(?MODULE_LIST, ErlFiles)
end,
%% Set include_dirs
case lists:keyfind('include', 1, Options) of
Expand Down
18 changes: 17 additions & 1 deletion src/util.erl
Expand Up @@ -14,8 +14,9 @@

-module(util).
-export([doc/1, test/0, flat_format/2, flush_mailbox/0,
funs/1, funs/2, funLine/3]).
is_erl_source/1, funs/1, funs/2, funLine/3]).

-include_lib("kernel/include/file.hrl").
-include("gen.hrl").

%% @spec doc(string()) -> 'ok'
Expand Down Expand Up @@ -52,6 +53,21 @@ flush_mailbox() ->
after 0 -> ok
end.

%% @spec is_erl_source(file:filename()) -> boolean()
%% @doc: Check if file exists and has `.erl' suffix
-spec is_erl_source(file:filename()) -> boolean().

is_erl_source(File) ->
case filename:extension(File) of
".erl" ->
case file:read_file_info(File) of
{ok, Info} ->
Info#file_info.type == 'regular';
_Error -> false
end;
_Other -> false
end.

%% @spec funs(string()) -> [{atom(), non_neg_integer()}]
%% @doc: Same as `funs(File, tuple)'.
-spec funs(string()) -> [{atom(), arity()}].
Expand Down

0 comments on commit 12a4ee2

Please sign in to comment.