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

Replace deprecated ioutil with io and os #10732

Merged
merged 3 commits into from Mar 1, 2023

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented Feb 18, 2023

This PR removes usages of io/ioutil.

The package io/ioutil is deprecated since Go 1.16:

Deprecated: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details.

Changes

  • Replace ioutil.ReadAll, ioutil.Discard, ioutil.NopCloser with io.ReadAll, io.Discard, io.NopCloser.
  • Replace ioutil.ReadFile, ioutil.WriteFile, ioutil.ReadDir with os.ReadFile, os.WriteFile, os.ReadDir.
  • Replace ioutil.TempFile with os.CreateTemp.
  • Replace ioutil.TempDir with os.MkdirTemp.

Tests only

  • Replace ioutil.TempDir with t.TempDir(). T.TempDir automatically clears directory.
  • Refactor initFsTests by replacing ioutil.TempDir with t.TempDir and using t.Cleanup instead of manual cleanup.
  • Remove unused createEmptyTempDir and deleteTempDir after refactoring to t.TempDir.

@alexandear alexandear force-pushed the deprecated-ioutil branch 2 times, most recently from eba0f7c to 91c25eb Compare February 18, 2023 23:04
@bep
Copy link
Member

bep commented Feb 21, 2023

Thanks for this. This needs to wait before I can merge; I have some bigger change sets in the merge pipeline in the near future, and I fear that these changes may create lots of potential merge conflicts.

@bep bep added this to the v0.111.0 milestone Mar 1, 2023
@bep bep force-pushed the deprecated-ioutil branch 3 times, most recently from dc46d0b to 033b822 Compare March 1, 2023 10:18
@CLAassistant
Copy link

CLAassistant commented Mar 1, 2023

CLA assistant check
All committers have signed the CLA.

alexandear and others added 2 commits March 1, 2023 11:30
To make the tests pass.

* Replace io => os.ReadFile in magefile.go
* Adjust failing image test vs fs.DirEntry
* Adjust poller test

See #10732
@alexandear
Copy link
Contributor Author

Created #10768 about data race in tests.

@bep
Copy link
Member

bep commented Mar 1, 2023

@alexandear I'm going to merge this once the tests go green, but a general remark for the future: If you have a PR that states that it does one isolated thing (ioutil => os) it would be good if it also doesn't do some refactoring of something totally unrelated. I know it's tempting and I'm certainly throwing stones in a glass house here, but it makes PRs like these much harder to reason about than they should.

@bep bep merged commit 5c317c5 into gohugoio:master Mar 1, 2023
bep added a commit that referenced this pull request Mar 1, 2023
To make the tests pass.

* Replace io => os.ReadFile in magefile.go
* Adjust failing image test vs fs.DirEntry
* Adjust poller test

See #10732
@alexandear alexandear deleted the deprecated-ioutil branch March 1, 2023 18:34
Copy link

github-actions bot commented Mar 1, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants