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"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -110,6 +111,22 @@ func (instruction *LinkInstruction) RunAsync(status chan (error)) {
|
||||
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 {
|
||||
log.Printf("Removing symlink at %s%s%s", TargetColor, instruction.Target, DefaultColor)
|
||||
err = os.Remove(instruction.Target)
|
||||
|
Reference in New Issue
Block a user