Skip to content

Commit 00fdbc3

Browse files
committed
add syncing handler
1 parent 6942259 commit 00fdbc3

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package putiosync
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"time"
78

@@ -21,6 +22,7 @@ type httpServer struct {
2122
func newServer(addr string) *httpServer {
2223
m := http.NewServeMux()
2324
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("putio-sync")) })
25+
m.HandleFunc("/syncing", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(fmt.Sprintf("%v", syncing))) })
2426
s := &httpServer{
2527
srv: &http.Server{
2628
Addr: addr,

sync.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
dirCache *dircache.DirCache
3434
tempDirPath string
3535
uploader *tus.Uploader
36+
syncing bool
3637
)
3738

3839
func Sync(ctx context.Context, config Config) error {
@@ -161,6 +162,8 @@ func syncRoots(ctx context.Context) error {
161162
log.Infoln("No changes detected")
162163
return nil
163164
}
165+
syncing = true
166+
defer func() { syncing = false }()
164167
for _, job := range jobs {
165168
log.Infoln(job.String())
166169
if cfg.DryRun {

0 commit comments

Comments
 (0)