Skip to content

Commit

Permalink
Revert "Allow user specified cache directory (aquasecurity#12)" (aqua…
Browse files Browse the repository at this point in the history
…security#111)

This reverts commit 2d512c5.
  • Loading branch information
knqyf263 authored Aug 13, 2019
1 parent f032725 commit 127cbf7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 25 deletions.
4 changes: 0 additions & 4 deletions cmd/trivy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ OPTIONS:
Name: "debug, d",
Usage: "debug mode",
},
cli.StringFlag{
Name: "cache-dir",
Usage: "cache directory",
},
cli.StringFlag{
Name: "vuln-type",
Value: "os,library",
Expand Down
5 changes: 2 additions & 3 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
)

var (
db *bolt.DB
db *bolt.DB
dbDir = filepath.Join(utils.CacheDir(), "db")
)

func Init() (err error) {
dbDir := filepath.Join(utils.CacheDir(), "db")
if err = os.MkdirAll(dbDir, 0700); err != nil {
return xerrors.Errorf("failed to mkdir: %w", err)
}
Expand All @@ -45,7 +45,6 @@ func Reset() error {
return xerrors.Errorf("failed to reset DB: %w", err)
}

dbDir := filepath.Join(utils.CacheDir(), "db")
if err := os.RemoveAll(dbDir); err != nil {
return xerrors.Errorf("failed to reset DB: %w", err)
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ func Run(c *cli.Context) (err error) {
if err = log.InitLogger(debug); err != nil {
l.Fatal(err)
}

cacheDir := c.String("cache-dir")
if cacheDir != "" {
utils.SetCacheDir(cacheDir)
}

log.Logger.Debugf("cache dir: %s", utils.CacheDir())

reset := c.Bool("reset")
Expand Down
15 changes: 3 additions & 12 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,15 @@ import (
"golang.org/x/xerrors"
)

var cacheDir string

func CacheDir() string {
if cacheDir == "" {
var err error
cacheDir, err = os.UserCacheDir()
if err != nil {
cacheDir = os.TempDir()
}
cacheDir, err := os.UserCacheDir()
if err != nil {
cacheDir = os.TempDir()
}
dir := filepath.Join(cacheDir, "trivy")
return dir
}

func SetCacheDir(cd string) {
cacheDir = cd
}

func FileWalk(root string, targetFiles map[string]struct{}, walkFn func(r io.Reader, path string) error) error {
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
Expand Down

0 comments on commit 127cbf7

Please sign in to comment.