okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(daemon): remove unused bus and harness APIs03610e4

main
1.4 KiB38 linesraw
1-module(albedo_skills_test_support).
2-export([fixture/0, write/3, replace_with_symlink/3, exists/2, chmod/3, cleanup/1]).
3
4fixture() ->
5    Root = filename:join(os:getenv("TMPDIR", "/tmp"), "albedo-skills-" ++ integer_to_list(erlang:system_time(nanosecond)) ++ "-" ++ integer_to_list(erlang:unique_integer([positive]))),
6    Workspace = filename:join(Root, "workspace"),
7    Home = filename:join(Root, "home"),
8    ok = filelib:ensure_dir(filename:join(Workspace, "placeholder")),
9    ok = filelib:ensure_dir(filename:join(Home, "placeholder")),
10    {bin(Root), bin(Workspace), bin(Home)}.
11
12write(Base0, Relative0, Content) ->
13    Path = filename:join(text(Base0), text(Relative0)),
14    ok = filelib:ensure_dir(Path),
15    ok = file:write_file(Path, Content),
16    bin(Path).
17
18replace_with_symlink(Base0, TargetRelative0, LinkRelative0) ->
19    Base = text(Base0),
20    Target = filename:join(Base, text(TargetRelative0)),
21    Link = filename:join(Base, text(LinkRelative0)),
22    ok = file:delete(Link),
23    ok = file:make_symlink(Target, Link),
24    nil.
25
26exists(Base0, Relative0) ->
27    filelib:is_file(filename:join(text(Base0), text(Relative0))).
28
29chmod(Base, Relative, Mode) ->
30    ok = file:change_mode(filename:join(text(Base), text(Relative)), Mode),
31    nil.
32
33cleanup(Root) ->
34    _ = file:del_dir_r(Root),
35    nil.
36
37text(Value) -> unicode:characters_to_list(Value).
38bin(Value) -> unicode:characters_to_binary(Value).