mirror of
https://gitlab.com/arm-research/smarter/smarter-device-manager.git
synced 2024-11-22 02:33:34 +00:00
Fix recursion problem
This commit is contained in:
parent
a6c2189a98
commit
1421f564e5
16
main.go
16
main.go
@ -55,7 +55,7 @@ func init() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func readDevDirectory(dirToList string) (files []string, err error) {
|
func readDevDirectory(dirToList string, allowedRecursions uint8) (files []string, err error) {
|
||||||
var foundFiles []string
|
var foundFiles []string
|
||||||
|
|
||||||
fType, err := os.Stat(dirToList)
|
fType, err := os.Stat(dirToList)
|
||||||
@ -79,10 +79,12 @@ func readDevDirectory(dirToList string) (files []string, err error) {
|
|||||||
f.Close()
|
f.Close()
|
||||||
for _, subDir := range files {
|
for _, subDir := range files {
|
||||||
foundFiles = append(foundFiles, subDir)
|
foundFiles = append(foundFiles, subDir)
|
||||||
filesDir, err := readDevDirectory(dirToList+"/"+subDir)
|
if allowedRecursions > 0 {
|
||||||
if err == nil {
|
filesDir, err := readDevDirectory(dirToList+"/"+subDir,allowedRecursions-1)
|
||||||
for _, fileName := range filesDir {
|
if err == nil {
|
||||||
foundFiles = append(foundFiles, subDir+"/"+fileName)
|
for _, fileName := range filesDir {
|
||||||
|
foundFiles = append(foundFiles, subDir+"/"+fileName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,13 +129,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glog.V(0).Info("Reading existing devices on /dev")
|
glog.V(0).Info("Reading existing devices on /dev")
|
||||||
ExistingDevices, err := readDevDirectory("/dev")
|
ExistingDevices, err := readDevDirectory("/dev",10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf(err.Error())
|
glog.Errorf(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExistingDevicesSys, err := readDevDirectory("/sys/devices")
|
ExistingDevicesSys, err := readDevDirectory("/sys/devices",0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf(err.Error())
|
glog.Errorf(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user