From 6771d91a1765443dcad494a879b2394e981e0ca1 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 22 Mar 2020 21:28:51 +0300 Subject: [PATCH] Read NS from stdin for convenience --- README | 2 +- main.go | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README b/README index f8b2b8a..56beec9 100644 --- a/README +++ b/README @@ -68,7 +68,7 @@ TWO PASS MODE ============= $ sgodup -basedir DIR -dupdir DIR -action ns [-minsize NNN] [-chmod NNN] > state -$ sgodup -action ACTION [-fsync] -ns state +$ sgodup -action ACTION [-fsync] -ns < state If you are dealing with huge amount of small files, then simultaneous reading (duplicate detection) and writing (duplicate files linking) on diff --git a/main.go b/main.go index 9c5382c..e9fcf7e 100644 --- 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 .`) 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) -- 2.44.0