Skip to content

Commit

Permalink
simplify check for dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ganawaj committed Jan 17, 2025
1 parent 7eccfc1 commit 4baee3a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions pkg/sysfsnet/interfaces_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ func Interfaces() ([]Interface, error) {
readMACFromFile := func(s string) (string, error) {

// Check if parent exists and is a directory
parent := filepath.Dir(s)
info, err := os.Stat(parent)
if err != nil {
if os.IsNotExist(err) {
return "", nil
}
return "", err
}
// parent := filepath.Dir(s)
// info, err := os.Stat(parent)
// if err != nil {
// if os.IsNotExist(err) {
// return "", nil
// }
// return "", err
// }

if !info.IsDir() {
return "", nil
}
// if !info.IsDir() {
// return "", nil
// }

f, err := os.Open(s)

Expand All @@ -55,6 +55,11 @@ func Interfaces() ([]Interface, error) {
}

for _, dentry := range dents {

if !dentry.IsDir() {
continue
}

hwText, err := readMACFromFile(filepath.Join(sysClassNet, dentry.Name(), "address"))
if os.IsNotExist(err) {
continue
Expand Down

0 comments on commit 4baee3a

Please sign in to comment.