Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
Invert parameter keepLocal into removeLocal to keep local files
Browse files Browse the repository at this point in the history
  • Loading branch information
wilriker committed May 28, 2019
1 parent c9a72e8 commit 5808e69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Usage of ./duetbackup:
Directory on Duet to create a backup of (default "0:/sys")
-domain string
Domain of Duet Wifi
-keepLocal
Keep files locally that have been deleted on the Duet
-outDir string
Output dir of backup
-password string
Connection password (default "reprap")
-port uint
Port of Duet Wifi (default 80)
-removeLocal
Remove files locally that have been deleted on the Duet
```
16 changes: 8 additions & 8 deletions duetbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func getFileList(baseURL string, dir string, first uint64) (*filelist, error) {
return &fl, nil
}

func updateLocalFiles(baseURL string, fl *filelist, outDir string, keepLocal bool) error {
func updateLocalFiles(baseURL string, fl *filelist, outDir string, removeLocal bool) error {

fileDownloadURL := "rr_download?name=" + url.QueryEscape(fl.Dir+"/")

Expand All @@ -138,7 +138,7 @@ func updateLocalFiles(baseURL string, fl *filelist, outDir string, keepLocal boo
}

// Go recursively into this directory
if err = syncFolder(baseURL, fl.Dir+"/"+file.Name, fileName, keepLocal); err != nil {
if err = syncFolder(baseURL, fl.Dir+"/"+file.Name, fileName, removeLocal); err != nil {
return err
}
continue
Expand Down Expand Up @@ -212,19 +212,19 @@ func removeDeletedFiles(fl *filelist, outDir string) error {
return nil
}

func syncFolder(address, folder, outDir string, keepLocal bool) error {
func syncFolder(address, folder, outDir string, removeLocal bool) error {
log.Println("Fetching filelist for", folder)
fl, err := getFileList(address, url.QueryEscape(folder), 0)
if err != nil {
return err
}

log.Println("Checking files to be downloaded from", folder)
if err = updateLocalFiles(address, fl, outDir, keepLocal); err != nil {
if err = updateLocalFiles(address, fl, outDir, removeLocal); err != nil {
return err
}

if !keepLocal {
if removeLocal {
log.Println("Checking no longer existing files in", outDir)
if err = removeDeletedFiles(fl, outDir); err != nil {
return err
Expand All @@ -246,15 +246,15 @@ func connect(address, password string) error {

func main() {
var domain, dirToBackup, outDir, password string
var keepLocal bool
var removeLocal bool
var port uint64

flag.StringVar(&domain, "domain", "", "Domain of Duet Wifi")
flag.Uint64Var(&port, "port", 80, "Port of Duet Wifi")
flag.StringVar(&dirToBackup, "dirToBackup", sysDir, "Directory on Duet to create a backup of")
flag.StringVar(&outDir, "outDir", "", "Output dir of backup")
flag.StringVar(&password, "password", "reprap", "Connection password")
flag.BoolVar(&keepLocal, "keepLocal", false, "Keep files locally that have been deleted on the Duet")
flag.BoolVar(&removeLocal, "removeLocal", false, "Remove files locally that have been deleted on the Duet")
flag.Parse()

if domain == "" || outDir == "" {
Expand All @@ -270,7 +270,7 @@ func main() {
os.Exit(0)
}

err := syncFolder(address, dirToBackup, outDir, keepLocal)
err := syncFolder(address, dirToBackup, outDir, removeLocal)
if err != nil {
log.Fatal(err)
os.Exit(1)
Expand Down

0 comments on commit 5808e69

Please sign in to comment.