refactor(shell): use fs instead of os for parent

This commit is contained in:
Jan De Dobbeleer 2022-11-02 15:57:30 +01:00 committed by Jan De Dobbeleer
parent cbd6518faf
commit 52b01aff63
2 changed files with 4 additions and 4 deletions

View file

@ -654,12 +654,12 @@ func (env *ShellEnvironment) HasParentFilePath(path string) (*FileInfo, error) {
defer env.Trace(time.Now(), "HasParentFilePath", path)
currentFolder := env.Pwd()
for {
searchPath := filepath.Join(currentFolder, path)
info, err := os.Stat(searchPath)
fileSystem := os.DirFS(currentFolder)
info, err := fs.Stat(fileSystem, path)
if err == nil {
return &FileInfo{
ParentFolder: currentFolder,
Path: searchPath,
Path: filepath.Join(currentFolder, path),
IsDir: info.IsDir(),
}, nil
}

View file

@ -21,7 +21,7 @@ func BenchmarkInit(b *testing.B) {
func BenchmarkPrimary(b *testing.B) {
cmd := cli.RootCmd
// needs to be a non-existing file as we panic otherwise
cmd.SetArgs([]string{"print", "primary", "--config", "err.omp.json", "--pwd", "/Users/jan/Code/oh-my-posh/src"})
cmd.SetArgs([]string{"print", "primary", "--config", "err.omp.json", "--pwd", "/Users/jan/Code/oh-my-posh/src", "--shell", "fish"})
out := bytes.NewBufferString("")
cmd.SetOut(out)