diff options
-rw-r--r-- | commands/cd.go | 7 | ||||
-rw-r--r-- | commands/compose/attach.go | 10 | ||||
-rw-r--r-- | commands/history.go | 7 | ||||
-rw-r--r-- | commands/msgview/save.go | 10 | ||||
-rw-r--r-- | commands/util.go | 9 | ||||
-rw-r--r-- | config/config.go | 26 | ||||
-rw-r--r-- | config/general.go | 8 | ||||
-rw-r--r-- | config/style.go | 9 | ||||
-rw-r--r-- | go.mod | 4 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | lib/crypto/pgp/pgp.go | 15 | ||||
-rw-r--r-- | lib/ipc/receive.go | 5 | ||||
-rw-r--r-- | lib/ipc/send.go | 5 | ||||
-rw-r--r-- | lib/templates/template.go | 9 | ||||
-rw-r--r-- | lib/xoauth2.go | 11 | ||||
-rw-r--r-- | widgets/account-wizard.go | 34 | ||||
-rw-r--r-- | widgets/compose.go | 7 | ||||
-rw-r--r-- | worker/imap/cache.go | 23 | ||||
-rw-r--r-- | worker/imap/configure.go | 7 | ||||
-rw-r--r-- | worker/jmap/cache/cache.go | 12 | ||||
-rw-r--r-- | worker/maildir/worker.go | 7 | ||||
-rw-r--r-- | worker/notmuch/worker.go | 18 |
22 files changed, 66 insertions, 181 deletions
diff --git a/commands/cd.go b/commands/cd.go index dc05adbb..8c0191c2 100644 --- a/commands/cd.go +++ b/commands/cd.go @@ -5,8 +5,8 @@ import ( "os" "strings" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/widgets" - "github.com/mitchellh/go-homedir" ) var previousDir string @@ -54,10 +54,7 @@ func (ChangeDirectory) Execute(aerc *widgets.Aerc, args []string) error { target = previousDir } } - target, err = homedir.Expand(target) - if err != nil { - return err - } + target = xdg.ExpandHome(target) if err := os.Chdir(target); err == nil { previousDir = cwd aerc.UpdateStatus() diff --git a/commands/compose/attach.go b/commands/compose/attach.go index 3f6d124f..f9ef027f 100644 --- a/commands/compose/attach.go +++ b/commands/compose/attach.go @@ -14,9 +14,9 @@ import ( "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/ui" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/widgets" - "github.com/mitchellh/go-homedir" "github.com/pkg/errors" "git.sr.ht/~sircmpwn/getopt" @@ -83,13 +83,7 @@ func (a Attach) Execute(aerc *widgets.Aerc, args []string) error { } func (a Attach) addPath(aerc *widgets.Aerc, path string) error { - path, err := homedir.Expand(path) - if err != nil { - log.Errorf("failed to expand path '%s': %v", path, err) - aerc.PushError(err.Error()) - return err - } - + path = xdg.ExpandHome(path) attachments, err := filepath.Glob(path) if err != nil && errors.Is(err, filepath.ErrBadPattern) { log.Warnf("failed to parse as globbing pattern: %v", err) diff --git a/commands/history.go b/commands/history.go index 7aa42fab..cc85f3ba 100644 --- a/commands/history.go +++ b/commands/history.go @@ -6,11 +6,10 @@ import ( "fmt" "io" "os" - "path" "sync" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" - "github.com/kyoh86/xdg" ) type cmdHistory struct { @@ -92,9 +91,9 @@ func (h *cmdHistory) initialize() { var err error openFlags := os.O_RDWR | os.O_EXCL - histPath := path.Join(xdg.CacheHome(), "aerc", "history") + histPath := xdg.CachePath("aerc", "history") if _, err := os.Stat(histPath); os.IsNotExist(err) { - _ = os.MkdirAll(path.Join(xdg.CacheHome(), "aerc"), 0o700) // caught by OpenFile + _ = os.MkdirAll(xdg.CachePath("aerc"), 0o700) // caught by OpenFile openFlags |= os.O_CREATE } diff --git a/commands/msgview/save.go b/commands/msgview/save.go index 170ef7c1..1ffdaf92 100644 --- a/commands/msgview/save.go +++ b/commands/msgview/save.go @@ -10,10 +10,10 @@ import ( "time" "git.sr.ht/~sircmpwn/getopt" - "github.com/mitchellh/go-homedir" "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/config" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -40,8 +40,7 @@ func (s Save) Complete(aerc *widgets.Aerc, args []string) []string { if defaultPath != "" && !isAbsPath(path) { path = filepath.Join(defaultPath, path) } - path, _ = homedir.Expand(path) - return commands.CompletePath(path) + return commands.CompletePath(xdg.ExpandHome(path)) } type saveParams struct { @@ -99,10 +98,7 @@ func (s Save) Execute(aerc *widgets.Aerc, args []string) error { path = filepath.Join(defaultPath, path) } - path, err = homedir.Expand(path) - if err != nil { - return err - } + path = xdg.ExpandHome(path) mv, ok := aerc.SelectedTabContent().(*widgets.MessageViewer) if !ok { diff --git a/commands/util.go b/commands/util.go index 7e21e167..aeb18237 100644 --- a/commands/util.go +++ b/commands/util.go @@ -13,12 +13,12 @@ import ( "github.com/lithammer/fuzzysearch/fuzzy" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~rjarry/aerc/worker/types" "github.com/gdamore/tcell/v2" - "github.com/mitchellh/go-homedir" ) // QuickTerm is an ephemeral terminal for running a single command and quitting. @@ -80,13 +80,8 @@ func CompletePath(path string) []string { path = cwd } - path, err := homedir.Expand(path) - if err != nil { - return nil - } - // strip trailing slashes, etc. - path = filepath.Clean(path) + path = filepath.Clean(xdg.ExpandHome(path)) if _, err := os.Stat(path); os.IsNotExist(err) { // if the path doesn't exist, it is likely due to it being a partial path diff --git a/config/config.go b/config/config.go index 4ace7d26..092b73a6 100644 --- a/config/config.go +++ b/config/config.go @@ -3,14 +3,12 @@ package config import ( "errors" "fmt" - "log" "os" "path" "strings" + "git.sr.ht/~rjarry/aerc/lib/xdg" "github.com/go-ini/ini" - "github.com/kyoh86/xdg" - "github.com/mitchellh/go-homedir" ) // Set at build time @@ -23,34 +21,24 @@ func buildDefaultDirs() []string { var defaultDirs []string prefixes := []string{ - xdg.ConfigHome(), + xdg.ConfigPath(), "~/.local/libexec", - xdg.DataHome(), + xdg.DataPath(), } // Add XDG_CONFIG_HOME and XDG_DATA_HOME for _, v := range prefixes { if v != "" { - v, err := homedir.Expand(v) - if err != nil { - log.Println(err) - } - defaultDirs = append(defaultDirs, path.Join(v, "aerc")) + defaultDirs = append(defaultDirs, xdg.ExpandHome(v, "aerc")) } } // Add custom buildtime dirs if libexecDir != "" && libexecDir != "/usr/local/libexec/aerc" { - libexecDir, err := homedir.Expand(libexecDir) - if err == nil { - defaultDirs = append(defaultDirs, libexecDir) - } + defaultDirs = append(defaultDirs, xdg.ExpandHome(libexecDir)) } if shareDir != "" && shareDir != "/usr/local/share/aerc" { - shareDir, err := homedir.Expand(shareDir) - if err == nil { - defaultDirs = append(defaultDirs, shareDir) - } + defaultDirs = append(defaultDirs, xdg.ExpandHome(shareDir)) } // Add fixed fallback locations @@ -91,7 +79,7 @@ func installTemplate(root, name string) error { func LoadConfigFromFile(root *string, accts []string) error { if root == nil { - _root := path.Join(xdg.ConfigHome(), "aerc") + _root := xdg.ConfigPath("aerc") root = &_root } filename := path.Join(*root, "aerc.conf") diff --git a/config/general.go b/config/general.go index 65c20cfd..f4149583 100644 --- a/config/general.go +++ b/config/general.go @@ -4,10 +4,10 @@ import ( "fmt" "os" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" "github.com/go-ini/ini" "github.com/mattn/go-isatty" - "github.com/mitchellh/go-homedir" ) type GeneralConfig struct { @@ -34,10 +34,8 @@ func parseGeneral(file *ini.File) error { // redirected to file, force TRACE level General.LogLevel = log.TRACE } else if General.LogFile != "" { - path, err := homedir.Expand(General.LogFile) - if err != nil { - return fmt.Errorf("log-file: %w", err) - } + var err error + path := xdg.ExpandHome(General.LogFile) logFile, err = os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600) if err != nil { diff --git a/config/style.go b/config/style.go index 2b1ef41a..50c53de3 100644 --- a/config/style.go +++ b/config/style.go @@ -4,15 +4,14 @@ import ( "errors" "fmt" "os" - "path" "regexp" "strconv" "strings" + "git.sr.ht/~rjarry/aerc/lib/xdg" "github.com/emersion/go-message/mail" "github.com/gdamore/tcell/v2" "github.com/go-ini/ini" - "github.com/mitchellh/go-homedir" ) type StyleObject int32 @@ -355,11 +354,7 @@ func (ss StyleSet) ComposeSelected( func findStyleSet(stylesetName string, stylesetsDir []string) (string, error) { for _, dir := range stylesetsDir { - stylesetPath, err := homedir.Expand(path.Join(dir, stylesetName)) - if err != nil { - return "", err - } - + stylesetPath := xdg.ExpandHome(dir, stylesetName) if _, err := os.Stat(stylesetPath); os.IsNotExist(err) { continue } @@ -24,12 +24,10 @@ require ( github.com/gdamore/tcell/v2 v2.6.0 github.com/go-ini/ini v1.67.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/kyoh86/xdg v1.2.0 github.com/lithammer/fuzzysearch v1.1.5 github.com/mattn/go-isatty v0.0.18 github.com/mattn/go-runewidth v0.0.14 github.com/miolini/datacounter v1.0.3 - github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 github.com/rivo/uniseg v0.4.4 github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab @@ -38,6 +36,7 @@ require ( github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e github.com/zenhack/go.notmuch v0.0.0-20220918173508-0c918632c39e golang.org/x/oauth2 v0.7.0 + golang.org/x/sys v0.7.0 golang.org/x/tools v0.6.0 ) @@ -56,7 +55,6 @@ require ( github.com/rogpeppe/go-internal v1.8.1 // indirect golang.org/x/crypto v0.8.0 // indirect golang.org/x/net v0.9.0 // indirect - golang.org/x/sys v0.7.0 // indirect golang.org/x/term v0.7.0 // indirect golang.org/x/text v0.9.0 // indirect google.golang.org/appengine v1.6.7 // indirect @@ -101,8 +101,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kyoh86/xdg v1.2.0 h1:CERuT/ShdTDj+A2UaX3hQ3mOV369+Sj+wyn2nIRIIkI= -github.com/kyoh86/xdg v1.2.0/go.mod h1:/mg8zwu1+qe76oTFUBnyS7rJzk7LLC0VGEzJyJ19DHs= github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMrOBEp1c= github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4HmAH30Dh61Ih1Q= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -116,8 +114,6 @@ github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWV github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miolini/datacounter v1.0.3 h1:tanOZPVblGXQl7/bSZWoEM8l4KK83q24qwQLMrO/HOA= github.com/miolini/datacounter v1.0.3/go.mod h1:C45dc2hBumHjDpEU64IqPwR6TDyPVpzOqqRTN7zmBUA= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= 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) } diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index b0615ef8..7bb61079 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -7,7 +7,6 @@ import ( "net/url" "os" "os/exec" - "path" "regexp" "strconv" "strings" @@ -16,13 +15,12 @@ import ( "github.com/emersion/go-message/mail" "github.com/gdamore/tcell/v2" "github.com/go-ini/ini" - "github.com/kyoh86/xdg" - "github.com/mitchellh/go-homedir" "golang.org/x/sys/unix" "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/format" "git.sr.ht/~rjarry/aerc/lib/ui" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" ) @@ -356,7 +354,7 @@ Make sure to review the contents of this file and read the aerc-accounts(5) man page for guidance and further tweaking. To add another account in the future, run ':new-account'. -`, tildeHome(path.Join(xdg.ConfigHome(), "aerc"))), +`, xdg.TildeHome(xdg.ConfigPath("aerc"))), &wizard.complete, ) complete.AddField( @@ -413,7 +411,7 @@ func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) { } func (wizard *AccountWizard) finish(tutorial bool) { - accountsConf := path.Join(xdg.ConfigHome(), "aerc", "accounts.conf") + accountsConf := xdg.ConfigPath("aerc", "accounts.conf") // Validation if wizard.accountName.String() == "" { @@ -439,10 +437,7 @@ func (wizard *AccountWizard) finish(tutorial bool) { } switch wizard.sourceProtocol.Selected() { case MAILDIR, MAILDIRPP, NOTMUCH: - path := wizard.sourceServer.String() - if p, err := homedir.Expand(path); err == nil { - path = p - } + path := xdg.ExpandHome(wizard.sourceServer.String()) s, err := os.Stat(path) if err == nil && !s.IsDir() { err = fmt.Errorf("%s: Not a directory", s.Name()) @@ -456,10 +451,7 @@ func (wizard *AccountWizard) finish(tutorial bool) { } } if wizard.outgoingProtocol.Selected() == SENDMAIL { - path := wizard.outgoingServer.String() - if p, err := homedir.Expand(path); err == nil { - path = p - } + path := xdg.ExpandHome(wizard.outgoingServer.String()) s, err := os.Stat(path) if err == nil && !s.Mode().IsRegular() { err = fmt.Errorf("%s: Not a regular file", s.Name()) @@ -510,7 +502,7 @@ func (wizard *AccountWizard) finish(tutorial bool) { out, err := cmd.Output() if err == nil { root := strings.TrimSpace(string(out)) - _, _ = sec.NewKey("maildir-store", tildeHome(root)) + _, _ = sec.NewKey("maildir-store", xdg.TildeHome(root)) } querymap := ini.Empty() def := querymap.Section("") @@ -526,7 +518,7 @@ func (wizard *AccountWizard) finish(tutorial bool) { _, _ = def.NewKey("INBOX", "tag:inbox and not tag:archived") } if !wizard.temporary { - qmapPath := path.Join(xdg.ConfigHome(), "aerc", + qmapPath := xdg.ConfigPath("aerc", wizard.accountName.String()+".qmap") f, err := os.OpenFile(qmapPath, os.O_WRONLY|os.O_CREATE, 0o600) if err != nil { @@ -538,7 +530,7 @@ func (wizard *AccountWizard) finish(tutorial bool) { wizard.errorFor(nil, err) return } - _, _ = sec.NewKey("query-map", tildeHome(qmapPath)) + _, _ = sec.NewKey("query-map", xdg.TildeHome(qmapPath)) } } @@ -866,7 +858,7 @@ func (wizard *AccountWizard) autofill() { out, err := cmd.Output() if err == nil { db := strings.TrimSpace(string(out)) - wizard.sourceServer.Set(tildeHome(db)) + wizard.sourceServer.Set(xdg.TildeHome(db)) } else { wizard.sourceServer.Set("~/mail") } @@ -897,11 +889,3 @@ func (wizard *AccountWizard) autofill() { } } } - -func tildeHome(path string) string { - home, err := homedir.Dir() - if err == nil && home != "" && strings.HasPrefix(path, home) { - path = "~" + strings.TrimPrefix(path, home) - } - return path -} diff --git a/widgets/compose.go b/widgets/compose.go index 5ad67fd3..f682fe5c 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -18,7 +18,6 @@ import ( "github.com/emersion/go-message/mail" "github.com/gdamore/tcell/v2" "github.com/mattn/go-runewidth" - "github.com/mitchellh/go-homedir" "github.com/pkg/errors" "git.sr.ht/~rjarry/aerc/completer" @@ -28,6 +27,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib/state" "git.sr.ht/~rjarry/aerc/lib/templates" "git.sr.ht/~rjarry/aerc/lib/ui" + "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" @@ -650,10 +650,7 @@ func (c *Composer) readSignatureFromFile() []byte { if sigFile == "" { return nil } - sigFile, err := homedir.Expand(sigFile) - if err != nil { - return nil - } + sigFile = xdg.ExpandHome(sigFile) signature, err := os.ReadFile(sigFile) if err != nil { c.aerc.PushError( 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 |