Skip to content

Instantly share code, notes, and snippets.

@ToJans
Created September 13, 2012 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToJans/3714046 to your computer and use it in GitHub Desktop.
Save ToJans/3714046 to your computer and use it in GitHub Desktop.
#!/usr/bin/env escript
%%! -pa ebin
main(_) ->
{ok, [T]} = file:consult("ebin/mimetypes.app"),
{application, mimetypes, PL} = T,
DynMods = [mimetypes:dmodule(),mimetypes:mmodule()],
BaseModules = proplists:get_value(modules, PL) -- DynMods,
Modules = DynMods ++ BaseModules,
Timestamps = last(["priv/mime.types"|files(BaseModules)]),
[DModTimestamp,MModTimestamp] = last(files(DynMods)),
DynMinTimestamp = erlang:min(DModTimestamp, MModTimestamp),
case lists:any(fun(TS) ->
TS > DynMinTimestamp
end, Timestamps) of
true ->
%% [ file:delete(F) || F <- files(DynMods) ],
%% ok = application:start(mimetypes),
%% ok = application:stop(mimetypes),
%% {ok, F} = file:open("ebin/mimetypes.app",[write]),
%% NewPL = lists:keyreplace(modules, 1, PL, {modules, Modules}),
%% NewApp = {application, mimetypes, NewPL},
%% io:format(F, "~s.\n", [io_lib_pretty:print(NewApp)]),
%% file:close(F);
ok;
false ->
%% everything is up to date
ok
end.
files([]) ->
[];
files([H|T]) ->
[ filename:join(["ebin",atom_to_list(H) ++ ".beam"]) | files(T) ].
last(Files) ->
[ case filelib:last_modified(F) of 0 -> 0; M -> calendar:datetime_to_gregorian_seconds(M) end || F <- Files ].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment