From 488335669d5ef8022b741f79903d414823b58aae Mon Sep 17 00:00:00 2001 From: Adam Krieg Date: Thu, 30 Sep 2021 16:03:21 -0400 Subject: [PATCH 1/2] Trim extra non-ascii characters that can arise from manually editing sequence number files --- filestore.go | 5 +++-- filestore_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/filestore.go b/filestore.go index 120ba83c0..650bd388a 100644 --- a/filestore.go +++ b/filestore.go @@ -22,6 +22,7 @@ import ( "os" "path" "strconv" + "strings" "time" "github.com/pkg/errors" @@ -213,7 +214,7 @@ func (store *fileStore) populateCache() (creationTimePopulated bool, err error) } if senderSeqNumBytes, err := ioutil.ReadFile(store.senderSeqNumsFname); err == nil { - if senderSeqNum, err := strconv.Atoi(string(senderSeqNumBytes)); err == nil { + if senderSeqNum, err := strconv.Atoi(strings.Trim(string(senderSeqNumBytes), "\r\n")); err == nil { if err = store.cache.SetNextSenderMsgSeqNum(senderSeqNum); err != nil { return creationTimePopulated, errors.Wrap(err, "cache set next sender") } @@ -221,7 +222,7 @@ func (store *fileStore) populateCache() (creationTimePopulated bool, err error) } if targetSeqNumBytes, err := ioutil.ReadFile(store.targetSeqNumsFname); err == nil { - if targetSeqNum, err := strconv.Atoi(string(targetSeqNumBytes)); err == nil { + if targetSeqNum, err := strconv.Atoi(strings.Trim(string(targetSeqNumBytes),"\r\n")); err == nil { if err = store.cache.SetNextTargetMsgSeqNum(targetSeqNum); err != nil { return creationTimePopulated, errors.Wrap(err, "cache set next target") } diff --git a/filestore_test.go b/filestore_test.go index 3713ac8a9..efb6a9283 100644 --- a/filestore_test.go +++ b/filestore_test.go @@ -19,10 +19,12 @@ import ( "fmt" "os" "path" + "strconv" "strings" "testing" "time" + assert2 "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -62,3 +64,14 @@ func (suite *FileStoreTestSuite) TearDownTest() { func TestFileStoreTestSuite(t *testing.T) { suite.Run(t, new(FileStoreTestSuite)) } + +func TestStringParse(t *testing.T) { + assert := assert2.New(t) + i, err := strconv.Atoi(strings.Trim("00005\n", "\r\n")) + assert.Nil(err) + assert.Equal(5, i) + + i, err = strconv.Atoi(strings.Trim("00006\r", "\r\n")) + assert.Nil(err) + assert.Equal(6, i) +} From e161d08e7b04f38db5be92bd2db26a7f02b91bc9 Mon Sep 17 00:00:00 2001 From: Adam Krieg Date: Thu, 26 Oct 2023 22:37:45 -0400 Subject: [PATCH 2/2] Go fmt file --- filestore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filestore.go b/filestore.go index 650bd388a..0d969a16e 100644 --- a/filestore.go +++ b/filestore.go @@ -222,7 +222,7 @@ func (store *fileStore) populateCache() (creationTimePopulated bool, err error) } if targetSeqNumBytes, err := ioutil.ReadFile(store.targetSeqNumsFname); err == nil { - if targetSeqNum, err := strconv.Atoi(strings.Trim(string(targetSeqNumBytes),"\r\n")); err == nil { + if targetSeqNum, err := strconv.Atoi(strings.Trim(string(targetSeqNumBytes), "\r\n")); err == nil { if err = store.cache.SetNextTargetMsgSeqNum(targetSeqNum); err != nil { return creationTimePopulated, errors.Wrap(err, "cache set next target") }