fix: remove deprecate way of implementaion#121
Open
pohanhuang wants to merge 1 commit into
Open
Conversation
- ioutils - Sprintf - replac(.., -1) Signed-off-by: pohanhuang <pohan.huang@suse.com>
There was a problem hiding this comment.
Pull request overview
This PR modernizes and streamlines multiple fetchers/utilities by removing deprecated io/ioutil usage, reducing fmt.Sprintf usage in favor of direct string building, and switching legacy strings.Replace(..., -1) calls to strings.ReplaceAll.
Changes:
- Replace deprecated
io/ioutilhelpers withio.ReadAll,os.ReadFile,os.ReadDir,os.MkdirTemp,os.CreateTemp, etc. - Reduce formatting overhead by replacing many
fmt.Sprintfcalls with string concatenation /strconvconversions. - Replace
strings.Replace(..., -1)withstrings.ReplaceAllin multiple fetchers.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| updater/nvd/xml.go | Removes fmt.Sprintf from CVSS vector construction in favor of direct concatenation. |
| updater/fetchers/ubuntu/ubuntu.go | Replaces ioutil.TempDir and various Sprintf uses with os.MkdirTemp and concatenation. |
| updater/fetchers/suse/suse.go | Uses direct concatenation for local file paths and namespace construction; switches to ReplaceAll. |
| updater/fetchers/rocky/rocky.go | Replaces fmt.Sprintf in namespaces and pagination URL construction with strconv + concatenation. |
| updater/fetchers/rhel2/rhel.go | Replaces ioutil usage and multiple Sprintf-built keys/URLs with io/os and concatenation. |
| updater/fetchers/photon/photon.go | Removes fmt usage; uses strconv.FormatFloat for namespace string building. |
| updater/fetchers/oracle/oracle.go | Replaces strings.Replace(..., -1) with ReplaceAll and removes some Sprintf usage. |
| updater/fetchers/mariner/mariner.go | Replaces Sprintf path building with concatenation; replaces fmt.Println with structured logging and skips invalid entries. |
| updater/fetchers/debian/debian.go | Replaces Sprintf path building with concatenation. |
| updater/fetchers/chainguardv2/chainguardv2.go | Replaces formatted advisory URL template with prefix/suffix concatenation. |
| updater/fetchers/apps/ruby.go | Replaces ioutil.TempDir/ReadFile with os.MkdirTemp/os.ReadFile; adjusts comment formatting. |
| updater/fetchers/apps/openssl.go | Replaces ioutil.ReadAll with io.ReadAll. |
| updater/fetchers/apps/nginx.go | Replaces ioutil.ReadAll with io.ReadAll and switches several Replace calls to ReplaceAll. |
| updater/fetchers/apps/manual.go | Replaces fmt.Sprintf path building with concatenation. |
| updater/fetchers/apps/k8s.go | Replaces ioutil.ReadAll with io.ReadAll and uses concatenation for local file path building. |
| updater/fetchers/apps/govuln.go | Replaces fmt.Sprintf local file path building with concatenation. |
| updater/fetchers/apps/ghsa.go | Replaces some Sprintf usage with concatenation (keys and description assembly). |
| updater/fetchers/apps/cvedetails.go | Replaces ioutil.ReadAll with io.ReadAll and removes a Sprintf string-contains usage. |
| updater/fetchers/apps/apps.go | Replaces fmt.Sprintf key building with concatenation. |
| updater/fetchers/amazon/amazon.go | Replaces ioutil.ReadAll with io.ReadAll and switches namespace formatting to strconv.Itoa. |
| updater/fetchers/alpine/alpine.go | Removes ioutil/fmt, adds response read error handling, and reuses a package-level namespace regex. |
| updater/fetchers/alpine/alpine_test.go | Updates tests to use package-level nsRegexp and os.ReadFile instead of ioutil. |
| share/utils.go | Replaces ioutil.ReadAll with io.ReadAll. |
| share/tar.go | Replaces multiple ioutil helpers with io/os equivalents and switches to ReplaceAll for path sanitization. |
| share/set.go | Replaces fmt.Sprintf in String() with direct concatenation around strings.Join. |
| common/debug.go | Replaces fmt.Sprintf("%s...", ...) with direct concatenation. |
Comments suppressed due to low confidence (1)
updater/fetchers/photon/photon.go:120
- The version parsing error check uses the wrong variable (
errinstead oferr2), so parse failures fromcommon.NewVersionmay be silently ignored (or the check may trigger incorrectly based on an unrelated earlier error).
namespace := "photon:" + strconv.FormatFloat(file.Version, 'f', -1, 64)
if vuln.ResolvedVersion == "N/A" || vuln.ResolvedVersion == "NA" {
vuln.ResolvedVersion = common.MaxVersion.String()
}
version, err2 := common.NewVersion(vuln.ResolvedVersion)
if err != nil {
log.WithFields(log.Fields{"err": err2, "vuln": vuln.CveId}).Info("Unable to resolve version for photon vulnerability.")
continue
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description