mv into func
parent
8185311a4f
commit
6af1f231df
32
main.go
32
main.go
|
|
@ -56,20 +56,7 @@ func Main(ctx context.Context) error {
|
|||
|
||||
mvNLn := RealMvNLn
|
||||
if *dry {
|
||||
outd := map[string]struct{}{}
|
||||
mvNLn = func(outf, inf string) error {
|
||||
if _, err := os.Stat(outf); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, ok := outd[outf]; ok {
|
||||
return nil
|
||||
}
|
||||
outd[outf] = struct{}{}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "mv %q %q\n", inf, outf)
|
||||
return nil
|
||||
}
|
||||
mvNLn = DryMvNLn()
|
||||
}
|
||||
|
||||
return Run(ctx,
|
||||
|
|
@ -151,3 +138,20 @@ func RealMvNLn(outf, inf string) error {
|
|||
}
|
||||
return os.Symlink(outf, inf)
|
||||
}
|
||||
|
||||
func DryMvNLn() func(string, string) error {
|
||||
outd := map[string]struct{}{}
|
||||
return func(outf, inf string) error {
|
||||
if _, err := os.Stat(outf); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, ok := outd[outf]; ok {
|
||||
return nil
|
||||
}
|
||||
outd[outf] = struct{}{}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "mv %q %q\n", inf, outf)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue