From 273ca9cd7538930930816d195c040bb1c6fb7697 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sun, 24 Dec 2023 15:16:36 +0100 Subject: [PATCH 1/4] Sync counters on read/write error (incl io.EOF) --- cmd/catp/catp/app.go | 2 -- progress.go | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/catp/catp/app.go b/cmd/catp/catp/app.go index f69882f..a7e0820 100644 --- a/cmd/catp/catp/app.go +++ b/cmd/catp/catp/app.go @@ -285,8 +285,6 @@ func (r *runner) cat(filename string) (err error) { r.readFile(rd, out) } - cr.Close() - if r.parallel <= 1 { r.pr.Stop() } diff --git a/progress.go b/progress.go index 6de875e..f66c522 100644 --- a/progress.go +++ b/progress.go @@ -277,10 +277,10 @@ func (cr *sharedCounters) SetBytes(bytes *int64) { cr.bytes = bytes } -func (cr *sharedCounters) count(n int, p []byte) { +func (cr *sharedCounters) count(n int, p []byte, err error) { cr.localBytes += int64(n) - if cr.localBytes > 100000 && cr.bytes != nil { + if (err != nil || cr.localBytes > 100000) && cr.bytes != nil { atomic.AddInt64(cr.bytes, cr.localBytes) cr.localBytes = 0 } @@ -293,7 +293,7 @@ func (cr *sharedCounters) count(n int, p []byte) { if p[i] == '\n' { cr.localLines++ - if cr.localLines > 1000 { + if err != nil || cr.localLines > 1000 { atomic.AddInt64(cr.lines, cr.localLines) cr.localLines = 0 } @@ -304,7 +304,7 @@ func (cr *sharedCounters) count(n int, p []byte) { // Read reads and counts bytes. func (cr *CountingReader) Read(p []byte) (n int, err error) { n, err = cr.Reader.Read(p) - cr.count(n, p) + cr.count(n, p, err) return n, err } @@ -349,7 +349,7 @@ type CountingWriter struct { // Write writes and counts bytes. func (cr *CountingWriter) Write(p []byte) (n int, err error) { n, err = cr.Writer.Write(p) - cr.count(n, p) + cr.count(n, p, err) return n, err } From ae0cc72f996e4959ad639b6c593121f02887c856 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sun, 24 Dec 2023 15:22:09 +0100 Subject: [PATCH 2/4] Sync counters on read/write error (incl io.EOF) --- .github/workflows/release-assets.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml index 515af94..d510ad2 100644 --- a/.github/workflows/release-assets.yml +++ b/.github/workflows/release-assets.yml @@ -34,6 +34,7 @@ jobs: uses: actions/checkout@v3 - name: Build artifacts run: | + git fetch -t make release-assets - name: Upload linux_amd64.tar.gz if: hashFiles('linux_amd64.tar.gz') != '' From 6de27188666e02651e091e0a0c801007b1e67a24 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sun, 24 Dec 2023 15:30:49 +0100 Subject: [PATCH 3/4] Fix lines syncer --- progress.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/progress.go b/progress.go index f66c522..b5d5649 100644 --- a/progress.go +++ b/progress.go @@ -292,13 +292,13 @@ func (cr *sharedCounters) count(n int, p []byte, err error) { for i := 0; i < n; i++ { if p[i] == '\n' { cr.localLines++ - - if err != nil || cr.localLines > 1000 { - atomic.AddInt64(cr.lines, cr.localLines) - cr.localLines = 0 - } } } + + if err != nil || cr.localLines > 1000 { + atomic.AddInt64(cr.lines, cr.localLines) + cr.localLines = 0 + } } // Read reads and counts bytes. From 8f714ff559c6e1066705f4c291601ad0229d4af7 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Sun, 24 Dec 2023 15:36:59 +0100 Subject: [PATCH 4/4] Fix version --- cmd/catp/catp/app.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/catp/catp/app.go b/cmd/catp/catp/app.go index a7e0820..77d2208 100644 --- a/cmd/catp/catp/app.go +++ b/cmd/catp/catp/app.go @@ -389,7 +389,8 @@ func Main() error { //nolint:funlen,cyclop,gocognit,gocyclo ver := flag.Bool("version", false, "print version and exit") flag.Usage = func() { - fmt.Println("catp", version.Info().Version+",", version.Info().GoVersion, strings.Join(versionExtra, " ")) + fmt.Println("catp", version.Module("github.com/bool64/progress").Version+",", + version.Info().GoVersion, strings.Join(versionExtra, " ")) fmt.Println() fmt.Println("catp prints contents of files to STDOUT or dir/file output, \n" + "while printing current progress status to STDERR. \n" +