File tree 2 files changed +23
-5
lines changed
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ import (
21
21
"fmt"
22
22
"io/ioutil"
23
23
"os"
24
- "path"
25
24
"path/filepath"
26
25
"strings"
27
26
@@ -124,15 +123,19 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
124
123
func searchConfigTree (cwd string ) string {
125
124
// go back up to root and search for the config file
126
125
for {
127
- if _ , err := os .Stat (path .Join (cwd , "arduino-cli.yaml" )); os .IsNotExist (err ) {
126
+ if _ , err := os .Stat (filepath .Join (cwd , "arduino-cli.yaml" )); err == nil {
127
+ // config file found
128
+ return cwd
129
+ } else if os .IsNotExist (err ) {
128
130
// no config file found
129
- next := path . Join (cwd , ".." )
130
- if filepath . Clean ( next ) == filepath . Clean ( cwd ) {
131
+ next := filepath . Dir (cwd )
132
+ if next == cwd {
131
133
return ""
132
134
}
133
135
cwd = next
134
136
} else {
135
- return cwd
137
+ // some error we can't handle happened
138
+ return ""
136
139
}
137
140
}
138
141
}
Original file line number Diff line number Diff line change @@ -513,3 +513,18 @@ func TestSearchConfigTreeInParent(t *testing.T) {
513
513
require .Nil (t , err )
514
514
require .Equal (t , searchConfigTree (target ), tmp )
515
515
}
516
+
517
+ var result string
518
+
519
+ func BenchmarkSearchConfigTree (b * testing.B ) {
520
+ tmp := tmpDirOrDie ()
521
+ defer os .RemoveAll (tmp )
522
+ target := filepath .Join (tmp , "foo" , "bar" , "baz" )
523
+ os .MkdirAll (target , os .ModePerm )
524
+
525
+ var s string
526
+ for n := 0 ; n < b .N ; n ++ {
527
+ s = searchConfigTree (target )
528
+ }
529
+ result = s
530
+ }
You can’t perform that action at this time.
0 commit comments