From c57e51af5b55cbc32511a8d039dea5182258006d Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Thu, 13 May 2021 06:58:08 +0200 Subject: [PATCH] fix(nodetool): add path from RELEASES file --- bin/nodetool | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/nodetool b/bin/nodetool index 5ab5ec69a..431121148 100755 --- a/bin/nodetool +++ b/bin/nodetool @@ -296,11 +296,30 @@ add_libs_dir() -> os:getenv("REL_VSN"), "emqx.rel" ]), - {ok, [{release, {_, _RelVsn}, {erts, _ErtsVsn}, Libs}]} = file:consult(RelFile), - lists:foreach( - fun({Name, Vsn}) -> add_lib_dir(RootDir, Name, Vsn); - ({Name, Vsn, _}) -> add_lib_dir(RootDir, Name, Vsn) - end, Libs). + case file:consult(RelFile) of + {ok, [{release, {_, _RelVsn}, {erts, _ErtsVsn}, Libs}]} -> + lists:foreach( + fun({Name, Vsn}) -> add_lib_dir(RootDir, Name, Vsn); + ({Name, Vsn, _}) -> add_lib_dir(RootDir, Name, Vsn) + end, Libs); + {error, enoent} -> + %% rel file is deleted by release handler + add_libs_dir2(RootDir) + end. + +add_libs_dir2(RootDir) -> + RelFile = filename:join([RootDir, "releases", "RELEASES"]), + case file:consult(RelFile) of + {ok, [[Release]]} -> + {release, _Name, _AppVsn, _ErtsVsn, Libs, _State} = Release, + lists:foreach( + fun({Name, Vsn, _}) -> + add_lib_dir(RootDir, Name, Vsn) + end, Libs); + {error, Reason} -> + %% rel file was been deleted by release handler + error({failed_to_read_RELEASES_file, RelFile, Reason}) + end. add_lib_dir(RootDir, Name, Vsn) -> LibDir = filename:join([RootDir, lib, atom_to_list(Name) ++ "-" ++ Vsn, ebin]),