diff --git a/filestore.go b/filestore.go index 6d010f897..1d23b1813 100644 --- a/filestore.go +++ b/filestore.go @@ -7,6 +7,7 @@ import ( "os" "path" "strconv" + "strings" "time" "github.com/pkg/errors" @@ -178,7 +179,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") } @@ -186,7 +187,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 56fc8ec68..b0ba70e24 100644 --- a/filestore_test.go +++ b/filestore_test.go @@ -4,10 +4,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" ) @@ -47,3 +49,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) +}