Skip to content

chore: Updater tool#5046

Closed
another-rex wants to merge 9 commits intogoogle:masterfrom
another-rex:modified-date-fix-tool
Closed

chore: Updater tool#5046
another-rex wants to merge 9 commits intogoogle:masterfrom
another-rex:modified-date-fix-tool

Conversation

@another-rex
Copy link
Contributor

Tool to update modified date back to the original value from local snapshot

@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@another-rex another-rex requested review from a team and michaelkedar March 13, 2026 06:27
vuln.Modified = fileModifiedTime
vuln.ModifiedRaw = fileModifiedTime

if _, err := client.Put(ctx, key, &vuln); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

you also need to write the vuln to GCS (and set the CustomTime field)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok fixed!

@another-rex
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new command-line tool, vuln-modified-sync, for synchronizing vulnerability modification times from local files to Datastore and GCS. The overall implementation is solid, utilizing a concurrent worker pool for efficient processing. My review focuses on improving code clarity, simplifying complex logic, and addressing a potential compatibility issue. Specifically, I've suggested making a time comparison more readable, simplifying a function that uses reflection, and replacing a Go 1.22+ specific feature with a more compatible alternative to prevent potential build failures on older Go versions.

sliceType := reflect.SliceOf(val.Type().Elem())
newSlice := reflect.MakeSlice(sliceType, 0, val.Len())
hasValues := false
for i := range val.Len() {
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The for i := range n loop over an integer n is a new feature introduced in Go 1.22. To maintain compatibility with older Go versions (pre-1.22) that the project might be using, it is safer to use the traditional for i := 0; i < val.Len(); i++ loop.

for i := 0; i < val.Len(); i++ {

}

// Minus 1 minute to file modified time to avoid any precision issues
if fileModifiedTime.Add(time.Minute * -1).After(vuln.Modified) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The expression fileModifiedTime.Add(time.Minute * -1).After(vuln.Modified) is functionally correct, but can be written in a more readable way as fileModifiedTime.After(vuln.Modified.Add(time.Minute)). This more clearly expresses the intent of checking if the file's time is later than the datastore time plus a buffer.

Additionally, the comment on line 259 is a bit misleading. This check is more about setting a threshold to avoid updates for minor time differences, rather than a "precision issue". Consider clarifying the comment and using a named constant for the one-minute duration to improve readability.

Suggested change
if fileModifiedTime.Add(time.Minute * -1).After(vuln.Modified) {
if fileModifiedTime.After(vuln.Modified.Add(time.Minute)) {

Comment on lines +337 to +348
if v != nil {
rt := reflect.ValueOf(v)
if rt.Kind() == reflect.Slice || rt.Kind() == reflect.Map {
if rt.Len() > 0 {
newMap.SetMapIndex(k, reflect.ValueOf(v))
hasValues = true
}
} else {
newMap.SetMapIndex(k, reflect.ValueOf(v))
hasValues = true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic within this if v != nil block can be simplified. The recursive call to removeEmptySlicesAndMaps already ensures that v will be nil if it's an empty slice or map. Therefore, the subsequent checks for kind and length are redundant. The block can be reduced to simply setting the map index if v is not nil.

if v != nil {
				newMap.SetMapIndex(k, reflect.ValueOf(v))
				hasValues = true
			}

Comment on lines +234 to +235
m1Strip := removeEmptySlicesAndMaps(m1)
m2Strip := removeEmptySlicesAndMaps(m2)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this matters in practice, but I think differences in empty slices/maps vs omitted fields should actually be considered different

@another-rex
Copy link
Contributor Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants