Skip to content

refactor: move from io/ioutil to io and os package#42792

Merged
thaJeztah merged 1 commit intomoby:masterfrom
Juneezee:deprecate-ioutil
Aug 27, 2021
Merged

refactor: move from io/ioutil to io and os package#42792
thaJeztah merged 1 commit intomoby:masterfrom
Juneezee:deprecate-ioutil

Conversation

@Juneezee
Copy link
Copy Markdown
Contributor

- What I did
The io/ioutil package has been deprecated in Go 1.16 (See https://golang.org/doc/go1.16#ioutil). This PR replaces the existing io/ioutil functions with their new definitions in io and os packages.

- How I did it
Searches and replaces the deprecated functions with the new functions using VSCode

- How to verify it
All usage of io/ioutil has been replaced by the corresponding new definitions in the io and os packages. Searching for io/ioutil should yield empty result.

- Description for the changelog

refactor: move from io/ioutil to io and os package

The io/ioutil package has been deprecated in Go 1.16. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

Signed-off-by: Eng Zer Jun <[email protected]>
@thaJeztah thaJeztah added kind/refactor PR's that refactor, or clean-up code status/4-merge labels Aug 27, 2021
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah added this to the 21.xx milestone Aug 27, 2021
@thaJeztah thaJeztah merged commit 085c6a9 into moby:master Aug 27, 2021
@thaJeztah
Copy link
Copy Markdown
Member

Thanks!

@tianon
Copy link
Copy Markdown
Member

tianon commented Aug 27, 2021

This makes it impossible to build against Go 1.16 -- that's OK, but IMO we should either drop explicitly drop support for older Go (and actually commit to it, like dropping all those old build tags we ended up keeping) or revert this. 😬

@thaJeztah
Copy link
Copy Markdown
Member

@tianon it was already in go 1.16, but not yet in 1.15

@tianon
Copy link
Copy Markdown
Member

tianon commented Aug 27, 2021

I wouldn't be here if it worked in Go 1.16: 😅

---> Making bundle: binary (in bundles/binary)
Building: bundles/binary-daemon/dockerd-dev
GOOS="" GOARCH="" GOARM=""
# github.com/docker/docker/pkg/plugins
pkg/plugins/discovery.go:44:12: undefined: fs.FileInfoToDirEntry

@thaJeztah
Copy link
Copy Markdown
Member

Ah, ugh. devil is in the details there. That's a great way of recommending people to use the new location, and "oh by the way, it's not compatible"

ReadDir => os.ReadDir (note: returns a slice of os.DirEntry rather than a slice of fs.FileInfo)

They should've backported these bits to Go 1.16.

https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/io/fs/readdir.go#L49-L77

Looking at our code, I see that's the only location it's used

git grep FileInfoToDirEntry
pkg/plugins/discovery.go:                       entry = fs.FileInfoToDirEntry(fi)

I think we can either revert the changes to that file, or copy the FileInfoToDirEntry function; WDYT?

@thaJeztah
Copy link
Copy Markdown
Member

I did a quick PR for variant "or copy the FileInfoToDirEntry function #42797, but happy to discuss the other options

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

Labels

kind/refactor PR's that refactor, or clean-up code status/4-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants