From 30c59bf3877cf561c54c2efaf6da042a2051bee7 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Tue, 24 Sep 2024 13:21:09 -0400 Subject: [PATCH] fix(remote): wait for prompt in the reader (#1833) --- taskfile/reader.go | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/taskfile/reader.go b/taskfile/reader.go index 1f1fefe2..c64f35b1 100644 --- a/taskfile/reader.go +++ b/taskfile/reader.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "sync" "time" "github.com/dominikbraun/graph" @@ -30,14 +31,15 @@ Continue?` // A Reader will recursively read Taskfiles from a given source using a directed // acyclic graph (DAG). type Reader struct { - graph *ast.TaskfileGraph - node Node - insecure bool - download bool - offline bool - timeout time.Duration - tempDir string - logger *logger.Logger + graph *ast.TaskfileGraph + node Node + insecure bool + download bool + offline bool + timeout time.Duration + tempDir string + logger *logger.Logger + promptMutex sync.Mutex } func NewReader( @@ -50,14 +52,15 @@ func NewReader( logger *logger.Logger, ) *Reader { return &Reader{ - graph: ast.NewTaskfileGraph(), - node: node, - insecure: insecure, - download: download, - offline: offline, - timeout: timeout, - tempDir: tempDir, - logger: logger, + graph: ast.NewTaskfileGraph(), + node: node, + insecure: insecure, + download: download, + offline: offline, + timeout: timeout, + tempDir: tempDir, + logger: logger, + promptMutex: sync.Mutex{}, } } @@ -244,12 +247,16 @@ func (r *Reader) readNode(node Node) (*ast.Taskfile, error) { // If there is a cached hash, but it doesn't match the expected hash, prompt the user to continue prompt = fmt.Sprintf(taskfileChangedPrompt, node.Location()) } + if prompt != "" { - if err := r.logger.Prompt(logger.Yellow, prompt, "n", "y", "yes"); err != nil { + if err := func() error { + r.promptMutex.Lock() + defer r.promptMutex.Unlock() + return r.logger.Prompt(logger.Yellow, prompt, "n", "y", "yes") + }(); err != nil { return nil, &errors.TaskfileNotTrustedError{URI: node.Location()} } } - // If the hash has changed (or is new) if checksum != cachedChecksum { // Store the checksum