diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-05-05 17:11:54 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-05-05 17:11:54 +0200 |
commit | 652b7a3d5a5428d5ee152c7aacabe9fad15d3806 (patch) | |
tree | 7ab61e1d6ee892fc6a13ebf86e7df4be5e4b8677 /skate | |
parent | c801b2ff0aa93489eed89ddb1f2d62404fc89ca2 (diff) | |
download | refcat-652b7a3d5a5428d5ee152c7aacabe9fad15d3806.tar.gz refcat-652b7a3d5a5428d5ee152c7aacabe9fad15d3806.zip |
skate-verify: tweaks
Diffstat (limited to 'skate')
-rw-r--r-- | skate/cmd/skate-verify/main.go | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/skate/cmd/skate-verify/main.go b/skate/cmd/skate-verify/main.go index 895d508..ab198fd 100644 --- a/skate/cmd/skate-verify/main.go +++ b/skate/cmd/skate-verify/main.go @@ -10,6 +10,7 @@ package main import ( "bufio" "flag" + "io" "log" "os" "runtime" @@ -52,6 +53,12 @@ func main() { pprof.StartCPUProfile(file) defer pprof.StopCPUProfile() } + var ( + f, g io.ReadCloser + err error + bw = bufio.NewWriter(os.Stdout) + ) + defer bw.Flush() switch *mode { case "exact": // Fixed zip mode for DOI. @@ -65,18 +72,11 @@ func main() { } log.Fatalf("need a reason for the record, one of: %s", strings.Join(keys, ", ")) } - f, err := os.Open(*releasesFile) - if err != nil { + if f, g, err = readersFromFilenames(*releasesFile, *refsFile); err != nil { log.Fatal(err) } defer f.Close() - g, err := os.Open(*refsFile) - if err != nil { - log.Fatal(err) - } defer g.Close() - bw := bufio.NewWriter(os.Stdout) - defer bw.Flush() mr, ok := matchResults[*exactReason] if !ok { mr = matchResults["unknown"] @@ -90,18 +90,11 @@ func main() { if *refsFile == "" || *releasesFile == "" { log.Fatal("zip mode requires -F and -R to be set") } - f, err := os.Open(*releasesFile) - if err != nil { + if f, g, err = readersFromFilenames(*releasesFile, *refsFile); err != nil { log.Fatal(err) } defer f.Close() - g, err := os.Open(*refsFile) - if err != nil { - log.Fatal(err) - } defer g.Close() - bw := bufio.NewWriter(os.Stdout) - defer bw.Flush() if err := skate.ZippyVerifyRefs(f, g, bw); err != nil { log.Fatal(err) } @@ -126,23 +119,16 @@ func main() { if *wikiFile == "" || *releasesFile == "" { log.Fatal("mode requires -W and -F to be set") } - f, err := os.Open(*releasesFile) - if err != nil { + if f, g, err = readersFromFilenames(*releasesFile, *wikiFile); err != nil { log.Fatal(err) } defer f.Close() - g, err := os.Open(*wikiFile) - if err != nil { - log.Fatal(err) - } defer g.Close() - bw := bufio.NewWriter(os.Stdout) - defer bw.Flush() - if err := skate.ZippyFixedWiki(f, g, skate.MatchResult{skate.StatusExact, skate.ReasonDOI}, "wiki", bw); err != nil { + if err = skate.ZippyFixedWiki(f, g, skate.MatchResult{skate.StatusExact, skate.ReasonDOI}, "wiki", bw); err != nil { log.Fatal(err) } default: - log.Fatal("not implemented, only: zip, ref, bref") + log.Fatal("not implemented, only: exact, zip, ref, bref, wiki") } if *memProfile != "" { f, err := os.Create(*memProfile) @@ -156,3 +142,16 @@ func main() { } } } + +// readersFromFilenames lets the called check for a single error only. +func readersFromFilenames(f0, f1 string) (io.ReadCloser, io.ReadCloser, error) { + f, err := os.Open(f0) + if err != nil { + return nil, nil, err + } + g, err := os.Open(f1) + if err != nil { + return nil, nil, err + } + return f, g, nil +} |