diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-04-06 12:10:08 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-04-18 15:53:00 -0500 |
commit | db2f19b8b40c12420070612acc3ed7faed45b819 (patch) | |
tree | 357db1ecf20ae18225b674ee650757479368a617 | |
parent | 3f0f806e903ac334a768210a9ac4a3c7947956c7 (diff) | |
download | couchdb-db2f19b8b40c12420070612acc3ed7faed45b819.tar.gz |
Fix mango full text detection
The check for whether full text support in mango is available was broken
in that the mango_cursor_text module is only compiled if dreyfus exists
while the check to use the module was a runtime check. Thus is a user
were to add dreyfus after mango had been compiled it would have led to a
runtime error when we attempted to use a module that didn't exist.
This changes the check to a compile time check in both places. And now
that its a compile time define we can remove the need to rename source
files around which causes problems with source control seeing that file
change depending on local configuration.
COUCHDB-3378
-rw-r--r-- | src/mango/rebar.config.script | 23 | ||||
-rw-r--r-- | src/mango/src/mango_cursor.erl | 21 | ||||
-rw-r--r-- | src/mango/src/mango_cursor_text.erl (renamed from src/mango/src/mango_cursor_text.erl.nocompile) | 4 |
3 files changed, 28 insertions, 20 deletions
diff --git a/src/mango/rebar.config.script b/src/mango/rebar.config.script index 3b046f4b9..d62cc69db 100644 --- a/src/mango/rebar.config.script +++ b/src/mango/rebar.config.script @@ -10,18 +10,15 @@ % License for the specific language governing permissions and limitations under % the License. -DreyfusAppFile = filename:join(filename:dirname(SCRIPT), - "../dreyfus/src/dreyfus.app.src"), -RenameFile = filename:join(filename:dirname(SCRIPT), - "src/mango_cursor_text.erl"), -CursorFile = filename:join(filename:dirname(SCRIPT), - "src/mango_cursor_text.erl.nocompile"), -case filelib:is_regular(DreyfusAppFile) of - true -> - file:rename(CursorFile, RenameFile); - false -> - ok -end, +HaveDreyfus = code:lib_dir(dreyfus) /= {error, bad_name}. + +if not HaveDreyfus -> CONFIG; true -> + CurrOpts = case lists:keyfind(erl_opts, 1, CONFIG) of + {erl_opts, Opts} -> Opts; + false -> [] + end, + NewOpts = [{d, 'HAVE_DREYFUS'} | CurrOpts], + lists:keystore(erl_opts, 1, CONFIG, {erl_opts, NewOpts}) +end. -CONFIG. diff --git a/src/mango/src/mango_cursor.erl b/src/mango/src/mango_cursor.erl index 911ecdb3e..cf7179079 100644 --- a/src/mango/src/mango_cursor.erl +++ b/src/mango/src/mango_cursor.erl @@ -26,6 +26,19 @@ -include("mango_cursor.hrl"). +-ifdef(HAVE_DREYFUS). +-define(CURSOR_MODULES, [ + mango_cursor_view, + mango_cursor_text, + mango_cursor_special +]). +-else. +-define(CURSOR_MODULES, [ + mango_cursor_view, + mango_cursor_special +]). +-endif. + -define(SUPERVISOR, mango_cursor_sup). @@ -113,12 +126,6 @@ group_indexes_by_type(Indexes) -> % used to service this query. This is so that we % don't suddenly switch indexes for existing client % queries. - CursorModules = case module_loaded(dreyfus_index) of - true -> - [mango_cursor_view, mango_cursor_text, mango_cursor_special]; - false -> - [mango_cursor_view, mango_cursor_special] - end, lists:flatmap(fun(CMod) -> case dict:find(CMod, IdxDict) of {ok, CModIndexes} -> @@ -126,4 +133,4 @@ group_indexes_by_type(Indexes) -> error -> [] end - end, CursorModules). + end, ?CURSOR_MODULES). diff --git a/src/mango/src/mango_cursor_text.erl.nocompile b/src/mango/src/mango_cursor_text.erl index a094b5528..96e365a49 100644 --- a/src/mango/src/mango_cursor_text.erl.nocompile +++ b/src/mango/src/mango_cursor_text.erl @@ -12,6 +12,8 @@ -module(mango_cursor_text). +-ifdef(HAVE_DREYFUS). + -export([ create/4, explain/1, @@ -304,3 +306,5 @@ get_json_docs(DbName, Hits) -> {Sort, not_found} end end, Hits). + +-endif. |