Tim Culverhouse: 1 chore: make linter happy 9 files changed, 32 insertions(+), 29 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~rockorager/offmap/patches/37330/mbox | git am -3Learn more about email & git
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> --- v2: use nolint comments, wrap an error cmd/offmap.go | 2 +- cmd/sync.go | 16 ++++++++++++---- imap/client.go | 5 ++--- imap/imap.go | 3 +-- log/log.go | 12 ++++++------ maildir/maildir.go | 8 +++++++- maildir/maildir_test.go | 9 +-------- maildir/update_test.go | 4 ++-- state.go | 2 -- 9 files changed, 32 insertions(+), 29 deletions(-) diff --git a/cmd/offmap.go b/cmd/offmap.go index dff52b8..94d05b8 100644 --- a/cmd/offmap.go +++ b/cmd/offmap.go @@ -12,7 +12,7 @@ import ( func main() { ctx, cancel := context.WithCancel(context.Background()) - sigCh := make(chan os.Signal) + sigCh := make(chan os.Signal, 4) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) go func() { sig := <-sigCh diff --git a/cmd/sync.go b/cmd/sync.go index 4568077..de6782d 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -61,7 +61,9 @@ func sync(cmd *cobra.Command, args []string) { go func() { // Save our state if we cancel the command <-cmd.Context().Done() - state.Save() + if err := state.Save(); err != nil { + log.Errorf("offmap: could not save state: %v", err) + } remote.Cleanup() log.Infof("offmap: sync aborted, state saved") }() @@ -71,7 +73,9 @@ func sync(cmd *cobra.Command, args []string) { if err != nil { // Save any changes we've made. log.Fatalf calls os.Exit(1). // Defers are bypassed with this call - state.Save() + if err := state.Save(); err != nil { + log.Errorf("offmap: could not save state: %v", err) + } log.Fatalf("imap: could not apply diff: %v", err) } @@ -80,12 +84,16 @@ func sync(cmd *cobra.Command, args []string) { if err != nil { // Save any changes we've made. log.Fatalf calls os.Exit(1). // Defers are bypassed with this call - state.Save() + if err := state.Save(); err != nil { + log.Errorf("offmap: could not save state: %v", err) + } log.Fatalf("%v", err) } // Save and clean up - state.Save() + if err := state.Save(); err != nil { + log.Errorf("offmap: could not save state: %v", err) + } remote.Cleanup() log.Infof("offmap (%s): sync completed in %s", cfg.Name, time.Since(start).Round(1*time.Millisecond)) } diff --git a/imap/client.go b/imap/client.go index 037a702..c410993 100644 --- a/imap/client.go +++ b/imap/client.go @@ -14,7 +14,7 @@ import ( "github.com/emersion/go-sasl" ) -func (s *Store) initClients() error { +func (s *Store) initClients() { start := time.Now() wg := sync.WaitGroup{} for n := 0; n < s.cfg.MaxConnections; n++ { @@ -103,7 +103,6 @@ func (s *Store) initClients() error { log.Debugf("imap: capability found: CONDSTORE") } log.Debugf("imap: created %d clients in %s", len(s.clients), time.Since(start).Round(1*time.Millisecond)) - return nil } type conn struct { @@ -133,6 +132,6 @@ func (s *Store) getConn() *conn { // logout logs out all clients func (s *Store) logout() { for _, client := range s.clients { - client.Logout() + client.Logout() //nolint:errcheck // If the client can't logout, we're exiting anyways } } diff --git a/imap/imap.go b/imap/imap.go index 2e21e78..dde5798 100644 --- a/imap/imap.go +++ b/imap/imap.go @@ -34,7 +34,6 @@ type Store struct { // capabilities liststatus bool condstore bool - qresync bool } // NewStore creates a new IMAP store @@ -210,7 +209,7 @@ func (s *Store) DownloadEmail(emls []*offmap.Email) []*offmap.Email { log.Errorf("imap: no body") continue } - io.Copy(f, r) + io.Copy(f, r) //nolint:errcheck // We don't care if it actually can't write at this point atomic.AddInt32(&dled, 1) cur := atomic.LoadInt32(&dled) f.Close() diff --git a/log/log.go b/log/log.go index 54da344..f52b52e 100644 --- a/log/log.go +++ b/log/log.go @@ -58,39 +58,39 @@ func Tracef(message string, args ...interface{}) { if level < LevelTrace { return } - trace.Output(2, fmt.Sprintf(message, args...)) + _ = trace.Output(2, fmt.Sprintf(message, args...)) } func Debugf(message string, args ...interface{}) { if level < LevelDebug { return } - debug.Output(2, fmt.Sprintf(message, args...)) + _ = debug.Output(2, fmt.Sprintf(message, args...)) } func Infof(message string, args ...interface{}) { if level < LevelInfo { return } - info.Output(2, fmt.Sprintf(message, args...)) + _ = info.Output(2, fmt.Sprintf(message, args...)) } func Warnf(message string, args ...interface{}) { if level < LevelWarn { return } - warn.Output(2, fmt.Sprintf(message, args...)) + _ = warn.Output(2, fmt.Sprintf(message, args...)) } func Errorf(message string, args ...interface{}) { if level < LevelError { return } - err.Output(2, fmt.Sprintf(message, args...)) + _ = err.Output(2, fmt.Sprintf(message, args...)) } // Fatalf logs the error and exits with code 1 func Fatalf(message string, args ...interface{}) { - fatal.Output(2, fmt.Sprintf(message, args...)) + _ = fatal.Output(2, fmt.Sprintf(message, args...)) os.Exit(1) } diff --git a/maildir/maildir.go b/maildir/maildir.go index 39c7b10..b5768ca 100644 --- a/maildir/maildir.go +++ b/maildir/maildir.go @@ -159,7 +159,10 @@ func (s *Store) readMailboxState() (map[string]*offmap.Mailbox, error) { } } mbox := offmap.NewMailbox(uint32(uidv), mailbox, "") - s.readEmailState(mbox) + err = s.readEmailState(mbox) + if err != nil { + return nil, fmt.Errorf("maildir: could not read email state: %v", err)
also missing a %w :)
+ } mailboxes[mailbox] = mbox } s.mailboxes = mailboxes
But feel free to fix that when applying Reviewed-by: Moritz Poldrack <moritz@poldrack.dev
@@ -188,6 +191,9 @@ func (s *Store) readEmailState(mbox *offmap.Mailbox) error { } file := filepath.Base(path) key, flags, err := parseFilename(file) + if err != nil { + return nil + } eml := offmap.NewEmail(mbox, 0, key, flags) mbox.Emails = append(mbox.Emails, eml) diff --git a/maildir/maildir_test.go b/maildir/maildir_test.go index 35b8fad..24b4ac7 100644 --- a/maildir/maildir_test.go +++ b/maildir/maildir_test.go @@ -9,13 +9,6 @@ import ( "github.com/stretchr/testify/assert" ) -const stateString = ` -dir:idInbox Inbox -dir:idInbox/Test Inbox/Test -dir:idSent Sent -1234 RS Inbox -123567 PS Inbox/Test -` const count = 100 // initMaildir inits a maildir structure with some empty messages @@ -67,7 +60,7 @@ func TestParseFilename(t *testing.T) { assert.Equal(t, "1668011222.spunky.4402831009928014a105838b7d5fe3b", key) assert.Equal(t, []maildir.Flag{'S'}, flags) - key, flags, err = parseFilename("1668011222.spunky.4402831009928014a105838b7d5fe3b2,S") + _, _, err = parseFilename("1668011222.spunky.4402831009928014a105838b7d5fe3b2,S") assert.Error(t, err) key, flags, err = parseFilename("1668011222.spunky.4402831009928014a105838b7d5fe3b:2,") diff --git a/maildir/update_test.go b/maildir/update_test.go index b29a891..4d6c1e5 100644 --- a/maildir/update_test.go +++ b/maildir/update_test.go @@ -21,7 +21,7 @@ func TestCreateMaildir(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 3, len(mboxes)) mbox := offmap.NewMailbox(0, "local", "remote") - err = store.createMaildir(mbox) + _ = store.createMaildir(mbox) mboxes, err = store.readMailboxState() assert.NoError(t, err) assert.Equal(t, 4, len(mboxes)) @@ -76,7 +76,7 @@ func TestCreateEmail(t *testing.T) { if err != nil { t.Fatal(err) } - f.WriteString("email body") + _, _ = f.WriteString("email body") f.Close() eml.SetFilename(tmpEml) diff --git a/state.go b/state.go index 7d9c23c..970c5e4 100644 --- a/state.go +++ b/state.go @@ -9,7 +9,6 @@ import ( "git.sr.ht/~rockorager/offmap/log" "github.com/emersion/go-maildir" - "github.com/spf13/viper" ) // State is the application state. It manages the synchronization state @@ -20,7 +19,6 @@ type State struct { // Emails []*Email `json:"emails"` // root is the save location of the state, and the root of the maildir root string - cfg *viper.Viper mboxes map[uint32]*Mailbox } -- 2.38.1
Applied with the agreed-upon changes. To ssh://git@git.sr.ht/~rockorager/offmap aa75a37..19986f4 main -> mai
builds.sr.ht <builds@sr.ht>offmap/patches/.build.yml: SUCCESS in 1m58s [chore: make linter happy][0] v2 from [Tim Culverhouse][1] [0]: https://lists.sr.ht/~rockorager/offmap/patches/37330 [1]: mailto:tim@timculverhouse.com ✓ #897494 SUCCESS offmap/patches/.build.yml https://builds.sr.ht/~rockorager/job/897494