Make forced hard links overwrite target if it has the same name as source
Or something like that... Maybe...
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -110,6 +111,22 @@ func (instruction *LinkInstruction) RunAsync(status chan (error)) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if instruction.Hard {
|
||||||
|
info, err := os.Stat(instruction.Target)
|
||||||
|
if err != nil {
|
||||||
|
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) {
|
||||||
|
log.Printf("Overwriting existing file %s%s%s", TargetColor, instruction.Target, DefaultColor)
|
||||||
|
err := os.Remove(instruction.Target)
|
||||||
|
if err != nil {
|
||||||
|
status <- fmt.Errorf("could not remove existing file %s%s%s; err: %s%+v%s", TargetColor, instruction.Target, DefaultColor, ErrorColor, err, DefaultColor)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if isSymlink {
|
if isSymlink {
|
||||||
log.Printf("Removing symlink at %s%s%s", TargetColor, instruction.Target, DefaultColor)
|
log.Printf("Removing symlink at %s%s%s", TargetColor, instruction.Target, DefaultColor)
|
||||||
err = os.Remove(instruction.Target)
|
err = os.Remove(instruction.Target)
|
||||||
|
Reference in New Issue
Block a user