Skip to content

Commit

Permalink
Merge pull request #40 from ferd/rework-cli
Browse files Browse the repository at this point in the history
Minor CLI patches and other things
  • Loading branch information
ferd authored Jul 4, 2024
2 parents 530d473 + b035b14 commit 27aff67
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion apps/revault/src/revault_file_disk.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ hash(Path) ->
{ok, Size} = size(Path),
case application:get_env(revault, multipart_size) of
{ok, Threshold} when Size > Threshold ->
{ok, Fd} = file:open(Path, [read, raw, binary]),
{ok, Fd} = file:open(Path, [read, raw, binary, {read_ahead, Threshold}]),
HashState = crypto:hash_init(sha256),
NewHashState = hash_fd(Fd, 0, Size, Threshold, HashState),
file:close(Fd),
Expand Down
42 changes: 30 additions & 12 deletions cli/revault_cli/src/revault_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ scan(_Args = #{node := NodeStr, dirs := Dirs}) ->
maybe
ok ?= connect(Node),
ok ?= revault_node(Node),
show(scan_dirs(Node, Dirs))
ok ?= scan_dirs(Node, Dirs)
else
{error, no_dist} ->
io:format("Erlang distribution seems to be off.~n");
Expand All @@ -119,7 +119,7 @@ sync(#{node := NodeStr, dirs := Dirs = [_|_], peer := [Peer]}) ->
maybe
ok ?= connect(Node),
ok ?= revault_node(Node),
show(sync_dirs(Node, Peer, Dirs))
ok ?= all_ok(sync_dirs(Node, Peer, Dirs), Dirs)
else
{error, no_dist} ->
io:format("Erlang distribution seems to be off.~n");
Expand Down Expand Up @@ -185,16 +185,29 @@ config(Node) ->
{config, Path, Config}.

scan_dirs(Node, Dirs) ->
[{scan, Name,
rpc:call(Node, revault_dirmon_event, force_scan, [Name, infinity])}
|| Name <- Dirs].
all_ok(scan_dirs_(Node, Dirs), Dirs).

scan_dirs_(_, []) ->
[];
scan_dirs_(Node, [Name|Dirs]) ->
io:format("Scanning ~ts: ", [Name]),
Res = rpc:call(Node, revault_dirmon_event, force_scan, [Name, infinity]),
io:format("~p~n", [Res]),
[Res | scan_dirs_(Node, Dirs)].

sync_dirs(Node, Remote, Dirs) ->
scan_dirs(Node, Dirs)
++
[{sync, Name, Remote,
rpc:call(Node, revault_fsm, sync, [Name, Remote])}
|| Name <- Dirs].
case scan_dirs(Node, Dirs) of
ok -> all_ok(sync_dirs_(Node, Remote, Dirs), Dirs);
Other -> Other
end.

sync_dirs_(_Node, _Remote, []) ->
[];
sync_dirs_(Node, Remote, [Name|Dirs]) ->
io:format("Syncing ~ts with ~ts: ", [Name, Remote]),
Res = rpc:call(Node, revault_fsm, sync, [Name, Remote]),
io:format("~p~n", [Res]),
[Res | sync_dirs_(Node, Remote, Dirs)].

seed_fork(Node, Path, Dirs) ->
[{fork, Name, Path,
Expand All @@ -205,13 +218,18 @@ show(List) when is_list(List) ->
[show(X) || X <- List];
show({config, Path, Config}) ->
io:format("Config parsed from ~ts:~n~p~n", [Path, Config]);
show({scan, Dir, Res}) ->
io:format("Scanning ~ts: ~p~n", [Dir, Res]);
show({sync, Dir, Peer, Res}) ->
io:format("Syncing ~ts with ~ts: ~p~n", [Dir, Peer, Res]);
show({fork, Name, Path, Res}) ->
io:format("Forking ~ts in ~p: ~p~n", [Name, Path, Res]).

all_ok(L, Keys) -> all_ok(L, Keys, []).

all_ok([], [], []) -> ok;
all_ok([], [], Bad) -> {error, Bad};
all_ok([ok|T], [_|Ks], Bad) -> all_ok(T, Ks, Bad);
all_ok([H|T], [K|Ks], Bad) -> all_ok(T, Ks, [{K,H}|Bad]).

%% Copied from revault_tls
make_selfsigned_cert(Dir, CertName) ->
check_openssl_vsn(),
Expand Down
30 changes: 15 additions & 15 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
{<<"aws">>,{pkg,<<"aws_erlang">>,<<"1.0.5">>},0},
{<<"aws_signature">>,{pkg,<<"aws_signature">>,<<"0.3.1">>},1},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
{<<"chatterbox">>,{pkg,<<"ts_chatterbox">>,<<"0.13.0">>},2},
{<<"chatterbox">>,{pkg,<<"ts_chatterbox">>,<<"0.15.1">>},2},
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
{<<"gproc">>,{pkg,<<"gproc">>,<<"0.9.0">>},0},
{<<"grpcbox">>,{pkg,<<"grpcbox">>,<<"0.16.0">>},1},
{<<"grpcbox">>,{pkg,<<"grpcbox">>,<<"0.17.1">>},1},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.18.0">>},1},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},3},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.3.0">>},3},
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},2},
{<<"itc">>,{pkg,<<"interval_tree_clocks">>,<<"1.0.0">>},0},
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.0.0">>},1},
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},2},
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2},
{<<"opentelemetry">>,
{git_subdir,"http://github.com/open-telemetry/opentelemetry-erlang",
{ref,"38591ea15dd903f3827cee792430ef5ce59d1da9"},
{ref,"8c9dc00196aebaaaa9db4c2992d4d872894044e5"},
"apps/opentelemetry"},
0},
{<<"opentelemetry_api">>,
{git_subdir,"http://github.com/open-telemetry/opentelemetry-erlang",
{ref,"38591ea15dd903f3827cee792430ef5ce59d1da9"},
{ref,"8c9dc00196aebaaaa9db4c2992d4d872894044e5"},
"apps/opentelemetry_api"},
0},
{<<"opentelemetry_exporter">>,
{git_subdir,"http://github.com/open-telemetry/opentelemetry-erlang",
{ref,"38591ea15dd903f3827cee792430ef5ce59d1da9"},
{ref,"8c9dc00196aebaaaa9db4c2992d4d872894044e5"},
"apps/opentelemetry_exporter"},
0},
{<<"opentelemetry_semantic_conventions">>,
Expand All @@ -41,7 +41,7 @@
{ref,"7bd3b824c9b5204c88cdd1c3e76999d3a8f0bfe1"}},
0},
{<<"tls_certificate_check">>,
{pkg,<<"tls_certificate_check">>,<<"1.17.4">>},
{pkg,<<"tls_certificate_check">>,<<"1.19.0">>},
1},
{<<"tomerl">>,{pkg,<<"tomerl">>,<<"0.5.0">>},0},
{<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.7.0">>},2},
Expand All @@ -52,12 +52,12 @@
{<<"aws">>, <<"F020F6F95BA32C4E3F49468B0F5275B8BEA4E591F442CB570011EAF74BC7C64F">>},
{<<"aws_signature">>, <<"67F369094CBD55FFA2BBD8CC713EDE14B195FCFB45C86665CD7C5AD010276148">>},
{<<"certifi">>, <<"D4FB0A6BB20B7C9C3643E22507E42F356AC090A1DCEA9AB99E27E0376D695EBA">>},
{<<"chatterbox">>, <<"6F059D97BCAA758B8EA6FFFE2B3B81362BD06B639D3EA2BB088335511D691EBF">>},
{<<"chatterbox">>, <<"5CAC4D15DD7AD61FC3C4415CE4826FC563D4643DEE897A558EC4EA0B1C835C9C">>},
{<<"ctx">>, <<"8FF88B70E6400C4DF90142E7F130625B82086077A45364A78D208ED3ED53C7FE">>},
{<<"gproc">>, <<"853CCB7805E9ADA25D227A157BA966F7B34508F386A3E7E21992B1B484230699">>},
{<<"grpcbox">>, <<"B83F37C62D6EECA347B77F9B1EC7E9F62231690CDFEB3A31BE07CD4002BA9C82">>},
{<<"grpcbox">>, <<"6E040AB3EF16FE699FFB513B0EF8E2E896DA7B18931A1EF817143037C454BCCE">>},
{<<"hackney">>, <<"C4443D960BB9FBA6D01161D01CD81173089686717D9490E5D3606644C48D121F">>},
{<<"hpack">>, <<"17670F83FF984AE6CD74B1C456EDDE906D27FF013740EE4D9EFAA4F1BF999633">>},
{<<"hpack">>, <<"2461899CC4AB6A0EF8E970C1661C5FC6A52D3C25580BC6DD204F84CE94669926">>},
{<<"idna">>, <<"8A63070E9F7D0C62EB9D9FCB360A7DE382448200FBBD1B106CC96D3D8099DF8D">>},
{<<"itc">>, <<"2CE9C218CE4DC34D0FECF282E70847F82C79435226E8AF3EAF0A1BA29ED7454E">>},
{<<"jsx">>, <<"20A170ABD4335FC6DB24D5FAD1E5D677C55DADF83D1B20A8A33B5FE159892A39">>},
Expand All @@ -68,7 +68,7 @@
{<<"quickrand">>, <<"06FCAD85CB47D5C85C51D6BC9C84A082501BA098A89D64AD0A2F69599E034C04">>},
{<<"recon">>, <<"739107B9050EA683C30E96DE050BC59248FD27EC147696F79A8797FF9FA17153">>},
{<<"ssl_verify_fun">>, <<"354C321CF377240C7B8716899E182CE4890C5938111A1296ADD3EC74CF1715DF">>},
{<<"tls_certificate_check">>, <<"75209AA363147D77D7782F446D76F7E15B04505B3EBAD4BE74B59B5A953955B2">>},
{<<"tls_certificate_check">>, <<"C76C4C5D79EE79A2B11C84F910C825D6F024A78427C854F515748E9BD025E987">>},
{<<"tomerl">>, <<"6E7CEAC151AC573B87B985F3D2112F29933B89BA0693FA741318D899A17AC318">>},
{<<"unicode_util_compat">>, <<"BC84380C9AB48177092F43AC89E4DFA2C6D62B40B8BD132B1059ECC7232F9A78">>},
{<<"uuid">>, <<"02C713FAC0E73E5F366CBA541216F1E956E2F00C91C7530D4B21DEC7D3ADA164">>}]},
Expand All @@ -77,12 +77,12 @@
{<<"aws">>, <<"A1382E961F141C3A02B5A13C7D49BDBFA1496B2BE9DA1F02F360BCCA1AA8AD8B">>},
{<<"aws_signature">>, <<"50FC4DC1D1F7C2D0A8C63F455B3C66ECD74C1CF4C915C768A636F9227704A674">>},
{<<"certifi">>, <<"6AC7EFC1C6F8600B08D625292D4BBF584E14847CE1B6B5C44D983D273E1097EA">>},
{<<"chatterbox">>, <<"B93D19104D86AF0B3F2566C4CBA2A57D2E06D103728246BA1AC6C3C0FF010AA7">>},
{<<"chatterbox">>, <<"4F75B91451338BC0DA5F52F3480FA6EF6E3A2AEECFC33686D6B3D0A0948F31AA">>},
{<<"ctx">>, <<"A14ED2D1B67723DBEBBE423B28D7615EB0BDCBA6FF28F2D1F1B0A7E1D4AA5FC2">>},
{<<"gproc">>, <<"587E8AF698CCD3504CF4BA8D90F893EDE2B0F58CABB8A916E2BF9321DE3CF10B">>},
{<<"grpcbox">>, <<"294DF743AE20A7E030889F00644001370A4F7CE0121F3BBDAF13CF3169C62913">>},
{<<"grpcbox">>, <<"4A3B5D7111DAABC569DC9CBD9B202A3237D81C80BF97212FBC676832CB0CEB17">>},
{<<"hackney">>, <<"9AFCDA620704D720DB8C6A3123E9848D09C87586DC1C10479C42627B905B5C5E">>},
{<<"hpack">>, <<"06F580167C4B8B8A6429040DF36CC93BBA6D571FAEAEC1B28816523379CBB23A">>},
{<<"hpack">>, <<"D6137D7079169D8C485C6962DFE261AF5B9EF60FBC557344511C1E65E3D95FB0">>},
{<<"idna">>, <<"92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA">>},
{<<"itc">>, <<"31582577C4D1254C526371B9AB4AF9073F2C96C1E13D59BBA71ABDA4C827D480">>},
{<<"jsx">>, <<"37BECA0435F5CA8A2F45F76A46211E76418FBEF80C36F0361C249FC75059DC6D">>},
Expand All @@ -93,7 +93,7 @@
{<<"quickrand">>, <<"252CF0493570EBF1A58985CB71990982CDDCD4396B6427F1E10CF58924C1C052">>},
{<<"recon">>, <<"6C6683F46FD4A1DFD98404B9F78DCABC7FCD8826613A89DCB984727A8C3099D7">>},
{<<"ssl_verify_fun">>, <<"FE4C190E8F37401D30167C8C405EDA19469F34577987C76DDE613E838BBC67F8">>},
{<<"tls_certificate_check">>, <<"FAF16168B340D965DA7B7DD20B73301D24BFF925FB4218BB1D6CC54AA41875AD">>},
{<<"tls_certificate_check">>, <<"4083B4A298ADD534C96125337CB01161C358BB32DD870D5A893AAE685FD91D70">>},
{<<"tomerl">>, <<"2A7FB62F9EBF0E75561B39255638BC2B805B437C86FEC538657E7C3B576979FA">>},
{<<"unicode_util_compat">>, <<"25EEE6D67DF61960CF6A794239566599B09E17E668D3700247BC498638152521">>},
{<<"uuid">>, <<"CE1C1ED1D786BA98F93204BE66F93A797504993954141122FCC5FE59B5331367">>}]}
Expand Down

0 comments on commit 27aff67

Please sign in to comment.