Skip to content

Commit

Permalink
job/task: Check if allowed to override or fail
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk>
  • Loading branch information
nderjung committed Dec 23, 2020
1 parent 835998c commit 5e09a97
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion job/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,19 @@ func (t *Task) Init(workDir string, allowOverride bool, runs *[]Run) error {
// Create a queue of runs for this particular task
t.runs = NewQueue(len(*runs))

// Create a working directory for this task
// Set the working directory
t.workDir = path.Join(workDir, "results", t.UUID())

// Check if we're allowed to override a non-empty directory
isEmpty, err := IsDirEmpty(t.workDir)
if err != nil {
return err
}
if !isEmpty && !allowOverride {
return fmt.Errorf("Task directory not empty: %s", t.workDir)
}

// Create a working directory for this task
if _, err := os.Stat(t.workDir); os.IsNotExist(err) {
os.MkdirAll(workDir, os.ModePerm)
}
Expand Down

0 comments on commit 5e09a97

Please sign in to comment.