@@ -4,14 +4,14 @@ import (
4
4
"context"
5
5
"crypto/sha1"
6
6
"encoding/base32"
7
+ "errors"
7
8
"fmt"
8
9
"io/fs"
9
10
"os"
10
11
"path/filepath"
11
12
"time"
12
13
13
14
"github.com/adrg/xdg"
14
- "github.com/juju/errors"
15
15
"github.com/vmihailenco/msgpack/v5"
16
16
bolt "go.etcd.io/bbolt"
17
17
)
@@ -41,24 +41,23 @@ func Open(treeRoot string, clean bool) (err error) {
41
41
42
42
name := base32 .StdEncoding .EncodeToString (digest )
43
43
path , err := xdg .CacheFile (fmt .Sprintf ("treefmt/eval-cache/%v.db" , name ))
44
+ if err != nil {
45
+ return fmt .Errorf ("%w: could not resolve local path for the cache" , err )
46
+ }
44
47
45
48
// force a clean of the cache if specified
46
49
if clean {
47
50
err := os .Remove (path )
48
51
if errors .Is (err , os .ErrNotExist ) {
49
52
err = nil
50
53
} else if err != nil {
51
- return errors . Annotate ( err , " failed to clear cache" )
54
+ return fmt . Errorf ( "%w: failed to clear cache", err )
52
55
}
53
56
}
54
57
55
- if err != nil {
56
- return errors .Annotate (err , "could not resolve local path for the cache" )
57
- }
58
-
59
58
db , err = bolt .Open (path , 0o600 , nil )
60
59
if err != nil {
61
- return errors . Annotate ( err , " failed to open cache" )
60
+ return fmt . Errorf ( "%w: failed to open cache", err )
62
61
}
63
62
64
63
err = db .Update (func (tx * bolt.Tx ) error {
@@ -86,7 +85,7 @@ func getEntry(bucket *bolt.Bucket, path string) (*Entry, error) {
86
85
if b != nil {
87
86
var cached Entry
88
87
if err := msgpack .Unmarshal (b , & cached ); err != nil {
89
- return nil , errors . Annotatef ( err , " failed to unmarshal cache info for path '%v'" , path )
88
+ return nil , fmt . Errorf ( "%w: failed to unmarshal cache info for path '%v'", err , path )
90
89
}
91
90
return & cached , nil
92
91
} else {
@@ -102,7 +101,7 @@ func ChangeSet(ctx context.Context, root string, pathsCh chan<- string) error {
102
101
103
102
return filepath .Walk (root , func (path string , info fs.FileInfo , err error ) error {
104
103
if err != nil {
105
- return errors . Annotate ( err , " failed to walk path" )
104
+ return fmt . Errorf ( "%w: failed to walk path", err )
106
105
} else if ctx .Err () != nil {
107
106
return ctx .Err ()
108
107
} else if info .IsDir () {
@@ -174,11 +173,11 @@ func Update(paths []string) (int, error) {
174
173
175
174
bytes , err := msgpack .Marshal (cacheInfo )
176
175
if err != nil {
177
- return errors . Annotate ( err , " failed to marshal mod time" )
176
+ return fmt . Errorf ( "%w: failed to marshal mod time", err )
178
177
}
179
178
180
179
if err = bucket .Put ([]byte (path ), bytes ); err != nil {
181
- return errors . Annotate ( err , " failed to put mode time" )
180
+ return fmt . Errorf ( "%w: failed to put mode time", err )
182
181
}
183
182
}
184
183
0 commit comments