Skip to content

Commit 13ef3e7

Browse files
authored
fix(db): check DownloadedAt for trivy-java-db (#7592)
1 parent 3fa24e8 commit 13ef3e7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/javadb/client.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (u *Updater) Update() error {
5353
}
5454
}
5555

56-
if (meta.Version != SchemaVersion || meta.NextUpdate.Before(time.Now().UTC())) && !u.skip {
56+
if (meta.Version != SchemaVersion || !u.isNewDB(meta)) && !u.skip {
5757
// Download DB
5858
log.Info("Java DB Repository", log.Any("repository", u.repo))
5959
log.Info("Downloading the Java DB...")
@@ -85,6 +85,20 @@ func (u *Updater) Update() error {
8585
return nil
8686
}
8787

88+
func (u *Updater) isNewDB(meta db.Metadata) bool {
89+
now := time.Now().UTC()
90+
if now.Before(meta.NextUpdate) {
91+
log.Debug("Java DB update was skipped because the local Java DB is the latest")
92+
return true
93+
}
94+
95+
if now.Before(meta.DownloadedAt.Add(time.Hour * 24)) { // 1 day
96+
log.Debug("Java DB update was skipped because the local Java DB was downloaded during the last day")
97+
return true
98+
}
99+
return false
100+
}
101+
88102
func Init(cacheDir string, javaDBRepository name.Reference, skip, quiet bool, registryOption ftypes.RegistryOptions) {
89103
updater = &Updater{
90104
repo: javaDBRepository,

0 commit comments

Comments
 (0)