mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-10 10:47:51 +08:00
align kubo with unified golang ci linter from IPDX and rules used in boxo and other go packages addressed lint rules: - ST1000: added package comments - ST1020, ST1021, ST1022: fixed function/method comments - QF1001: applied De Morgan's law - QF1003: converted if-else chains to tagged switches - QF1004: replaced strings.Replace with strings.ReplaceAll - QF1008: simplified embedded struct field selectors - unconvert: removed unnecessary type conversions - usestdlibvars: used stdlib constants instead of literals disabled errcheck linter in .golangci.yml
38 lines
657 B
Go
38 lines
657 B
Go
package testutils
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func MustOpen(name string) *os.File {
|
|
f, err := os.Open(name)
|
|
if err != nil {
|
|
log.Panicf("opening %s: %s", name, err)
|
|
}
|
|
return f
|
|
}
|
|
|
|
// FindUp searches for a file in a dir, then the parent dir, etc.
|
|
// If the file is not found, an empty string is returned.
|
|
func FindUp(name, dir string) string {
|
|
curDir := dir
|
|
for {
|
|
entries, err := os.ReadDir(curDir)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
for _, e := range entries {
|
|
if name == e.Name() {
|
|
return filepath.Join(curDir, name)
|
|
}
|
|
}
|
|
newDir := filepath.Dir(curDir)
|
|
if newDir == curDir {
|
|
return ""
|
|
}
|
|
curDir = newDir
|
|
}
|
|
}
|