Permalink
Browse files

a file which has at least one compilation error shouldn't be cached i…

…n the code cache, the nect time the same file is GET'ed it a recompilation is attempted

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@169 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent fc117d0 commit 8722844f3e52a20600e008dab49b67a552b4fbf7 @klacke committed Sep 17, 2002
Showing with 41 additions and 37 deletions.
  1. +29 −30 src/yaws_compile.erl
  2. +4 −2 src/yaws_ctl.erl
  3. +8 −5 src/yaws_server.erl
View
@@ -38,9 +38,7 @@
comp_opts(GC) ->
?Debug("I=~p~n", [GC#gconf.include_dir]),
I = lists:map(fun(Dir) -> {i, Dir} end, GC#gconf.include_dir),
- YawsDir = {i, "/home/klacke/yaws/include"},
- I2 = [YawsDir | I],
- Opts = [binary, report_errors | I2],
+ Opts = [binary, report_errors | I],
?Debug("Compile opts = ~p~n", [Opts]),
Opts.
@@ -51,48 +49,49 @@ compile_file(File, GC, SC) ->
Spec = compile_file(#comp{infile = File,
infd = Fd, gc = GC, sc = SC},
1,
- io:get_line(Fd, ''), init, 0, []),
+ io:get_line(Fd, ''), init, 0, [], 0),
Spec;
_Err ->
yaws:elog("can't open ~s~n", [File]),
exit(normal)
end.
-compile_file(C, _LineNo, eof, _Mode, NumChars, Ack) ->
+compile_file(C, _LineNo, eof, _Mode, NumChars, Ack, Errors) ->
file:close(C#comp.infd),
- {ok, lists:reverse([{data, NumChars} |Ack])};
+ {ok, [{errors, Errors} |lists:reverse([{data, NumChars} |Ack])]};
%% skip initial space if first thing is <erl> otherwise not
-compile_file(C, LineNo, Chars, init, NumChars, Ack) ->
+compile_file(C, LineNo, Chars, init, NumChars, Ack, Errs) ->
case Chars -- [$\s, $\t, $\n, $\r] of
[] ->
?Debug("SKIP ~p~n", [Chars]),
L=length(Chars),
- compile_file(C, LineNo+1, line(C), init, NumChars-L, Ack);
+ compile_file(C, LineNo+1, line(C), init, NumChars-L, Ack, Errs);
"<erl>" ++ _ -> %% first chunk is erl, skip whistespace
- compile_file(C, LineNo, Chars, html, NumChars, Ack);
+ compile_file(C, LineNo, Chars, html, NumChars, Ack, Errs);
_ ->
%% first chunk is html, keep whitespace
Fd=C#comp.infd,
file:position(Fd, bof),
- compile_file(C,1,io:get_line(Fd,''),html,0,[])
+ compile_file(C,1,io:get_line(Fd,''),html,0,[], Errs)
end;
-compile_file(C, LineNo, Chars = "<erl>" ++ _Tail, html, NumChars, Ack) ->
+compile_file(C, LineNo, Chars = "<erl>" ++ _Tail, html, NumChars, Ack,Es) ->
?Debug("start erl:~p",[LineNo]),
C2 = new_out_file(LineNo, C, C#comp.gc),
C3 = C2#comp{startline = LineNo},
L = length(Chars),
if
NumChars > 0 ->
compile_file(C3, LineNo+1, line(C) , erl,L,
- [{data, NumChars} | Ack]);
+ [{data, NumChars} | Ack], Es);
true -> %% just ignore zero byte data segments
- compile_file(C3, LineNo+1, line(C) , erl, L + (-NumChars), Ack) %hack
+ compile_file(C3, LineNo+1, line(C) , erl, L + (-NumChars),
+ Ack, Es) %hack
end;
-compile_file(C, LineNo, Chars = "</erl>" ++ _Tail, erl, NumChars, Ack) ->
+compile_file(C, LineNo, Chars = "</erl>" ++ _Tail, erl, NumChars, Ack, Es) ->
?Debug("stop erl:~p",[LineNo]),
file:close(C#comp.outfd),
NumChars2 = NumChars + length(Chars),
@@ -102,18 +101,18 @@ compile_file(C, LineNo, Chars = "</erl>" ++ _Tail, erl, NumChars, Ack) ->
{module, ModuleName} ->
C2 = C#comp{modnum = C#comp.modnum+1},
L2 = check_exported(C, LineNo,NumChars2, ModuleName),
- compile_file(C2, LineNo+1, line(C),html,0,L2++Ack);
+ compile_file(C2, LineNo+1, line(C),html,0,L2++Ack, Es);
Err ->
A2 = gen_err(C, LineNo, NumChars2,
?F("Cannot load module ~p: ~p",
[ModuleName, Err])),
compile_file(C, LineNo+1, line(C),
- html, 0, [A2|Ack])
+ html, 0, [A2|Ack], Es+1)
end;
{error, Errors, _Warnings} ->
%% FIXME remove outfile here ... keep while debuging
A2 = comp_err(C, LineNo, NumChars2, Errors),
- compile_file(C, LineNo+1, line(C), html, 0, [A2|Ack]);
+ compile_file(C, LineNo+1, line(C), html, 0, [A2|Ack], Es+1);
{error, Str} ->
%% this is boring but does actually happen
%% in order to get proper user errors here we need to catch i/o
@@ -123,39 +122,39 @@ compile_file(C, LineNo, Chars = "</erl>" ++ _Tail, erl, NumChars, Ack) ->
A2 = {error, NumChars2, ?F("<pre> Dynamic compile error in file "
" ~s line ~w~n~s </pre>",
[C#comp.infile, LineNo, Str])},
- compile_file(C, LineNo+1, line(C), html, 0, [A2|Ack])
+ compile_file(C, LineNo+1, line(C), html, 0, [A2|Ack], Es+1)
end;
-compile_file(C, LineNo, Chars = "<pre>" ++ _Tail, html, NumChars, Ack) ->
+compile_file(C, LineNo, Chars = "<pre>" ++ _Tail, html, NumChars, Ack, Es) ->
?Debug("start pre:~p",[LineNo]),
- compile_file(C, LineNo+1, line(C) , pre, NumChars + length(Chars), Ack);
+ compile_file(C, LineNo+1, line(C) , pre, NumChars + length(Chars), Ack,Es);
-compile_file(C, LineNo, Chars = "</pre>" ++ _Tail, pre, NumChars, Ack) ->
+compile_file(C, LineNo, Chars = "</pre>" ++ _Tail, pre, NumChars, Ack,Es) ->
?Debug("stop pre:~p",[LineNo]),
- compile_file(C, LineNo+1, line(C) , html, NumChars + length(Chars), Ack);
+ compile_file(C, LineNo+1, line(C) , html, NumChars + length(Chars), Ack,Es);
-compile_file(C, LineNo, Chars, erl, NumChars, Ack) ->
+compile_file(C, LineNo, Chars, erl, NumChars, Ack,Es) ->
case has_tag(Chars, "</erl>") of
{ok, Skipped, Chars2} ->
- compile_file(C, LineNo, Chars2, erl, NumChars + Skipped, Ack);
+ compile_file(C, LineNo, Chars2, erl, NumChars + Skipped, Ack,Es);
false ->
io:format(C#comp.outfd, "~s", [Chars]),
compile_file(C, LineNo+1, line(C), erl, NumChars +
- length(Chars), Ack)
+ length(Chars), Ack,Es)
end;
-compile_file(C, LineNo, Chars, html, NumChars, Ack) ->
+compile_file(C, LineNo, Chars, html, NumChars, Ack,Es) ->
case has_tag(Chars, "<erl>") of
{ok, Skipped, Chars2} ->
- compile_file(C, LineNo, Chars2, html, NumChars+Skipped, Ack);
+ compile_file(C, LineNo, Chars2, html, NumChars+Skipped, Ack,Es);
false ->
compile_file(C, LineNo+1, line(C), html, NumChars +
- length(Chars), Ack)
+ length(Chars), Ack,Es)
end;
-compile_file(C, LineNo, Chars, pre, NumChars, Ack) ->
- compile_file(C, LineNo+1, line(C), pre, NumChars + length(Chars), Ack).
+compile_file(C, LineNo, Chars, pre, NumChars, Ack,Es) ->
+ compile_file(C, LineNo+1, line(C), pre, NumChars + length(Chars), Ack,Es).
View
@@ -98,8 +98,10 @@ a_status(Sock) ->
END = "\n",
[L1, T, L2, END]
end, L),
- gen_tcp:send(Sock, [H, T]).
-
+ gen_tcp:send(Sock, [H, T]),
+
+ %% Now lets' figure out the status of loaded modules
+ ok.
actl(Term, Uid) ->
View
@@ -200,6 +200,7 @@ init2(Gconf, Sconfs, RunMod) ->
({_Pid, _SCs}) ->
true
end, L),
+ io:format("L=~p~n", [L]),
if
length(L) == length(L2) ->
proc_lib:spawn_link(yaws_ctl, start, [self(), Gconf#gconf.uid]),
@@ -1007,20 +1008,22 @@ do_yaws(CliSock, GC, SC, Req, H, ARG, UT, N) ->
FileAtom = list_to_atom(UT#urltype.fullpath),
Mtime = mtime(UT#urltype.finfo),
case ets:lookup(SC#sconf.ets, FileAtom) of
- [{FileAtom, spec, Mtime1, Spec}] when Mtime1 == Mtime ->
+ [{FileAtom, spec, Mtime1, Spec, Es}] when Mtime1 == Mtime,
+ Es == 0 ->
deliver_dyn_file(CliSock, GC, SC, Req, H, Spec, ARG, UT, N);
Other ->
del_old_files(Other),
- {ok, Spec} = yaws_compile:compile_file(UT#urltype.fullpath, GC, SC),
+ {ok, [{errors, Errs}| Spec]} =
+ yaws_compile:compile_file(UT#urltype.fullpath, GC, SC),
?Debug("Spec for file ~s is:~n~p~n",[UT#urltype.fullpath, Spec]),
- ets:insert(SC#sconf.ets, {FileAtom, spec, Mtime, Spec}),
+ ets:insert(SC#sconf.ets, {FileAtom, spec, Mtime, Spec, Errs}),
deliver_dyn_file(CliSock, GC, SC, Req, H, Spec, ARG, UT, N)
end.
del_old_files([]) ->
ok;
-del_old_files([{_FileAtom, spec, _Mtime1, Spec}]) ->
+del_old_files([{_FileAtom, spec, _Mtime1, Spec, _}]) ->
lists:foreach(
fun({mod, _, _, _, Mod, _Func}) ->
F="/tmp/yaws/" ++ yaws:to_list(Mod) ++ ".erl",
@@ -1855,7 +1858,7 @@ cleanup_cache(E, num) ->
clear_ets(E) ->
- ets:match_delete(E, {'_', spec, '_', '_'}),
+ ets:match_delete(E, {'_', spec, '_', '_', '_'}),
ets:match_delete(E, {{url, '_'}, '_', '_'}),
ets:match_delete(E, {{urlc, '_'}, '_', '_'}),
ets:insert(E, {num_files, 0}),

0 comments on commit 8722844

Please sign in to comment.