Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): check DownloadedAt for trivy-java-db #7592

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkg/javadb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (u *Updater) Update() error {
}
}

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

func (u *Updater) isNewDB(meta db.Metadata) bool {
now := time.Now().UTC()
if now.Before(meta.NextUpdate) {
log.Debug("Java DB update was skipped because the local Java DB is the latest")
return true
}

if now.Before(meta.DownloadedAt.Add(time.Hour * 24)) { // 1 day
log.Debug("Java DB update was skipped because the local Java DB was downloaded during the last hour")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log message should be updated, (day, not hour)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. I overlooked it. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Updated in 1de0a81

return true
}
return false
}

func Init(cacheDir string, javaDBRepository name.Reference, skip, quiet bool, registryOption ftypes.RegistryOptions) {
updater = &Updater{
repo: javaDBRepository,
Expand Down