Skip to content

Commit

Permalink
Fix issue where .manifest files didn't register as roots (#1081)
Browse files Browse the repository at this point in the history
We previously traversed the path downwards, so if we had
`foo/bar/.manifest` and `foo/bar/baz` was provided, we would
not find `foo/bar` as a root. Now search for manifests from the
root.

Fixes #1077

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert authored Sep 9, 2024
1 parent 71e17a3 commit a562087
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ func WalkFiles(root string, f func(path string) error) error {
})
}

// FindManifestLocations walks the file system rooted at root, and returns the
// *relative* paths of directories containing a .manifest file.
func FindManifestLocations(root string) ([]string, error) {
var foundBundleRoots []string

Expand Down
10 changes: 8 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func FindRegalDirectory(path string) (*os.File, error) {
//
// - Configuration (`project.roots`)
// - By the presence of a .manifest file anywhere under the path
// - By the presence of a .regal directory anywhere under or above the path ... TODO (anders): might reconsider "above"?
// - By the presence of a .regal directory anywhere under or above the path ...
//
// All returned paths are absolute paths. If the provided path itself
// is determined to be a bundle root directory it will be included in the result.
Expand Down Expand Up @@ -219,7 +219,6 @@ func FindBundleRootDirectories(path string) ([]string, error) {
foundBundleRoots = append(foundBundleRoots, roots...)
}

// rather than calling rio.FindManifestLocations later, let's
// check for .manifest directories as part of the same walk
if !info.IsDir() && info.Name() == ".manifest" {
foundBundleRoots = append(foundBundleRoots, filepath.Dir(path))
Expand Down Expand Up @@ -268,6 +267,13 @@ func rootsFromRegalDirectory(regalDir *os.File) ([]string, error) {
foundBundleRoots = append(foundBundleRoots, customRulesDir)
}

manifestRoots, err := rio.FindManifestLocations(filepath.Dir(regalDir.Name()))
if err != nil {
return nil, fmt.Errorf("failed while looking for manifest locations: %w", err)
}

foundBundleRoots = append(foundBundleRoots, util.Map(util.FilepathJoiner(parent), manifestRoots)...)

return foundBundleRoots, nil
}

Expand Down

0 comments on commit a562087

Please sign in to comment.