Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hashGlobs query to state service #3484

Merged
merged 16 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions cmd/state-svc/internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"os"
"path/filepath"
"runtime/debug"
"sort"
"strconv"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/graph"
"github.com/ActiveState/cli/internal/hash"
"github.com/ActiveState/cli/internal/logging"
configMediator "github.com/ActiveState/cli/internal/mediators/config"
"github.com/ActiveState/cli/internal/multilog"
Expand All @@ -36,6 +38,7 @@ type Resolver struct {
updatePoller *poller.Poller
authPoller *poller.Poller
projectIDCache *projectcache.ID
fileHasher *hash.FileHasher
an *sync.Client
anForClient *sync.Client // Use separate client for events sent through service so we don't contaminate one with the other
rtwatch *rtwatcher.Watcher
Expand Down Expand Up @@ -81,6 +84,7 @@ func New(cfg *config.Instance, an *sync.Client, auth *authentication.Auth) (*Res
pollUpdate,
pollAuth,
projectcache.NewID(),
hash.NewFileHasher(),
an,
anForClient,
rtwatcher.New(cfg, anForClient),
Expand Down Expand Up @@ -263,6 +267,8 @@ func (r *Resolver) GetProcessesInUse(ctx context.Context, execDir string) ([]*gr
}

func (r *Resolver) GetJwt(ctx context.Context) (*graph.Jwt, error) {
defer func() { handlePanics(recover(), debug.Stack()) }()

if err := r.auth.MaybeRenew(); err != nil {
return nil, errs.Wrap(err, "Could not renew auth token")
}
Expand Down Expand Up @@ -296,6 +302,21 @@ func (r *Resolver) GetJwt(ctx context.Context) (*graph.Jwt, error) {
return jwt, nil
}

func (r *Resolver) HashGlobs(ctx context.Context, globs []string) (string, error) {
defer func() { handlePanics(recover(), debug.Stack()) }()

var files []string
for _, glob := range globs {
matches, err := filepath.Glob(glob)
if err != nil {
return "", errs.Wrap(err, "Could not match glob: %s", glob)
}
files = append(files, matches...)
}

return r.fileHasher.HashFiles(files)
}

func handlePanics(recovered interface{}, stack []byte) {
if recovered != nil {
multilog.Error("Panic: %v", recovered)
Expand Down
Loading
Loading