Skip to content

Commit

Permalink
Add hashGlobs query to state service
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Sep 9, 2024
1 parent 89d51c3 commit 519d304
Show file tree
Hide file tree
Showing 302 changed files with 39,895 additions and 7,818 deletions.
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

0 comments on commit 519d304

Please sign in to comment.