Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
This commit and others in this branch fix
the lint errors popping up in
#1400
to unblock this PR, to allow rebase other branches
to master without getting stuck on linter errors.

Changes
* Remove io.util usage from contentcache
  • Loading branch information
gargnitingoogle committed Sep 28, 2023
1 parent 4b8ed76 commit 8f68ec8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/contentcache/contentcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path"
"regexp"
Expand Down Expand Up @@ -83,7 +82,7 @@ func (c *ContentCache) WriteMetadataCheckpointFile(cacheFileName string, cacheFi
return
}
metadataFileName = fmt.Sprintf("%s.json", cacheFileName)
err = ioutil.WriteFile(metadataFileName, file, 0644)
err = os.WriteFile(metadataFileName, file, 0644)
if err != nil {
err = fmt.Errorf("WriteFile for JSON metadata: %w", err)
return
Expand Down Expand Up @@ -111,7 +110,7 @@ func (c *ContentCache) recoverFileFromCache(metadataFile fs.FileInfo) {
}
var metadata CacheFileObjectMetadata
metadataAbsolutePath := path.Join(c.tempDir, metadataFile.Name())
contents, err := ioutil.ReadFile(metadataAbsolutePath)
contents, err := os.ReadFile(metadataAbsolutePath)
if err != nil {
logger.Errorf("content cache: Skip metadata file %v due to read error: %s", metadataFile.Name(), err)
return
Expand Down Expand Up @@ -152,11 +151,19 @@ func (c *ContentCache) RecoverCache() error {
c.tempDir = "/tmp"
}
logger.Infof("Recovering cache:\n")
files, err := ioutil.ReadDir(c.tempDir)
dirEntries, err := os.ReadDir(c.tempDir)
if err != nil {
// if we fail to read the specified directory, log and return error
return fmt.Errorf("recover cache: %w", err)
}
files := make([]os.FileInfo, len(dirEntries))
for i, dirEntry := range dirEntries {
files[i], err = dirEntry.Info()
if err != nil {
// if we fail to read the specified directory, log and return error
return fmt.Errorf("recover cache: %w", err)
}
}
for _, metadataFile := range files {
c.recoverFileFromCache(metadataFile)
}
Expand Down Expand Up @@ -196,7 +203,7 @@ func (c *ContentCache) AddOrReplace(cacheObjectKey *CacheObjectKey, generation i
cacheObject.Destroy()
}
// Create a temporary cache file on disk
f, err := ioutil.TempFile(c.tempDir, CacheFilePrefix)
f, err := os.CreateTemp(c.tempDir, CacheFilePrefix)
if err != nil {
return nil, fmt.Errorf("TempFile: %w", err)
}
Expand Down

0 comments on commit 8f68ec8

Please sign in to comment.