-
Notifications
You must be signed in to change notification settings - Fork 503
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
⚠️ Switch RepoClient file access to io.ReadCloser #3912
Merged
Merged
Conversation
This file contains 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
callers don't always need the full file. large files are slow and can cause crashes. Signed-off-by: Spencer Schrock <sschrock@google.com>
Previously they returned bytes or strings, which have corresponding NewReader types. Since they don't need to be closed, io.NopCloser works well to give them a fake Close. Signed-off-by: Spencer Schrock <sschrock@google.com>
os.File fufills io.ReadCloser, so this is an easy change Signed-off-by: Spencer Schrock <sschrock@google.com>
The rest of the test was kept the same to minimize the change. Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
spencerschrock
temporarily deployed
to
integration-test
March 4, 2024 17:56
— with
GitHub Actions
Inactive
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3912 +/- ##
==========================================
- Coverage 75.12% 70.51% -4.62%
==========================================
Files 234 234
Lines 15842 15857 +15
==========================================
- Hits 11901 11181 -720
- Misses 3183 3965 +782
+ Partials 758 711 -47 |
add check which ensures git client fulfills the interface Signed-off-by: Spencer Schrock <sschrock@google.com>
/scdiff generate Fuzzing,Token-Permissions,Pinned-Dependencies,SAST,Security-Policy,Binary-Artifact,Dangerous-Workflow,Packaging |
spencerschrock
temporarily deployed
to
integration-test
March 4, 2024 18:28
— with
GitHub Actions
Inactive
spencerschrock
requested review from
raghavkaul and
laurentsimon
and removed request for
a team
March 4, 2024 19:13
laurentsimon
approved these changes
Mar 4, 2024
fhoeborn
pushed a commit
to fhoeborn/scorecard
that referenced
this pull request
Apr 1, 2024
* change file access method to io.ReadCloser callers don't always need the full file. large files are slow and can cause crashes. Signed-off-by: Spencer Schrock <sschrock@google.com> * switch tests to hardcoded readers Previously they returned bytes or strings, which have corresponding NewReader types. Since they don't need to be closed, io.NopCloser works well to give them a fake Close. Signed-off-by: Spencer Schrock <sschrock@google.com> * switch tests which called os.ReadFile to os.Open os.File fufills io.ReadCloser, so this is an easy change Signed-off-by: Spencer Schrock <sschrock@google.com> * break tarball tests into two steps: reader and read The rest of the test was kept the same to minimize the change. Signed-off-by: Spencer Schrock <sschrock@google.com> * ossfuzz doesn't implement GetFileReader Signed-off-by: Spencer Schrock <sschrock@google.com> * appease linter during refactor Signed-off-by: Spencer Schrock <sschrock@google.com> * switch git client to new method add check which ensures git client fulfills the interface Signed-off-by: Spencer Schrock <sschrock@google.com> --------- Signed-off-by: Spencer Schrock <sschrock@google.com>
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.
What kind of change does this PR introduce?
breaking change
What is the current behavior?
Checks which deal with file content must work with the whole file contents. Some usages don't require any data, some require only the first line, others require 1 KiB. This is inefficient, and leads to crashes. (See #3831 (comment))
What is the new behavior (if this is a feature change)?**
Clients will provide an
io.ReadCloser
when accessing a file, so the callers can use as much or as little data as they need.GetFileContent
will useio.ReadAll
to get the whole file contents, and thenClose
the Reader.Cleaned up the tests to return
io.ReadClosers
.Tests for the changes have been added (for bug fixes/features)
Which issue(s) this PR fixes
Related to #3831, however follow-up PRs are needed to allow Binary-Artifacts and Pinned-Dependencies to take advantage of the
io.Reader
Special notes for your reviewer
#3831 (comment) talks about a non-breaking way of doing this, but with V5 around the corner, breaking changes are fine.
This is simpler than maintaining two versions of the functions (
[]byte
andio.Reader
versions)Does this PR introduce a user-facing change?
For user-facing changes, please add a concise, human-readable release note to
the
release-note
(In particular, describe what changes users might need to make in their
application as a result of this pull request.)