1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
)
var (
hostDir = flag.String("host", "/host", "Host source directory (read-only)")
dataDir = flag.String("data", "/data", "Data destination directory")
verbose = flag.Bool("verbose", false, "Enable verbose logging")
dryRun = flag.Bool("dry-run", false, "Preview what would be synced without copying")
)
func main() {
flag.Parse()
log.SetFlags(log.LstdFlags | log.Lshortfile)
if *verbose {
log.Println("sourcewatch starting...")
log.Printf("host: %s, data: %s, dry-run: %v", *hostDir, *dataDir, *dryRun)
}
stack := NewGitignoreStack(*hostDir)
manifest, err := initialSync(*hostDir, *dataDir, stack, *dryRun)
if err != nil {
log.Fatalf("initial sync failed: %v", err)
}
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
if err := watch(ctx, *hostDir, *dataDir, manifest, stack, *dryRun, *verbose); err != nil {
log.Fatalf("watcher failed: %v", err)
}
}
|