Add Abs(); clean up

This commit is contained in:
Denis Bilenko 2024-12-10 14:26:12 +01:00
parent dab674bbdb
commit 122e6f5a4c
2 changed files with 4 additions and 32 deletions

View File

@ -9,6 +9,10 @@ import (
// FindDirWithLeaf returns the first directory that holds `leaf`,
// traversing up to the root of the filesystem, starting at `dir`.
func FindDirWithLeaf(dir string, leaf string) (string, error) {
p, err := filepath.Abs(p)
if err != nil {
return "", err
}
for {
_, err := os.Stat(filepath.Join(dir, leaf))

View File

@ -2,12 +2,8 @@ package git
import (
"context"
"errors"
"io/fs"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"github.com/databricks/cli/libs/dbr"
@ -135,31 +131,3 @@ func fetchRepositoryInfoDotGit(ctx context.Context, path string) (RepositoryInfo
return result, nil
}
func FindLeafInTree(p string, leafName string) (string, error) {
p, err := filepath.Abs(p)
if err != nil {
return "", err
}
for i := 0; i < 10000; i++ {
_, err = os.Stat(filepath.Join(p, leafName))
if err == nil {
// Found [leafName] in p
return p, nil
}
// ErrNotExist means we continue traversal up the tree.
if errors.Is(err, fs.ErrNotExist) {
parent := filepath.Dir(p)
if parent == p {
return "", nil
}
p = parent
continue
}
break
}
return "", err
}