Skip to content

Commit

Permalink
job/task: Fix directory creation logic
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 3029940 commit 31b516e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions job/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,24 @@ func (t *Task) Init(workDir string, allowOverride bool, runs *[]Run) error {
// 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)
}
// Set additional task configuration
t.AllowOverride = allowOverride

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

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

os.MkdirAll(workDir, os.ModePerm)
}

// Add the runs in-order
Expand Down

0 comments on commit 31b516e

Please sign in to comment.