From 00cb3a2488db11c8ce96d182915b8c448edce976 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 4 Sep 2024 09:11:35 +0200 Subject: chore(gonf): add a DECLARED promise status and make it the default instead of PROMISED --- stdlib/backups/borg/client.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'stdlib/backups/borg/client.go') diff --git a/stdlib/backups/borg/client.go b/stdlib/backups/borg/client.go index a203ae2..95d8d0d 100644 --- a/stdlib/backups/borg/client.go +++ b/stdlib/backups/borg/client.go @@ -33,13 +33,18 @@ type BorgClient struct { status gonf.Status } +var borgClient *BorgClient = nil + func (b *BorgClient) IfRepaired(p ...gonf.Promise) gonf.Promise { b.chain = append(b.chain, p...) return b } func (b *BorgClient) Promise() *BorgClient { - gonf.MakeCustomPromise(b).Promise() + if b.status == gonf.DECLARED { + b.status = gonf.PROMISED + gonf.MakeCustomPromise(b).Promise() + } return b } @@ -101,12 +106,15 @@ func (b BorgClient) Status() gonf.Status { } func Client() *BorgClient { - return &BorgClient{ - chain: nil, - jobs: make(map[string]*Job), - path: "/etc/borg/", - status: gonf.PROMISED, + if borgClient == nil { + borgClient = &BorgClient{ + chain: nil, + jobs: make(map[string]*Job), + path: "/etc/borg/", + status: gonf.DECLARED, + } } + return borgClient } func (b *BorgClient) Add(name string, path string, privateKey []byte, hostname string) *BorgClient { -- cgit v1.2.3