Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Add --nodelete argument #23

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
var verbose = flag.Bool("verbose", false, "Verbose output")
var srcpath = flag.String("src", pwd, "Source directory")
var dstpath = flag.String("dst", pathpkg.Join("/rsync", pwd), "Destination directory")
var nodelete = flag.Bool("nodelete", false, "Don't delete pre-existing files in destination")

flag.Parse()

Expand Down Expand Up @@ -62,12 +63,12 @@ func main() {
rsyncEndpoint := via

fmt.Printf("Syncing %s (local) to %s (%s)\n", *srcpath, *dstpath, rsyncEndpoint)
Sync(rsyncEndpoint, SSHCredentials{}, rpath, rpathDir, *verbose) // initial sync
Sync(rsyncEndpoint, SSHCredentials{}, rpath, rpathDir, *nodelete, *verbose) // initial sync

if *watch {
fmt.Println("Watching for file changes ...")
Watch(rpath, func(id uint64, path string, flags []string) {
Sync(rsyncEndpoint, SSHCredentials{}, rpath, rpathDir, *verbose)
Sync(rsyncEndpoint, SSHCredentials{}, rpath, rpathDir, *nodelete, *verbose)
})
}

Expand All @@ -83,13 +84,18 @@ func main() {

Provision(machineName, *verbose)
RunSSHCommand(machineName, "sudo mkdir -p "+rpathDir, *verbose)
fmt.Printf("Syncing %s (local) to %s (docker-machine %s)\n", *srcpath, *dstpath, machineName)
Sync(machineName, c, rpath, rpathDir, *verbose) // initial sync
if *nodelete {
fmt.Printf("Copying")
} else {
fmt.Printf("Syncing")
}
fmt.Printf(" %s (local) to %s (docker-machine %s)\n", *srcpath, *dstpath, machineName)
Sync(machineName, c, rpath, rpathDir, *nodelete, *verbose) // initial sync

if *watch {
fmt.Println("Watching for file changes ...")
Watch(rpath, func(id uint64, path string, flags []string) {
Sync(machineName, c, rpath, rpathDir, *verbose)
Sync(machineName, c, rpath, rpathDir, *nodelete, *verbose)
})
}
}
Expand Down
7 changes: 5 additions & 2 deletions rsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var lastSyncError = ""

func Sync(via string, c SSHCredentials, src, dst string, verbose bool) {
func Sync(via string, c SSHCredentials, src, dst string, nodelete bool, verbose bool) {
args := []string{
// "--verbose",
// "--stats",
Expand All @@ -19,7 +19,6 @@ func Sync(via string, c SSHCredentials, src, dst string, verbose bool) {
"--times",
"--inplace",
"--itemize-changes",
"--delete",
"--force",
"--executability",
"--compress",
Expand All @@ -39,6 +38,10 @@ func Sync(via string, c SSHCredentials, src, dst string, verbose bool) {
args = append(args, src, fmt.Sprintf("%s@%s:%s", c.SSHUser, c.IPAddress, dst))
}

if ! nodelete {
args = append(args, "--delete")
}

cmd := Exec("rsync", args...)

if verbose {
Expand Down