]> Sergey Matveev's repositories - sgodup.git/blobdiff - main.go
Read NS from stdin for convenience
[sgodup.git] / main.go
diff --git a/main.go b/main.go
index 9c5382ce03f79d536422e03e383a7c403cfe6faa..e9fcf7ea1a1e50906f976b3c7fbfe55b53e519e2 100644 (file)
--- a/main.go
+++ b/main.go
@@ -39,7 +39,7 @@ import (
 )
 
 const (
-       Version    = "0.1.0"
+       Version    = "0.2.0"
        SectorSize = 1 << 12 // 4 KiB sector size
        BufSize    = 1 << 17 // ZFS default 128 KiB recordsize
 
@@ -63,7 +63,7 @@ var (
        actionS  = flag.String("action", "", "print, ns, symlink, hardlink")
        minSize  = flag.Int64("minsize", 1, "minimal file size")
        chmod    = flag.String("chmod", "", "chmod files")
-       nsPath   = flag.String("ns", "", "link targets from netstring file")
+       doNS     = flag.Bool("ns", false, "link targets from netstring read from stdin")
        fsync    = flag.Bool("fsync", false, "fsync directories?")
        version  = flag.Bool("version", false, "Print version information")
        warranty = flag.Bool("warranty", false, "Print warranty information")
@@ -142,7 +142,7 @@ Single pass mode:
     [-chmod XXX] [-minsize XXX] [-fsync]
 Two pass mode:
   %s -basedir DIR -dupdir DIR -action ns [-chmod XXX] [-minsize XXX] > state
-  %s -action {print,symlink,hardlink} [-fsync] -ns state
+  %s -action {print,symlink,hardlink} [-fsync] -ns state
 
 Options:
 `, os.Args[0], os.Args[0], os.Args[0])
@@ -184,17 +184,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.`)
                log.Fatalln("invalid action")
        }
 
-       if *nsPath != "" {
+       if *doNS {
                if action == ActNS {
                        log.Fatalln("\"-action ns\" has no meaning with -ns")
                }
-               fd, err := os.Open(*nsPath)
-               if err != nil {
-                       log.Fatal(err)
-               }
-               nsR := netstring.NewReader(bufio.NewReaderSize(fd, BufSize))
+               nsR := netstring.NewReader(bufio.NewReaderSize(os.Stdin, BufSize))
                pathDup := make([]byte, 1<<10)
                pathOrig := make([]byte, 1<<10)
+               var err error
                var pathDupLen, pathOrigLen uint64
                files := 0
                fullSize := int64(0)