瀏覽代碼

feat: use name-vsn instead of lib for plugin apps

Using a shared lib dir for different plugins may complicate
installation management.
e.g. when un-installing a plugin, we can't be sure if the beams
are actually used by other plugins.
Zaiming (Stone) Shi 4 年之前
父節點
當前提交
68012f1675
共有 1 個文件被更改,包括 8 次插入10 次删除
  1. 8 10
      src/emqx_plugrel.erl

+ 8 - 10
src/emqx_plugrel.erl

@@ -81,14 +81,14 @@ make_tar(#{name := Name, rel_vsn := Vsn, rel_apps := Apps} = Info, State) ->
     BaseDir = rebar_dir:base_dir(State),
     BaseDir = rebar_dir:base_dir(State),
     Dir = filename:join([BaseDir, ?MODULE]),
     Dir = filename:join([BaseDir, ?MODULE]),
     NameWithVsn = binary_to_list(bin([Name, "-", Vsn])),
     NameWithVsn = binary_to_list(bin([Name, "-", Vsn])),
-    %% write info file
-    InfoFile = filename:join([Dir, NameWithVsn ++ ".json"]),
+    LibDir = filename:join([Dir, NameWithVsn]),
+    InfoFile = filename:join([LibDir, "release" ++ ".json"]),
+    %% ensure clean state
+    ok = rebar_file_utils:rm_rf(LibDir),
     ok = filelib:ensure_dir(InfoFile),
     ok = filelib:ensure_dir(InfoFile),
+    %% write info file
     ok = file:write_file(InfoFile, jsx:encode(Info, [space, {indent, 4}])),
     ok = file:write_file(InfoFile, jsx:encode(Info, [space, {indent, 4}])),
     %% copy apps to lib dir
     %% copy apps to lib dir
-    LibDir = filename:join([Dir, lib]),
-    ok = rebar_file_utils:rm_rf(LibDir),
-    ok = filelib:ensure_dir(filename:join([LibDir, "foo"])),
     Sources = lists:map(fun(App) -> filename:join([BaseDir, "rel", Name, "lib", App]) end, Apps),
     Sources = lists:map(fun(App) -> filename:join([BaseDir, "rel", Name, "lib", App]) end, Apps),
     ok = rebar_file_utils:cp_r(Sources, LibDir),
     ok = rebar_file_utils:cp_r(Sources, LibDir),
     {ok, OriginalCwd} = file:get_cwd(),
     {ok, OriginalCwd} = file:get_cwd(),
@@ -97,16 +97,14 @@ make_tar(#{name := Name, rel_vsn := Vsn, rel_apps := Apps} = Info, State) ->
         do_make_tar(Dir, NameWithVsn)
         do_make_tar(Dir, NameWithVsn)
     after
     after
         file:set_cwd(OriginalCwd)
         file:set_cwd(OriginalCwd)
-    end,
-    ok = file:delete(InfoFile),
-    ok = rebar_file_utils:rm_rf(LibDir).
+    end.
 
 
 do_make_tar(Cwd, NameWithVsn) ->
 do_make_tar(Cwd, NameWithVsn) ->
-    Files = filelib:wildcard("lib/**"),
+    Files = filelib:wildcard(NameWithVsn ++ "/**"),
     TarFile = NameWithVsn ++ ".tar.gz",
     TarFile = NameWithVsn ++ ".tar.gz",
     FullName = filename:join([Cwd, TarFile]),
     FullName = filename:join([Cwd, TarFile]),
     ?LOG(info, "creating ~ts", [FullName]),
     ?LOG(info, "creating ~ts", [FullName]),
-    ok = erl_tar:create(TarFile, [NameWithVsn ++ ".json"| Files], [compressed]),
+    ok = erl_tar:create(TarFile, Files, [compressed]),
     {ok, Bin} = file:read_file(TarFile),
     {ok, Bin} = file:read_file(TarFile),
     Sha = bin2hexstr(crypto:hash(sha256, Bin)),
     Sha = bin2hexstr(crypto:hash(sha256, Bin)),
     ok = file:write_file(NameWithVsn ++ ".sha256", Sha).
     ok = file:write_file(NameWithVsn ++ ".sha256", Sha).