Repository navigation
lib: replace Readdir(-1) with os.ReadDir - #8901
Merged
Merged
Conversation
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 <[email protected]>
calmh
approved these changes
May 11, 2023
Juneezee
marked this pull request as ready for review
May 11, 2023 15:05
calmh
added a commit
to calmh/syncthing
that referenced
this pull request
Jun 4, 2023
* main: gui: Remove HTML support in tooltips cmd/syncthing: Use correct binary when restarting monitor (syncthing#8919) build(deps): bump github.com/minio/sha256-simd from 1.0.0 to 1.0.1 (syncthing#8916) build: Increase concurrency, add "basic checks" gatekeeper gui, man, authors: Update docs, translations, and contributors gui, man, authors: Update docs, translations, and contributors lib/model: Set platform data for new folders w/ ignorePerms (ref syncthing#8883) (syncthing#8907) gui, man, authors: Update docs, translations, and contributors lib: replace `Readdir(-1)` with `os.ReadDir` (syncthing#8901) lib/api: Allow BindDN to exclude any username formatting (fixes syncthing#8899) (syncthing#8900) build: Attempt cross compilation for ~all targets, allow it to fail lib/fs: Fix root path handling for Windows (fixes syncthing#8778) all: Grand test refactor (fixes syncthing#8779, fixes syncthing#8799) all: Correct various typos (syncthing#8870)
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Purpose
We can simplify the following code
with just
os.ReadDir(dirname).os.ReadDiris recommended overReaddir(), as stated in the official doc 1Authorship
Your name and email will be added automatically to the AUTHORS file
based on the commit metadata.
Footnotes
"Most clients are better served by the more efficient ReadDir method." https://pkg.go.dev/os#File.Readdir ↩