Skip to content

pkg/plugins: fix compatibility with go1.16#42797

Merged
cpuguy83 merged 1 commit intomoby:masterfrom
thaJeztah:go116_compat
Aug 31, 2021
Merged

pkg/plugins: fix compatibility with go1.16#42797
cpuguy83 merged 1 commit intomoby:masterfrom
thaJeztah:go116_compat

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented Aug 27, 2021

relates to #42792 (comment)

commit c55a4ac (#42792) changed the ioutil utilities
to use the new os variants, per recommendation from the go 1.16 release notes:
https://golang.org/doc/go1.16#ioutil

we encourage new code to use the new definitions in the io and os packages.
Here is a list of the new locations of the names exported by io/ioutil:

However, the devil is in the detail, and io.ReadDir() is not a direct
replacement for ioutil.ReadDir();

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

go1.17 added a io.FileInfoToDirEntry() utility to concert a DirEntry to
a FileInfo, but it's not available in go1.16

This patch copies the FileInfoToDirEntry code, and uses it for go1.16.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Copy Markdown
Member Author

@tianon @tonistiigi @cpuguy83 PTAL - let's discuss what direction we want to take.

Alternatives:

  1. revert refactor: move from io/ioutil to io and os package #42792 as a whole
  2. only revert the changes in pkg/plugins
  3. other suggestions ????

@thaJeztah
Copy link
Copy Markdown
Member Author

Ahum. of course it helps if you import the correct package 🤦 should be fixed now

Copy link
Copy Markdown
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

I tested and this does successfully compile on Go 1.16 -- just a minor note/question/discussion about the new go1.16 file. 😇

Comment thread pkg/plugins/utils_go1.16.go
commit c55a4ac changed the ioutil utilities
to use the new os variants, per recommendation from the go 1.16 release notes:
https://golang.org/doc/go1.16#ioutil

> we encourage new code to use the new definitions in the io and os packages.
> Here is a list of the new locations of the names exported by io/ioutil:

However, the devil is in the detail, and io.ReadDir() is not a direct
replacement for ioutil.ReadDir();

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

go1.16 added a io.FileInfoToDirEntry() utility to concert a DirEntry to
a FileInfo, but it's not available in go1.16

This patch copies the FileInfoToDirEntry code, and uses it for go1.16.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Copy Markdown
Member Author

@tianon I added a comment describing where we copied the code from (and why); PTAL

Copy link
Copy Markdown
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants