Skip to content

Commit

Permalink
fix: relative recipe paths starting with ".." did not work
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Jun 12, 2024
1 parent 7b25d7c commit e8618a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
3 changes: 1 addition & 2 deletions pkg/recipe/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ var (

// LoadRecipe reads a recipe from a given path
func LoadRecipe(path string) (*Recipe, error) {
// TODO: is there a better way to handle this?
rootDir, err := filepath.Abs(strings.TrimPrefix(path, "file://"))
rootDir, err := filepath.Abs(path)
if err != nil {
return nil, err
}
Expand Down
17 changes: 6 additions & 11 deletions pkg/recipe/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package recipe

import (
"os"
"path/filepath"
"strings"
)

Expand All @@ -20,17 +19,13 @@ func DetermineRecipeURLType(url string) URLType {
return OCIType
}

if strings.HasPrefix(url, "file://") || filepath.IsAbs(url) || filepath.IsLocal(url) {
fileinfo, _ := os.Stat(url)
fileinfo, _ := os.Stat(url)

// If the file exists and it is not a directory, assume manifest
if fileinfo != nil && !fileinfo.IsDir() {
return ManifestType
}

// Else assume that the URL points to a recipe
return LocalType
// If the file exists and it is not a directory, assume manifest
if fileinfo != nil && !fileinfo.IsDir() {
return ManifestType
}

return UnknownType
// Else assume that the URL points to a local recipe
return LocalType
}
2 changes: 1 addition & 1 deletion test/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func aManifestFileThatIncludesRecipes(ctx context.Context, recipeNames *godog.Ta
recipes[i] = recipe.ManifestRecipe{
Name: re.Name,
Version: re.Version,
Repository: fmt.Sprintf("file://%s/%s", recipeDir, name),
Repository: fmt.Sprintf("%s/%s", recipeDir, name),
}
}

Expand Down

0 comments on commit e8618a4

Please sign in to comment.