Skip to content

Commit

Permalink
move parent check outside of readMACFromFile
Browse files Browse the repository at this point in the history
  • Loading branch information
ganawaj committed Jan 17, 2025
1 parent 4baee3a commit a146b48
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions pkg/sysfsnet/interfaces_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ 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
// }

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

f, err := os.Open(s)

if os.IsNotExist(err) {
Expand All @@ -56,11 +42,20 @@ func Interfaces() ([]Interface, error) {

for _, dentry := range dents {

if !dentry.IsDir() {
entryPath := filepath.Join(sysClassNet, dentry.Name())

// os.Stat to follow symlinks and return the info of the target
info, err := os.Stat(entryPath)
if err != nil {
continue
}

// os.FileInfo.IsDir to check if the entry is a directory
if !info.IsDir() {
continue
}

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

0 comments on commit a146b48

Please sign in to comment.