From b45a2a0f89a465ecd8c36e275ab566f1644164d1 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 5 Jul 2020 19:39:42 +0530 Subject: [PATCH] Fix incorrect record count in the importer --- frontend/src/views/Import.vue | 2 +- internal/subimporter/importer.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/Import.vue b/frontend/src/views/Import.vue index 3dad14d..a2381dd 100644 --- a/frontend/src/views/Import.vue +++ b/frontend/src/views/Import.vue @@ -284,7 +284,7 @@ export default Vue.extend({ // Import progress bar value. progress() { - if (!this.status) { + if (!this.status || !this.status.total > 0) { return 0; } return Math.ceil((this.status.imported / this.status.total) * 100); diff --git a/internal/subimporter/importer.go b/internal/subimporter/importer.go index 9129c99..1ff7816 100644 --- a/internal/subimporter/importer.go +++ b/internal/subimporter/importer.go @@ -432,8 +432,14 @@ func (s *Session) LoadCSV(srcPath string, delim rune) error { s.log.Printf("error counting lines in '%s': '%v'", srcPath, err) return err } + + if numLines == 0 { + return errors.New("empty file") + } + s.im.Lock() - s.im.status.Total = numLines + // Exclude the header from count. + s.im.status.Total = numLines - 1 s.im.Unlock() // Rewind, now that we've done a linecount on the same handler.