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

lib: replace Readdir(-1) with os.ReadDir #8901

Merged
merged 1 commit into from
May 11, 2023
Merged

lib: replace Readdir(-1) with os.ReadDir #8901

merged 1 commit into from
May 11, 2023

Conversation

Juneezee
Copy link
Contributor

Purpose

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

Authorship

Your name and email will be added automatically to the AUTHORS file
based on the commit metadata.

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>
@Juneezee Juneezee marked this pull request as ready for review May 11, 2023 15:05
@calmh calmh merged commit 089320a into syncthing:main May 11, 2023
15 of 16 checks passed
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)
@calmh calmh added this to the v1.23.6 milestone Jun 4, 2023
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label May 10, 2024
@syncthing syncthing locked and limited conversation to collaborators May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants