]> Sergey Matveev's repositories - syncer.git/blobdiff - syncer.go
More descriptive installation instrustions
[syncer.git] / syncer.go
index 3d96ccd8e543fcebd3db5c1059a0da302e2c5a71..dc48314e044c0dbc731c0dd1bc414b097d9b7d28 100644 (file)
--- a/syncer.go
+++ b/syncer.go
@@ -1,6 +1,6 @@
 /*
 syncer -- stateful file/device data syncer.
-Copyright (C) 2015 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2015-2016 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -35,7 +35,7 @@ import (
 var (
        blkSize   = flag.Int64("blk", 2*1<<10, "Block size (KiB)")
        statePath = flag.String("state", "state.bin", "Path to statefile")
-       dstPath   = flag.String("dst", "/dev/ada0", "Path to destination disk")
+       dstPath   = flag.String("dst", "", "Path to destination disk")
        srcPath   = flag.String("src", "/dev/da0", "Path to source disk")
 )
 
@@ -45,15 +45,14 @@ type SyncEvent struct {
        data []byte
 }
 
-func prn(s string) {
-       os.Stdout.Write([]byte(s))
-       os.Stdout.Sync()
-}
-
 func main() {
        flag.Parse()
        bs := *blkSize * int64(1<<10)
 
+       if *dstPath == "" {
+               log.Fatalln("Not destination is specified")
+       }
+
        // Open source, calculate number of blocks
        var size int64
        src, err := os.Open(*srcPath)
@@ -151,7 +150,7 @@ func main() {
        syncs := make(chan chan SyncEvent, workers)
 
        // Writer
-       prn("[")
+       prn := NewPrinter(blocks)
        finished := make(chan struct{})
        go func() {
                var event SyncEvent
@@ -184,10 +183,10 @@ func main() {
                        sumState := state[i*blake2b.Size : i*blake2b.Size+blake2b.Size]
                        if bytes.Compare(sumState, sum[:]) != 0 {
                                sync <- SyncEvent{i, buf, buf[:n]}
-                               prn("%")
+                               prn.Changed()
                        } else {
                                sync <- SyncEvent{i, buf, nil}
-                               prn(".")
+                               prn.Unchanged()
                        }
                        copy(sumState, sum[:])
                        close(sync)
@@ -195,7 +194,7 @@ func main() {
        }
        close(syncs)
        <-finished
-       prn("]\n")
+       prn.Output()
 
        log.Println("Saving state")
        stateFile.Write(state)