Skip to content

Commit 65d9d5a

Browse files
committed
repeat sync
1 parent ad472ce commit 65d9d5a

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

main.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/signal"
99
"path/filepath"
1010
"syscall"
11+
"time"
1112

1213
"github.com/adrg/xdg"
1314
"github.com/cenkalti/log"
@@ -19,8 +20,6 @@ import (
1920
// "0.0.0" is the development version.
2021
var Version = "0.0.0"
2122

22-
// TODO Reconciliation tests
23-
// TODO Daemon mode
2423
// TODO HTTP API
2524

2625
var (
@@ -30,6 +29,7 @@ var (
3029
username = flag.String("username", "", "put.io account username")
3130
password = flag.String("password", "", "put.io account password")
3231
dryrun = flag.Bool("dryrun", false, "do not make changes on filesystems")
32+
repeat = flag.Duration("repeat", 0, "sync repeatedly, pause given duration between syncs")
3333
)
3434

3535
var (
@@ -101,11 +101,25 @@ func main() {
101101
log.Noticef("Received %s. Stopping sync.", sig)
102102
cancel()
103103
}()
104-
err = syncOnce(ctx)
105-
if err != nil {
106-
log.Fatal(err)
104+
for {
105+
err = syncOnce(ctx)
106+
if err != nil {
107+
if *repeat == 0 {
108+
log.Fatal(err)
109+
}
110+
log.Error(err)
111+
} else {
112+
log.Infoln("Sync finished successfully")
113+
}
114+
if *repeat == 0 {
115+
break
116+
}
117+
select {
118+
case <-time.After(*repeat):
119+
case <-ctx.Done():
120+
return
121+
}
107122
}
108-
log.Infoln("Sync finished")
109123
}
110124

111125
func syncOnce(ctx context.Context) error {

0 commit comments

Comments
 (0)