Add support for hard links

This commit is contained in:
2024-08-15 22:44:03 +02:00
parent 595a11552c
commit b8e7bc3576
2 changed files with 9 additions and 1 deletions

View File

@@ -122,7 +122,12 @@ func (instruction *LinkInstruction) RunAsync(status chan (error)) {
} }
} }
err := os.Symlink(instruction.Source, instruction.Target) var err error
if *hard {
err = os.Link(instruction.Source, instruction.Target)
} else {
err = os.Symlink(instruction.Source, instruction.Target)
}
if err != nil { if err != nil {
status <- fmt.Errorf("failed creating symlink between %s%s%s and %s%s%s with error %s%+v%s", SourceColor, instruction.Source, DefaultColor, TargetColor, instruction.Target, DefaultColor, ErrorColor, err, DefaultColor) status <- fmt.Errorf("failed creating symlink between %s%s%s and %s%s%s with error %s%+v%s", SourceColor, instruction.Source, DefaultColor, TargetColor, instruction.Target, DefaultColor, ErrorColor, err, DefaultColor)
return return

View File

@@ -32,10 +32,13 @@ var DirRegex, _ = regexp.Compile(`^(.+?)[/\\]sync$`)
var FileRegex, _ = regexp.Compile(`^sync$`) var FileRegex, _ = regexp.Compile(`^sync$`)
var programName = os.Args[0] var programName = os.Args[0]
var hard *bool
func main() { func main() {
recurse := flag.String("r", "", "recurse into directories") recurse := flag.String("r", "", "recurse into directories")
file := flag.String("f", "", "file to read instructions from") file := flag.String("f", "", "file to read instructions from")
debug := flag.Bool("d", false, "debug") debug := flag.Bool("d", false, "debug")
hard = flag.Bool("h", false, "create hard links instead")
flag.Parse() flag.Parse()
if *debug { if *debug {