@@ -50,13 +50,14 @@ type Cache struct {
5050// to share a cache directory (for example, if the directory were stored
5151// in a network file system). File locking is notoriously unreliable in
5252// network file systems and may not suffice to protect the cache.
53+ //
5354func Open (dir string ) (* Cache , error ) {
5455 info , err := os .Stat (dir )
5556 if err != nil {
5657 return nil , err
5758 }
5859 if ! info .IsDir () {
59- return nil , & os.PathError {Op : "open" , Path : dir , Err : errors . New ("not a directory" )}
60+ return nil , & os.PathError {Op : "open" , Path : dir , Err : fmt . Errorf ("not a directory" )}
6061 }
6162 for i := 0 ; i < 256 ; i ++ {
6263 name := filepath .Join (dir , fmt .Sprintf ("%02x" , i ))
@@ -165,7 +166,7 @@ func (c *Cache) get(id ActionID) (Entry, error) {
165166 eid , entry := entry [3 :3 + hexSize ], entry [3 + hexSize :]
166167 eout , entry := entry [1 :1 + hexSize ], entry [1 + hexSize :]
167168 esize , entry := entry [1 :1 + 20 ], entry [1 + 20 :]
168- etime := entry [1 : 1 + 20 ]
169+ etime , entry := entry [1 : 1 + 20 ], entry [ 1 + 20 : ]
169170 var buf [HashSize ]byte
170171 if _ , err = hex .Decode (buf [:], eid ); err != nil || buf != id {
171172 return failed (fmt .Errorf ("failed to hex decode eid data in %s: %w" , fileName , err ))
@@ -255,7 +256,7 @@ const (
255256// and to reduce the amount of disk activity caused by using
256257// cache entries, used only updates the mtime if the current
257258// mtime is more than an hour old. This heuristic eliminates
258- // nearly all the mtime updates that would otherwise happen,
259+ // nearly all of the mtime updates that would otherwise happen,
259260// while still keeping the mtimes useful for cache trimming.
260261func (c * Cache ) used (file string ) error {
261262 info , err := os .Stat (file )
@@ -301,15 +302,15 @@ func (c *Cache) Trim() {
301302
302303 // Ignore errors from here: if we don't write the complete timestamp, the
303304 // cache will appear older than it is, and we'll trim it again next time.
304- _ = renameio .WriteFile (filepath .Join (c .dir , "trim.txt" ), []byte (fmt .Sprintf ("%d" , now .Unix ())), 0666 )
305+ renameio .WriteFile (filepath .Join (c .dir , "trim.txt" ), []byte (fmt .Sprintf ("%d" , now .Unix ())), 0666 )
305306}
306307
307308// trimSubdir trims a single cache subdirectory.
308309func (c * Cache ) trimSubdir (subdir string , cutoff time.Time ) {
309310 // Read all directory entries from subdir before removing
310311 // any files, in case removing files invalidates the file offset
311312 // in the directory scan. Also, ignore error from f.Readdirnames,
312- // because we don't care about reporting the error, and we still
313+ // because we don't care about reporting the error and we still
313314 // want to process any entries found before the error.
314315 f , err := os .Open (subdir )
315316 if err != nil {
@@ -346,7 +347,6 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify
346347 // are entirely reproducible. As just noted, this may be unrealistic
347348 // in some cases but the check is also useful for shaking out real bugs.
348349 entry := fmt .Sprintf ("v1 %x %x %20d %20d\n " , id , out , size , time .Now ().UnixNano ())
349-
350350 if verify && allowVerify {
351351 old , err := c .get (id )
352352 if err == nil && (old .OutputID != out || old .Size != size ) {
@@ -368,7 +368,7 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify
368368 // Truncate the file only *after* writing it.
369369 // (This should be a no-op, but truncate just in case of previous corruption.)
370370 //
371- // This differs from os .WriteFile, which truncates to 0 *before* writing
371+ // This differs from ioutil .WriteFile, which truncates to 0 *before* writing
372372 // via os.O_TRUNC. Truncating only after writing ensures that a second write
373373 // of the same content to the same file is idempotent, and does not — even
374374 // temporarily! — undo the effect of the first write.
@@ -502,7 +502,7 @@ func (c *Cache) copyFile(file io.ReadSeeker, out OutputID, size int64) error {
502502 sum := h .Sum (nil )
503503 if ! bytes .Equal (sum , out [:]) {
504504 _ = f .Truncate (0 )
505- return errors . New ("file content changed underfoot" )
505+ return fmt . Errorf ("file content changed underfoot" )
506506 }
507507
508508 // Commit cache file entry.
0 commit comments