use reader instead of scanner to be able to read long lines

pull/155/head
Simon Let 5 years ago
parent d5f8df8c06
commit 1188da141c
No known key found for this signature in database
GPG Key ID: D650C65DD46D431D
  1. 3
      cmd/cli/main.go
  2. 2
      pkg/histfile/histfile.go
  3. 15
      pkg/records/records.go

@ -622,5 +622,8 @@ func SendCliMsg(m msg.CliMsg, port string) msg.CliResponse {
if err != nil {
log.Fatal("unmarshal resp error: ", err)
}
if debug {
log.Printf("recieved %d records from daemon\n", len(response.CliRecords))
}
return response
}

@ -61,6 +61,7 @@ func (h *Histfile) loadCliRecords(recs []records.Record) {
rec := recs[i]
h.cliRecords.AddRecord(rec)
}
log.Println("histfile: resh history loaded - history records count:", len(h.cliRecords.List))
}
// loadsHistory from resh_history and if there is not enough of it also load native shell histories
@ -88,6 +89,7 @@ func (h *Histfile) loadHistory(bashHistoryPath, zshHistoryPath string, maxInitHi
}
log.Println("histfile: Loading resh history from file ...")
history := records.LoadFromFile(h.historyPath, math.MaxInt32)
log.Println("histfile: resh history loaded from file - count:", len(history))
go h.loadCliRecords(history)
// NOTE: keeping this weird interface for now because we might use it in the future
// when we only load bash or zsh history

@ -524,14 +524,17 @@ func LoadFromFile(fname string, limit int) []Record {
}
defer file.Close()
scanner := bufio.NewScanner(file)
reader := bufio.NewReader(file)
var i int
var firstErrLine int
for scanner.Scan() {
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
i++
record := Record{}
fallbackRecord := FallbackRecord{}
line := scanner.Text()
err = json.Unmarshal([]byte(line), &record)
if err != nil {
err = json.Unmarshal([]byte(line), &fallbackRecord)
@ -550,6 +553,11 @@ func LoadFromFile(fname string, limit int) []Record {
}
recs = append(recs, record)
}
// log.Println("records: done loading file:", err)
if err != io.EOF {
log.Println("records: error while loading file:", err)
}
// log.Println("records: Loaded lines - count:", i)
if encounteredErrors > 0 {
// fix errors in the history file
log.Printf("There were %d decoding errors, the first error happend on line %d/%d", encounteredErrors, firstErrLine, i)
@ -564,6 +572,7 @@ func LoadFromFile(fname string, limit int) []Record {
log.Fatalln("Fatal: Failed write out new history")
}
}
log.Println("records: Loaded records - count:", len(recs))
return recs
}

Loading…
Cancel
Save