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

refactor: replace Readdir(-1) with os.ReadDir #3361

Merged
merged 1 commit into from May 8, 2023
Merged

refactor: replace Readdir(-1) with os.ReadDir #3361

merged 1 commit into from May 8, 2023

Conversation

Juneezee
Copy link
Contributor

@Juneezee Juneezee commented May 7, 2023

We can simplify the following code

dir, err := os.Open(dirname)
if err != nil {
	return err
}
defer dir.Close()

dirs, err := dir.Readdir(-1)

with just os.ReadDir(dirname). os.ReadDir is recommended over Readdir(), as stated in the official doc 1

Footnotes

  1. "Most clients are better served by the more efficient ReadDir method." https://pkg.go.dev/os#File.Readdir

We can simplify the following code
	dir, err := os.Open(dirname)
	if err != nil {
		return err
	}
	defer dir.Close()

	dirs, err := dir.Readdir(-1)

with just `os.ReadDir(dirname)`.

Reference: https://pkg.go.dev/os#ReadDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Copy link
Member

@derekparker derekparker left a comment

Choose a reason for hiding this comment

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

LGTM

@derekparker derekparker merged commit 8711f62 into go-delve:master May 8, 2023
1 of 2 checks passed
@Kevin40481 Kevin40481 linked an issue May 18, 2023 that may be closed by this pull request
@achal1012
Copy link

# github.com/go-delve/delve/pkg/proc/gdbserial
gopath/src/github.com/go-delve/delve/pkg/proc/gdbserial/rr.go:303:14: undefined: os.ReadDir

I started seeing this error when I run Docker on my mac (both x86 and ARM64) do you think its related to this change?

@Juneezee
Copy link
Contributor Author

# github.com/go-delve/delve/pkg/proc/gdbserial
gopath/src/github.com/go-delve/delve/pkg/proc/gdbserial/rr.go:303:14: undefined: os.ReadDir

I started seeing this error when I run Docker on my mac (both x86 and ARM64) do you think its related to this change?

@achal1012 Make sure you have Go 1.16 or newer

@achal1012
Copy link

achal1012 commented Jun 13, 2023

Thanks @Juneezee I have this:

go version 
go version go1.19.3 darwin/amd64

Oh wait I see the issue: my docker has older go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kingbug
3 participants