Ensure target exists by creating directories
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -122,7 +122,7 @@ func (instruction *LinkInstruction) RunAsync(status chan (error)) {
|
||||
status <- fmt.Errorf("could not stat %s%s%s, stopping; err: %s%+v%s", TargetColor, instruction.Target, DefaultColor, ErrorColor, err, DefaultColor)
|
||||
return
|
||||
}
|
||||
if info.Mode().IsRegular() && info.Name() == path.Base(instruction.Source) {
|
||||
if info.Mode().IsRegular() && info.Name() == filepath.Base(instruction.Source) {
|
||||
log.Printf("Overwriting existing file %s%s%s", TargetColor, instruction.Target, DefaultColor)
|
||||
err := os.Remove(instruction.Target)
|
||||
if err != nil {
|
||||
@@ -149,6 +149,15 @@ func (instruction *LinkInstruction) RunAsync(status chan (error)) {
|
||||
}
|
||||
}
|
||||
|
||||
targetDir := filepath.Dir(instruction.Target)
|
||||
if _, err := os.Stat(targetDir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(targetDir, 0755)
|
||||
if err != nil {
|
||||
status <- fmt.Errorf("failed creating directory %s%s%s due to %s%+v%s", TargetColor, targetDir, DefaultColor, ErrorColor, err, DefaultColor)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
if instruction.Hard {
|
||||
err = os.Link(instruction.Source, instruction.Target)
|
||||
|
Reference in New Issue
Block a user