diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 777b2997f..853174c14 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -652,7 +652,11 @@ func (d *Daemon) WithWorkingClone(ctx context.Context, fn func(*git.Checkout) er if err != nil { return err } - defer co.Clean() + defer func() { + if err := co.Clean(); err != nil { + d.Logger.Log("error", fmt.Sprintf("cannot clean working clone: %s", err)) + } + }() if d.GitSecretEnabled { if err := co.SecretUnseal(ctx); err != nil { return err @@ -673,7 +677,11 @@ func (d *Daemon) WithReadonlyClone(ctx context.Context, fn func(*git.Export) err if err != nil { return err } - defer co.Clean() + defer func() { + if err := co.Clean(); err != nil { + d.Logger.Log("error", fmt.Sprintf("cannot read-only clone: %s", err)) + } + }() if d.GitSecretEnabled { if err := co.SecretUnseal(ctx); err != nil { return err diff --git a/pkg/daemon/sync.go b/pkg/daemon/sync.go index 6d764236b..a5f81873a 100644 --- a/pkg/daemon/sync.go +++ b/pkg/daemon/sync.go @@ -4,6 +4,7 @@ import ( "context" "crypto/sha256" "encoding/base64" + "fmt" "github.com/fluxcd/flux/pkg/metrics" "github.com/go-kit/kit/log" "github.com/pkg/errors" @@ -48,7 +49,11 @@ func (d *Daemon) Sync(ctx context.Context, started time.Time, newRevision string return err } cancel() - defer working.Clean() + defer func() { + if err := working.Clean(); err != nil { + d.Logger.Log("error", fmt.Sprintf("cannot clean sync clone: %s", err)) + } + }() // Unseal any secrets if enabled if d.GitSecretEnabled { diff --git a/pkg/git/export.go b/pkg/git/export.go index 34d23cda1..b8ee1500c 100644 --- a/pkg/git/export.go +++ b/pkg/git/export.go @@ -14,10 +14,11 @@ func (e *Export) Dir() string { return e.dir } -func (e *Export) Clean() { +func (e *Export) Clean() error { if e.dir != "" { - os.RemoveAll(e.dir) + return os.RemoveAll(e.dir) } + return nil } // Export creates a minimal clone of the repo, at the ref given. diff --git a/pkg/git/repo.go b/pkg/git/repo.go index 8e0ef470c..5098c2361 100644 --- a/pkg/git/repo.go +++ b/pkg/git/repo.go @@ -486,5 +486,9 @@ func (r *Repo) workingClone(ctx context.Context, ref string) (string, error) { if err != nil { return "", err } - return clone(ctx, working, r.dir, ref) + path, err := clone(ctx, working, r.dir, ref) + if err != nil { + os.RemoveAll(working) + } + return path, err } diff --git a/pkg/sync/git.go b/pkg/sync/git.go index d50babe9e..217e55f95 100644 --- a/pkg/sync/git.go +++ b/pkg/sync/git.go @@ -66,6 +66,7 @@ func (p GitTagSyncProvider) UpdateMarker(ctx context.Context, revision string) e if err != nil { return err } + defer checkout.Clean() return checkout.MoveTagAndPush(ctx, git.TagAction{ Tag: p.syncTag, Revision: revision,