Don't create cache directory in daemon

This commit is contained in:
Brian Picciano 2024-12-13 10:56:43 +01:00
parent c08b225ee2
commit 5e8049c8d0
2 changed files with 14 additions and 10 deletions

View File

@ -52,10 +52,6 @@ func (o *subCmdCtxOpts) withDefaults() *subCmdCtxOpts {
o.stdout = os.Stdout o.stdout = os.Stdout
} }
if o.changeStager == nil {
o.changeStager = &changeStager{envCacheDir()}
}
return o return o
} }
@ -89,6 +85,14 @@ func newSubCmdCtx(
} }
} }
func (ctx subCmdCtx) getChangeStager() *changeStager {
if ctx.opts.changeStager != nil {
return ctx.opts.changeStager
}
return &changeStager{envCacheDir()}
}
func usagePrefix(subCmdNames []string) string { func usagePrefix(subCmdNames []string) string {
subCmdNamesStr := strings.Join(subCmdNames, " ") subCmdNamesStr := strings.Join(subCmdNames, " ")
if subCmdNamesStr != "" { if subCmdNamesStr != "" {

View File

@ -21,7 +21,7 @@ func vpnFirewallGetConfig(ctx subCmdCtx) (daecommon.NetworkConfig, error) {
} }
var firewallConfig daecommon.ConfigFirewall var firewallConfig daecommon.ConfigFirewall
if ok, err := ctx.opts.changeStager.get( if ok, err := ctx.getChangeStager().get(
&firewallConfig, vpnFirewallConfigChangeStagerName, &firewallConfig, vpnFirewallConfigChangeStagerName,
); err != nil { ); err != nil {
return daecommon.NetworkConfig{}, fmt.Errorf( return daecommon.NetworkConfig{}, fmt.Errorf(
@ -122,7 +122,7 @@ var subCmdVPNFirewallAdd = subCmd{
return err return err
} }
if err := ctx.opts.changeStager.set( if err := ctx.getChangeStager().set(
config.VPN.Firewall, vpnFirewallConfigChangeStagerName, config.VPN.Firewall, vpnFirewallConfigChangeStagerName,
); err != nil { ); err != nil {
return fmt.Errorf("staging changes: %w", err) return fmt.Errorf("staging changes: %w", err)
@ -142,7 +142,7 @@ var subCmdVPNFirewallCommit = subCmd{
} }
var firewallConfig daecommon.ConfigFirewall var firewallConfig daecommon.ConfigFirewall
ok, err := ctx.opts.changeStager.get( ok, err := ctx.getChangeStager().get(
&firewallConfig, vpnFirewallConfigChangeStagerName, &firewallConfig, vpnFirewallConfigChangeStagerName,
) )
if err != nil { if err != nil {
@ -232,7 +232,7 @@ var subCmdVPNFirewallRemove = subCmd{
return err return err
} }
if err := ctx.opts.changeStager.set( if err := ctx.getChangeStager().set(
config.VPN.Firewall, vpnFirewallConfigChangeStagerName, config.VPN.Firewall, vpnFirewallConfigChangeStagerName,
); err != nil { ); err != nil {
return fmt.Errorf("staging changes: %w", err) return fmt.Errorf("staging changes: %w", err)
@ -246,7 +246,7 @@ var subCmdVPNFirewallReset = subCmd{
name: "reset", name: "reset",
descr: "Discard all changes which have been staged", descr: "Discard all changes which have been staged",
do: func(ctx subCmdCtx) error { do: func(ctx subCmdCtx) error {
return ctx.opts.changeStager.del(vpnFirewallConfigChangeStagerName) return ctx.getChangeStager().del(vpnFirewallConfigChangeStagerName)
}, },
} }
@ -301,7 +301,7 @@ var subCmdVPNFirewallShow = subCmd{
) )
if *staged { if *staged {
var err error var err error
if foundStaged, err = ctx.opts.changeStager.get( if foundStaged, err = ctx.getChangeStager().get(
&firewallConfig, vpnFirewallConfigChangeStagerName, &firewallConfig, vpnFirewallConfigChangeStagerName,
); err != nil { ); err != nil {
return nil, fmt.Errorf("checking for staged changes: %w", err) return nil, fmt.Errorf("checking for staged changes: %w", err)