Skip to content

Commit 6cb7ab0

Browse files
committed
Remove redundant os.Stat call, use os.ReadDir error directly
ReadDir already returns os.ErrNotExist when the directory does not exist, so no need to run Stat before ReadDir. Signed-off-by: chijiajian <33536362+chijiajian@users.noreply.github.com>
1 parent 343ab71 commit 6cb7ab0

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

sysfs/class_fibrechannel.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,15 @@ func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error)
152152
var counters FibreChannelCounters
153153

154154
path := filepath.Join(hostPath, "statistics")
155-
156-
if _, err := os.Stat(path); err != nil {
155+
files, err := os.ReadDir(path)
156+
if err != nil {
157157
if errors.Is(err, os.ErrNotExist) {
158158
// statistics directory not present, skip
159159
return &counters, nil
160160
}
161161
return nil, err
162162
}
163163

164-
files, err := os.ReadDir(path)
165-
if err != nil {
166-
return nil, err
167-
}
168-
169164
for _, f := range files {
170165
if !f.Type().IsRegular() || f.Name() == "reset_statistics" {
171166
continue

0 commit comments

Comments
 (0)