Always copy source directory contents, not the directory itself
This commit is contained in:
@@ -69,15 +69,28 @@ func (r *RsyncRunner) buildArgs(pair *SyncPairConfig) []string {
|
||||
args = append(args, "--delete")
|
||||
}
|
||||
|
||||
src := ensureDirSlash(pair.Source)
|
||||
if pair.Direction == "pull" {
|
||||
args = append(args, pair.Dest, pair.Source)
|
||||
args = append(args, pair.Dest, src)
|
||||
} else {
|
||||
args = append(args, pair.Source, pair.Dest)
|
||||
args = append(args, src, pair.Dest)
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
// ensureDirSlash guarantees the source path is treated by rsync as a
|
||||
// directory whose contents are copied, regardless of whether the user
|
||||
// supplied a trailing slash. This avoids the common foot-gun where
|
||||
// "rsync host:/path/series /dest/" creates /dest/series/<contents> nested
|
||||
// inside an extra "series" subdirectory.
|
||||
func ensureDirSlash(p string) string {
|
||||
if strings.HasSuffix(p, "/") {
|
||||
return p
|
||||
}
|
||||
return p + "/"
|
||||
}
|
||||
|
||||
type MachineKeys struct {
|
||||
Host string
|
||||
Port int
|
||||
|
||||
Reference in New Issue
Block a user