Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync counters on read/write error (incl io.EOF) #12

Merged
merged 4 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') != ''
Expand Down
5 changes: 2 additions & 3 deletions cmd/catp/catp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@
r.readFile(rd, out)
}

cr.Close()

if r.parallel <= 1 {
r.pr.Stop()
}
Expand Down Expand Up @@ -391,7 +389,8 @@
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, " "))

Check notice on line 393 in cmd/catp/catp/app.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

7 statement(s) on lines 391:402 are not covered by tests.
fmt.Println()
fmt.Println("catp prints contents of files to STDOUT or dir/file output, \n" +
"while printing current progress status to STDERR. \n" +
Expand Down
18 changes: 9 additions & 9 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@
cr.bytes = bytes
}

func (cr *sharedCounters) count(n int, p []byte) {
func (cr *sharedCounters) count(n int, p []byte, err error) {

Check notice on line 280 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

4 statement(s) on lines 280:286 are not covered by tests.
cr.localBytes += int64(n)

if cr.localBytes > 100000 && cr.bytes != nil {
if (err != nil || cr.localBytes > 100000) && cr.bytes != nil {

Check notice on line 283 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

4 statement(s) on lines 280:286 are not covered by tests.
atomic.AddInt64(cr.bytes, cr.localBytes)
cr.localBytes = 0
}
Expand All @@ -292,19 +292,19 @@
for i := 0; i < n; i++ {
if p[i] == '\n' {
cr.localLines++

if 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
}

Check notice on line 301 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

3 statement(s) are not covered by tests.
}

// 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)

Check notice on line 307 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

3 statement(s) on lines 305:310 are not covered by tests.

return n, err
}
Expand Down Expand Up @@ -349,7 +349,7 @@
// 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)

Check notice on line 352 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.21.x)

3 statement(s) on lines 350:355 are not covered by tests.

return n, err
}
Expand Down
Loading