Fix cache_dir() problem, made it configurable

This commit is contained in:
Ulf Wiger 2025-10-15 12:41:00 +02:00
parent 1e60f35dd3
commit 847ffc810a
18 changed files with 48 additions and 18 deletions

View File

@ -103,6 +103,10 @@ option `-setup data_dir Dir`.
"$schema": "http://json-schema.org/draft-04/schema#",
"additionalProperties": false,
"properties": {
"cache_dir": {
"description": "Location of cache, default is 'setup:data_dir()'",
"type": "string"
},
"extra_pubkeys": {
"default": [],
"description": "Additional worker pubkeys, sharing rewards",

View File

@ -1,6 +1,6 @@
{application,gmhive_client,
[{description,"Gajumaru Hive Client"},
{vsn,"0.8.2"},
{vsn,"0.8.3"},
{registered,[]},
{applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
gmconfig,gmhive_protocol,gmhive_worker]},

View File

@ -2,6 +2,10 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"additionalProperties": false,
"properties": {
"cache_dir": {
"description": "Location of cache, default is 'setup:data_dir()'",
"type": "string"
},
"extra_pubkeys": {
"default": [],
"description": "Additional worker pubkeys, sharing rewards",

View File

@ -1,6 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_app).
-vsn("0.6.1").
-vsn("0.8.3").
-behaviour(application).

View File

@ -1,5 +1,5 @@
-module(gmhc_config).
-vsn("0.6.1").
-vsn("0.8.3").
-export([ load_config/0
, get_config/1

View File

@ -1,5 +1,5 @@
-module(gmhc_config_schema).
-vsn("0.6.1").
-vsn("0.8.3").
-export([ schema/0
, to_json/0
@ -51,6 +51,7 @@ schema() ->
, pool => pool()
, pool_admin => pool_admin()
, workers => workers()
, cache_dir => str(#{description => <<"Location of cache, default is 'setup:data_dir()'">>})
, report => str(#{ enum => [<<"debug">>, <<"progress">>, <<"silent">>]
, default => <<"silent">>
, description => <<"Progress reporting">> })

View File

@ -1,5 +1,5 @@
-module(gmhc_connector).
-vsn("0.6.1").
-vsn("0.8.3").
-behaviour(gen_server).

View File

@ -1,5 +1,5 @@
-module(gmhc_connectors_sup).
-vsn("0.6.1").
-vsn("0.8.3").
-behavior(supervisor).
-export([ start_link/0

View File

@ -1,5 +1,5 @@
-module(gmhc_counters).
-vsn("0.6.1").
-vsn("0.8.3").
-export([ initialize/0 ]).

View File

@ -1,9 +1,12 @@
-module(gmhc_eureka).
-vsn("0.6.1").
-vsn("0.8.3").
-export([get_pool_address/0]).
-export([cache_good_address/1,
invalidate_cache/0]).
invalidate_cache/0,
cached_address/0,
cache_filename/0,
cache_dir/0]).
-include_lib("kernel/include/logger.hrl").
-include("gmhc_events.hrl").
@ -99,10 +102,27 @@ cache_filename() ->
cache_filename(cache_info()).
cache_filename(#{network := Network, pubkey := Pubkey}) ->
Path = filename:join(setup:data_dir(), Network),
Path = filename:join(cache_dir(), Network),
<<"ak_", PKShort:8/binary, _/binary>> = Pubkey,
filename:join(Path, "gmhc_eureka." ++ binary_to_list(PKShort) ++ ".cache").
cache_dir() ->
case gmconfig:find_config([<<"cache_dir">>]) of
{ok, D} ->
D;
undefined ->
case setup_zomp:is_zomp_context() of
true ->
cache_dir_zomp();
false ->
filename:join(setup:data_dir(), "gmhive.cache")
end
end.
cache_dir_zomp() ->
#{package_id := {Realm, App, _}} = zx_daemon:meta(),
filename:join(zx_lib:ppath(var, {Realm, App}), "gmhive.cache").
get_pool_address_() ->
case gmconfig:find_config([<<"pool_admin">>, <<"url">>], [user_config]) of
{ok, URL0} ->

View File

@ -1,5 +1,5 @@
-module(gmhc_events).
-vsn("0.6.1").
-vsn("0.8.3").
-export([subscribe/1,
ensure_subscribed/1,

View File

@ -1,5 +1,5 @@
-module(gmhc_handler).
-vsn("0.6.1").
-vsn("0.8.3").
-behavior(gen_server).
-export([ start_link/0

View File

@ -1,4 +1,5 @@
-module(gmhc_lib).
-vsn("0.8.3").
-export([ rand/1 ]).

View File

@ -1,5 +1,5 @@
-module(gmhc_server).
-vsn("0.6.1").
-vsn("0.8.3").
-behaviour(gen_server).

View File

@ -1,6 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_sup).
-vsn("0.6.1").
-vsn("0.8.3").
-behaviour(supervisor).

View File

@ -8,7 +8,7 @@
%%%-------------------------------------------------------------------
-module(gmhc_workers).
-vsn("0.6.1").
-vsn("0.8.3").
-export([
get_worker_configs/0

View File

@ -1,5 +1,5 @@
-module(gmhive_client).
-vsn("0.6.1").
-vsn("0.8.3").
-export([ connect/1
, disconnect/1

View File

@ -2,9 +2,9 @@
{type,app}.
{modules,[]}.
{prefix,"gmhc"}.
{author,"Ulf Wiger, QPQ AG"}.
{desc,"Gajumaru Hive Client"}.
{package_id,{"uwiger","gmhive_client",{0,8,2}}}.
{author,"Ulf Wiger, QPQ AG"}.
{package_id,{"uwiger","gmhive_client",{0,8,3}}}.
{deps,[{"uwiger","gmhive_protocol",{0,2,0}},
{"uwiger","gmhive_worker",{0,5,1}},
{"uwiger","gmcuckoo",{1,2,4}},