Skip to content

Commit

Permalink
use file stat to check if file is empty (#4469)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar authored Dec 8, 2023
1 parent 5d1a4b7 commit f54ca1c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions internal/pdcp/writer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pdcp

import (
"bufio"
"encoding/json"
"fmt"
"io"
Expand All @@ -10,7 +9,6 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -84,14 +82,15 @@ type uploadResponse struct {
func (u *UploadWriter) Upload() {
defer u.done.Store(true)

// start from beginning
_, _ = u.tempFile.Seek(0, 0)
// skip if file is empty
scanner := bufio.NewScanner(u.tempFile)
if !scanner.Scan() || (scanner.Scan() && strings.TrimSpace(scanner.Text()) == "") {
_ = u.tempFile.Sync()
info, err := u.tempFile.Stat()
if err != nil {
gologger.Error().Msgf("Failed to upload scan results on cloud: %v", err)
return
}
if info.Size() == 0 {
gologger.Verbose().Msgf("Scan results upload to cloud skipped, no results found to upload")
return

}
_, _ = u.tempFile.Seek(0, 0)

Expand Down

0 comments on commit f54ca1c

Please sign in to comment.