aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/pgp/pgp.go15
-rw-r--r--lib/ipc/receive.go5
-rw-r--r--lib/ipc/send.go5
-rw-r--r--lib/templates/template.go9
-rw-r--r--lib/xoauth2.go11
5 files changed, 17 insertions, 28 deletions
diff --git a/lib/crypto/pgp/pgp.go b/lib/crypto/pgp/pgp.go
index 8d7c135a..af406446 100644
--- a/lib/crypto/pgp/pgp.go
+++ b/lib/crypto/pgp/pgp.go
@@ -5,10 +5,10 @@ import (
"fmt"
"io"
"os"
- "path"
"strings"
"time"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"github.com/ProtonMail/go-crypto/openpgp"
@@ -16,7 +16,6 @@ import (
"github.com/ProtonMail/go-crypto/openpgp/packet"
"github.com/emersion/go-message/mail"
"github.com/emersion/go-pgpmail"
- "github.com/kyoh86/xdg"
"github.com/pkg/errors"
)
@@ -29,7 +28,7 @@ var (
)
func (m *Mail) KeyringExists() bool {
- keypath := path.Join(xdg.DataHome(), "aerc", "keyring.asc")
+ keypath := xdg.DataPath("aerc", "keyring.asc")
keyfile, err := os.Open(keypath)
if err != nil {
return false
@@ -41,12 +40,12 @@ func (m *Mail) KeyringExists() bool {
func (m *Mail) Init() error {
log.Debugf("Initializing PGP keyring")
- err := os.MkdirAll(path.Join(xdg.DataHome(), "aerc"), 0o700)
+ err := os.MkdirAll(xdg.DataPath("aerc"), 0o700)
if err != nil {
return fmt.Errorf("failed to create data directory: %w", err)
}
- lockpath := path.Join(xdg.DataHome(), "aerc", "keyring.lock")
+ lockpath := xdg.DataPath("aerc", "keyring.lock")
lockfile, err := os.OpenFile(lockpath, os.O_CREATE|os.O_EXCL, 0o600)
if err != nil {
// TODO: Consider connecting to main process over IPC socket
@@ -56,7 +55,7 @@ func (m *Mail) Init() error {
lockfile.Close()
}
- keypath := path.Join(xdg.DataHome(), "aerc", "keyring.asc")
+ keypath := xdg.DataPath("aerc", "keyring.asc")
keyfile, err := os.Open(keypath)
if os.IsNotExist(err) {
return nil
@@ -76,7 +75,7 @@ func (m *Mail) Close() {
if !locked {
return
}
- lockpath := path.Join(xdg.DataHome(), "aerc", "keyring.lock")
+ lockpath := xdg.DataPath("aerc", "keyring.lock")
os.Remove(lockpath)
}
@@ -161,7 +160,7 @@ func (m *Mail) ImportKeys(r io.Reader) error {
}
Keyring = append(Keyring, keys...)
if locked {
- keypath := path.Join(xdg.DataHome(), "aerc", "keyring.asc")
+ keypath := xdg.DataPath("aerc", "keyring.asc")
keyfile, err := os.OpenFile(keypath, os.O_CREATE|os.O_APPEND, 0o600)
if err != nil {
return err
diff --git a/lib/ipc/receive.go b/lib/ipc/receive.go
index 12df3411..29ed0808 100644
--- a/lib/ipc/receive.go
+++ b/lib/ipc/receive.go
@@ -6,14 +6,13 @@ import (
"net"
"net/url"
"os"
- "path"
"strings"
"sync/atomic"
"time"
"git.sr.ht/~rjarry/aerc/config"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
- "github.com/kyoh86/xdg"
)
type AercServer struct {
@@ -22,7 +21,7 @@ type AercServer struct {
}
func StartServer(handler Handler) (*AercServer, error) {
- sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
+ sockpath := xdg.RuntimePath("aerc.sock")
// remove the socket if it is not connected to a session
if err := ConnectAndExec(nil); err != nil {
os.Remove(sockpath)
diff --git a/lib/ipc/send.go b/lib/ipc/send.go
index 4b09268c..fbe67413 100644
--- a/lib/ipc/send.go
+++ b/lib/ipc/send.go
@@ -5,13 +5,12 @@ import (
"errors"
"fmt"
"net"
- "path"
- "github.com/kyoh86/xdg"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
)
func ConnectAndExec(args []string) error {
- sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
+ sockpath := xdg.RuntimePath("aerc.sock")
conn, err := net.Dial("unix", sockpath)
if err != nil {
return err
diff --git a/lib/templates/template.go b/lib/templates/template.go
index 6eae591a..4d96472d 100644
--- a/lib/templates/template.go
+++ b/lib/templates/template.go
@@ -5,21 +5,16 @@ import (
"fmt"
"io"
"os"
- "path"
"reflect"
"text/template"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/models"
- "github.com/mitchellh/go-homedir"
)
func findTemplate(templateName string, templateDirs []string) (string, error) {
for _, dir := range templateDirs {
- templateFile, err := homedir.Expand(path.Join(dir, templateName))
- if err != nil {
- return "", err
- }
-
+ templateFile := xdg.ExpandHome(dir, templateName)
if _, err := os.Stat(templateFile); os.IsNotExist(err) {
continue
}
diff --git a/lib/xoauth2.go b/lib/xoauth2.go
index c0f654b8..65f914de 100644
--- a/lib/xoauth2.go
+++ b/lib/xoauth2.go
@@ -13,11 +13,10 @@ import (
"encoding/json"
"fmt"
"os"
- "path"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"github.com/emersion/go-imap/client"
"github.com/emersion/go-sasl"
- "github.com/kyoh86/xdg"
"golang.org/x/oauth2"
)
@@ -73,10 +72,8 @@ func (c *Xoauth2) ExchangeRefreshToken(refreshToken string) (*oauth2.Token, erro
}
func SaveRefreshToken(refreshToken string, acct string) error {
- p := path.Join(xdg.CacheHome(), "aerc", acct+"-xoauth2.token")
- if _, err := os.Stat(p); os.IsNotExist(err) {
- _ = os.MkdirAll(path.Join(xdg.CacheHome(), "aerc"), 0o700)
- }
+ p := xdg.CachePath("aerc", acct+"-xoauth2.token")
+ _ = os.MkdirAll(xdg.CachePath("aerc"), 0o700)
return os.WriteFile(
p,
@@ -86,7 +83,7 @@ func SaveRefreshToken(refreshToken string, acct string) error {
}
func GetRefreshToken(acct string) ([]byte, error) {
- p := path.Join(xdg.CacheHome(), "aerc", acct+"-xoauth2.token")
+ p := xdg.CachePath("aerc", acct+"-xoauth2.token")
return os.ReadFile(p)
}