mirror of
https://github.com/go-task/task.git
synced 2025-02-03 13:22:11 +02:00
Post-fixes to #211
This commit is contained in:
parent
b66bf58064
commit
fe2b8c8afa
@ -1,5 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Create directory informed on `dir:` if it doesn't exist
|
||||
([#209](https://github.com/go-task/task/issues/209), [#211](https://github.com/go-task/task/pull/211)).
|
||||
|
||||
## v2.5.2 - 2019-05-11
|
||||
|
||||
- Reverted YAML upgrade due issues with CRLF on Windows
|
||||
|
@ -1,8 +1,5 @@
|
||||
package taskfile
|
||||
|
||||
import "os"
|
||||
import "sync"
|
||||
|
||||
// Tasks represents a group of tasks
|
||||
type Tasks map[string]*Task
|
||||
|
||||
@ -17,7 +14,6 @@ type Task struct {
|
||||
Generates []string
|
||||
Status []string
|
||||
Dir string
|
||||
mkdirMutex sync.Mutex
|
||||
Vars Vars
|
||||
Env Vars
|
||||
Silent bool
|
||||
@ -25,22 +21,3 @@ type Task struct {
|
||||
Prefix string
|
||||
IgnoreError bool `yaml:"ignore_error"`
|
||||
}
|
||||
|
||||
// Mkdir creates the directory Task.Dir.
|
||||
// Safe to be called concurrently.
|
||||
func (t *Task) Mkdir() error {
|
||||
if t.Dir == "" {
|
||||
// No "dir:" attribute, so we do nothing.
|
||||
return nil
|
||||
}
|
||||
|
||||
t.mkdirMutex.Lock()
|
||||
defer t.mkdirMutex.Unlock()
|
||||
|
||||
if _, err := os.Stat(t.Dir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(t.Dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
25
task.go
25
task.go
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/go-task/task/v2/internal/compiler"
|
||||
@ -51,6 +52,7 @@ type Executor struct {
|
||||
taskvars taskfile.Vars
|
||||
|
||||
taskCallCount map[string]*int32
|
||||
mkdirMutexMap map[string]*sync.Mutex
|
||||
}
|
||||
|
||||
// Run runs Task
|
||||
@ -167,8 +169,10 @@ func (e *Executor) Setup() error {
|
||||
}
|
||||
|
||||
e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks))
|
||||
e.mkdirMutexMap = make(map[string]*sync.Mutex, len(e.Taskfile.Tasks))
|
||||
for k := range e.Taskfile.Tasks {
|
||||
e.taskCallCount[k] = new(int32)
|
||||
e.mkdirMutexMap[k] = &sync.Mutex{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -200,9 +204,7 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
||||
}
|
||||
}
|
||||
|
||||
// When using the "dir:" attribute it can happen that the directory doesn't exist.
|
||||
// If so, we create it.
|
||||
if err := t.Mkdir(); err != nil {
|
||||
if err := e.mkdir(t); err != nil {
|
||||
e.Logger.Errf("task: cannot make directory %q: %v", t.Dir, err)
|
||||
}
|
||||
|
||||
@ -223,6 +225,23 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Executor) mkdir(t *taskfile.Task) error {
|
||||
if t.Dir == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
mutex := e.mkdirMutexMap[t.Task]
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
if _, err := os.Stat(t.Dir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(t.Dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Executor) runDeps(ctx context.Context, t *taskfile.Task) error {
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user