feat!: add clean subcommand (#6993)

Signed-off-by: knqyf263 <knqyf263@gmail.com>
Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com>
Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
This commit is contained in:
Teppei Fukuda
2024-06-25 13:06:27 +04:00
committed by GitHub
parent de201dc772
commit 8d0ae1f5de
35 changed files with 496 additions and 210 deletions

View File

@@ -79,7 +79,7 @@ func (u *Updater) Update() error {
return xerrors.Errorf("Java DB metadata update error: %w", err)
}
log.Info("The Java DB is cached for 3 days. If you want to update the database more frequently, " +
"the '--reset' flag clears the DB cache.")
`"trivy clean --java-db" command clears the DB cache.`)
}
return nil
@@ -88,7 +88,7 @@ func (u *Updater) Update() error {
func Init(cacheDir string, javaDBRepository name.Reference, skip, quiet bool, registryOption ftypes.RegistryOptions) {
updater = &Updater{
repo: javaDBRepository,
dbDir: filepath.Join(cacheDir, "java-db"),
dbDir: dbDir(cacheDir),
skip: skip,
quiet: quiet,
registryOption: registryOption,
@@ -107,6 +107,14 @@ func Update() error {
return err
}
func Clear(ctx context.Context, cacheDir string) error {
return os.RemoveAll(dbDir(cacheDir))
}
func dbDir(cacheDir string) string {
return filepath.Join(cacheDir, "java-db")
}
type DB struct {
driver db.DB
}