]> Sergey Matveev's repositories - sgodup.git/commitdiff
Read NS from stdin for convenience v0.2.0
authorSergey Matveev <stargrave@stargrave.org>
Sun, 22 Mar 2020 18:28:51 +0000 (21:28 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 22 Mar 2020 18:28:51 +0000 (21:28 +0300)
README
main.go

diff --git a/README b/README
index f8b2b8a7b0eafc769c8e661a228126600c99e42f..56beec94e99a44c33ef68a54f9e3b1461720471b 100644 (file)
--- a/README
+++ b/README
@@ -68,7 +68,7 @@ TWO PASS MODE
 =============
 
 $ sgodup -basedir DIR -dupdir DIR -action ns [-minsize NNN] [-chmod NNN] > state
 =============
 
 $ 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
 
 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 9c5382ce03f79d536422e03e383a7c403cfe6faa..e9fcf7ea1a1e50906f976b3c7fbfe55b53e519e2 100644 (file)
--- a/main.go
+++ b/main.go
@@ -39,7 +39,7 @@ import (
 )
 
 const (
 )
 
 const (
-       Version    = "0.1.0"
+       Version    = "0.2.0"
        SectorSize = 1 << 12 // 4 KiB sector size
        BufSize    = 1 << 17 // ZFS default 128 KiB recordsize
 
        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")
        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")
        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
     [-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])
 
 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")
        }
 
                log.Fatalln("invalid action")
        }
 
-       if *nsPath != "" {
+       if *doNS {
                if action == ActNS {
                        log.Fatalln("\"-action ns\" has no meaning with -ns")
                }
                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)
                pathDup := make([]byte, 1<<10)
                pathOrig := make([]byte, 1<<10)
+               var err error
                var pathDupLen, pathOrigLen uint64
                files := 0
                fullSize := int64(0)
                var pathDupLen, pathOrigLen uint64
                files := 0
                fullSize := int64(0)