From 94bdf8275ad71f6f46e5588b45fe74d88cc701f6 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Sat, 7 Oct 2023 18:16:11 -0700 Subject: [PATCH] Fix search package --- pkg/search/search.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/search/search.go b/pkg/search/search.go index 15561d9..de753e7 100644 --- a/pkg/search/search.go +++ b/pkg/search/search.go @@ -1,6 +1,7 @@ package search import ( + "context" "errors" "io" "io/fs" @@ -84,7 +85,7 @@ type Options struct { } // Search searches for packages in the database based on the given options. -func Search(opts Options) ([]Package, error) { +func Search(ctx context.Context, opts Options) ([]Package, error) { query := "(name LIKE ? OR description LIKE ? OR json_array_contains(provides, ?))" args := []any{"%" + opts.Query + "%", "%" + opts.Query + "%", opts.Query} @@ -113,7 +114,7 @@ func Search(opts Options) ([]Package, error) { query += " LIMIT " + strconv.FormatInt(opts.Limit, 10) } - result, err := db.GetPkgs(query, args...) + result, err := db.GetPkgs(ctx, query, args...) if err != nil { return nil, err } @@ -132,8 +133,8 @@ func Search(opts Options) ([]Package, error) { } // GetPkg gets a single package from the database and returns it. -func GetPkg(repo, name string) (Package, error) { - pkg, err := db.GetPkg("name = ? AND repository = ?", name, repo) +func GetPkg(ctx context.Context, repo, name string) (Package, error) { + pkg, err := db.GetPkg(ctx, "name = ? AND repository = ?", name, repo) return convertPkg(*pkg), err } @@ -148,12 +149,12 @@ var ( ) // GetScript returns a reader containing the build script for a given package. -func GetScript(repo, name string) (io.ReadCloser, error) { +func GetScript(ctx context.Context, repo, name string) (io.ReadCloser, error) { if strings.Contains(name, "./") || strings.ContainsAny(repo, "./") { return nil, ErrInvalidArgument } - scriptPath := filepath.Join(config.GetPaths().RepoDir, repo, name, "lure.sh") + scriptPath := filepath.Join(config.GetPaths(ctx).RepoDir, repo, name, "lure.sh") fl, err := os.Open(scriptPath) if errors.Is(err, fs.ErrNotExist) { return nil, ErrScriptNotFound