aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-08-23 21:36:23 +0200
committerRobin Jarry <robin@jarry.cc>2023-08-27 18:44:12 +0200
commita5bc7ccf0cae608ac1e72ab4c9ebe5596eb8c988 (patch)
treebe2e5f55fc21980489dca61947ea6b9819853ec3 /worker
parentfff16640ad7cd8c4b73187fbce10f2aa558701be (diff)
downloadaerc-a5bc7ccf0cae608ac1e72ab4c9ebe5596eb8c988.tar.gz
xdg: get rid of deprecated dependencies
github.com/mitchellh/go-homedir has not received any update since 2019. The last release of github.com/kyoh86/xdg was in 2020 and it has been marked as deprecated by its author. Replace these with internal functions. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/cache.go23
-rw-r--r--worker/imap/configure.go7
-rw-r--r--worker/jmap/cache/cache.go12
-rw-r--r--worker/maildir/worker.go7
-rw-r--r--worker/notmuch/worker.go18
5 files changed, 13 insertions, 54 deletions
diff --git a/worker/imap/cache.go b/worker/imap/cache.go
index ec7cffd9..e33736cc 100644
--- a/worker/imap/cache.go
+++ b/worker/imap/cache.go
@@ -6,19 +6,17 @@ import (
"encoding/gob"
"errors"
"fmt"
- "os"
- "path"
"strings"
"time"
"git.sr.ht/~rjarry/aerc/lib/parse"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
"github.com/emersion/go-message"
"github.com/emersion/go-message/mail"
"github.com/emersion/go-message/textproto"
- "github.com/mitchellh/go-homedir"
"github.com/syndtr/goleveldb/leveldb"
)
@@ -51,13 +49,7 @@ func (w *IMAPWorker) initCacheDb(acct string) {
headerTag := strings.Join(w.config.headers, "")
cacheTag = append(cacheTag, headerTag...)
}
- cd, err := cacheDir()
- if err != nil {
- w.cache = nil
- w.worker.Errorf("unable to find cache directory: %v", err)
- return
- }
- p := path.Join(cd, acct)
+ p := xdg.CachePath("aerc", acct)
db, err := leveldb.OpenFile(p, nil)
if err != nil {
w.cache = nil
@@ -171,17 +163,6 @@ func (w *IMAPWorker) headerKey(uid uint32) []byte {
return []byte(key)
}
-func cacheDir() (string, error) {
- dir, err := os.UserCacheDir()
- if err != nil {
- dir, err = homedir.Expand("~/.cache")
- if err != nil {
- return "", err
- }
- }
- return path.Join(dir, "aerc"), nil
-}
-
// cleanCache removes stale entries from the selected mailbox cachedb
func (w *IMAPWorker) cleanCache(path string) {
defer log.PanicHandler()
diff --git a/worker/imap/configure.go b/worker/imap/configure.go
index c325de23..49464689 100644
--- a/worker/imap/configure.go
+++ b/worker/imap/configure.go
@@ -9,10 +9,10 @@ import (
"strings"
"time"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/worker/lib"
"git.sr.ht/~rjarry/aerc/worker/middleware"
"git.sr.ht/~rjarry/aerc/worker/types"
- "github.com/mitchellh/go-homedir"
"golang.org/x/oauth2"
)
@@ -170,10 +170,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error {
w.observer = newObserver(w.config, w.worker)
if name, ok := msg.Config.Params["folder-map"]; ok {
- file, err := homedir.Expand(name)
- if err != nil {
- return err
- }
+ file := xdg.ExpandHome(name)
f, err := os.Open(file)
if err != nil {
return err
diff --git a/worker/jmap/cache/cache.go b/worker/jmap/cache/cache.go
index 07d23493..249ed0e9 100644
--- a/worker/jmap/cache/cache.go
+++ b/worker/jmap/cache/cache.go
@@ -5,8 +5,8 @@ import (
"os"
"path"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
- "github.com/mitchellh/go-homedir"
"github.com/syndtr/goleveldb/leveldb"
)
@@ -18,15 +18,9 @@ type JMAPCache struct {
func NewJMAPCache(state, blobs bool, accountName string) *JMAPCache {
c := new(JMAPCache)
- cacheDir, err := os.UserCacheDir()
- if err != nil {
- cacheDir, err = homedir.Expand("~/.cache")
- if err != nil {
- log.Errorf("homedir.Expand: %s", err)
- cacheDir = ""
- }
- }
+ cacheDir := xdg.CachePath()
if state && cacheDir != "" {
+ var err error
dir := path.Join(cacheDir, "aerc", accountName, "state")
_ = os.MkdirAll(dir, 0o700)
c.file, err = leveldb.OpenFile(dir, nil)
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index e8da6fbd..de882589 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -18,11 +18,11 @@ import (
"time"
"github.com/emersion/go-maildir"
- "github.com/mitchellh/go-homedir"
aercLib "git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/iterator"
"git.sr.ht/~rjarry/aerc/lib/watchers"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/handlers"
@@ -361,10 +361,7 @@ func (w *Worker) handleConfigure(msg *types.Configure) error {
w.worker.Debugf("configured base maildir: %s", dir)
if name, ok := msg.Config.Params["folder-map"]; ok {
- file, err := homedir.Expand(name)
- if err != nil {
- return err
- }
+ file := xdg.ExpandHome(name)
f, err := os.Open(file)
if err != nil {
return err
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 85f813da..73aa0efe 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -20,13 +20,13 @@ import (
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib/watchers"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/handlers"
"git.sr.ht/~rjarry/aerc/worker/lib"
notmuch "git.sr.ht/~rjarry/aerc/worker/notmuch/lib"
"git.sr.ht/~rjarry/aerc/worker/types"
- "github.com/mitchellh/go-homedir"
)
func init() {
@@ -208,10 +208,7 @@ func (w *worker) handleConfigure(msg *types.Configure) error {
w.w.Errorf("error configuring notmuch worker: %v", err)
return err
}
- home, err := homedir.Expand(u.Hostname())
- if err != nil {
- return fmt.Errorf("could not resolve home directory: %w", err)
- }
+ home := xdg.ExpandHome(u.Hostname())
pathToDB := filepath.Join(home, u.Path)
err = w.loadQueryMap(msg.Config)
if err != nil {
@@ -222,11 +219,7 @@ func (w *worker) handleConfigure(msg *types.Configure) error {
val, ok := msg.Config.Params["maildir-store"]
if ok {
- path, err := homedir.Expand(val)
- if err != nil {
- return err
- }
-
+ path := xdg.ExpandHome(val)
w.maildirAccountPath = msg.Config.Params["maildir-account-path"]
path = filepath.Join(path, w.maildirAccountPath)
@@ -607,10 +600,7 @@ func (w *worker) loadQueryMap(acctConfig *config.AccountConfig) error {
// nothing to do
return nil
}
- file, err := homedir.Expand(raw)
- if err != nil {
- return err
- }
+ file := xdg.ExpandHome(raw)
f, err := os.Open(file)
if err != nil {
return err