github.com/jaypipes/ghw@v0.21.1/pkg/snapshot/clonetree_usb_linux.go (about) 1 // 2 // Use and distribution licensed under the Apache license version 2. 3 // 4 // See the COPYING file in the root project directory for full text. 5 // 6 7 package snapshot 8 9 import ( 10 "os" 11 "path/filepath" 12 ) 13 14 // ExpectedCloneUSBContent returns a slice of strings pertaning to the USB interfaces 15 func ExpectedCloneUSBContent() []string { 16 const sysBusUSB = "/sys/bus/usb/devices/" 17 18 paths := []string{sysBusUSB} 19 usbDevicesDirs, err := os.ReadDir(sysBusUSB) 20 if err != nil { 21 return []string{} 22 } 23 24 for _, dir := range usbDevicesDirs { 25 susBusUSBLink := filepath.Join(sysBusUSB, dir.Name()) 26 paths = append(paths, susBusUSBLink) 27 28 fullDir, err := os.Readlink(susBusUSBLink) 29 if err != nil { 30 continue 31 } 32 if !filepath.IsAbs(fullDir) { 33 fullDir, err = filepath.Abs(filepath.Join(sysBusUSB, fullDir)) 34 if err != nil { 35 continue 36 } 37 } 38 for _, fileName := range []string{"uevent", "interface", "product"} { 39 paths = append(paths, filepath.Join(fullDir, fileName)) 40 } 41 42 } 43 44 return paths 45 }