diff options
| author | Tero Koskinen <tero.koskinen@iki.fi> | 2020-07-25 11:11:13 +0300 |
|---|---|---|
| committer | Reto Brunner <reto@labrat.space> | 2020-07-27 18:26:57 +0200 |
| commit | f81cc2803cca4a5213a9d4514ddae8417c23f8ee (patch) | |
| tree | 6b3c3c2264b267106bd922ee9734c248cc933934 /worker/maildir/container.go | |
| parent | c574a838fa89bf46bf7188442f400b206b04df95 (diff) | |
| download | aerc-f81cc2803cca4a5213a9d4514ddae8417c23f8ee.tar.gz aerc-f81cc2803cca4a5213a9d4514ddae8417c23f8ee.zip | |
maildir: Provide nicer error message on invalid url
If accounts.conf contains an invalid maildir url, return a nice
error instead of panicking.
Log a couple of different error cases to provide extra
information about the error to the user.
Diffstat (limited to 'worker/maildir/container.go')
| -rw-r--r-- | worker/maildir/container.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/worker/maildir/container.go b/worker/maildir/container.go index cd9a447..14815c9 100644 --- a/worker/maildir/container.go +++ b/worker/maildir/container.go @@ -21,15 +21,30 @@ type Container struct { } // NewContainer creates a new container at the specified directory -// TODO: return an error if the provided directory is not accessible -func NewContainer(dir string, l *log.Logger) *Container { - return &Container{dir: dir, uids: uidstore.NewStore(), log: l} +func NewContainer(dir string, l *log.Logger) (*Container, error) { + f, err := os.Open(dir) + if err != nil { + return nil, err + } + defer f.Close() + s, err := f.Stat() + if err != nil { + return nil, err + } + if !s.IsDir() { + return nil, fmt.Errorf("Given maildir '%s' not a directory", dir) + } + return &Container{dir: dir, uids: uidstore.NewStore(), log: l}, nil } // ListFolders returns a list of maildir folders in the container func (c *Container) ListFolders() ([]string, error) { folders := []string{} err := filepath.Walk(c.dir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return fmt.Errorf("Invalid path '%s': error: %v", path, err) + + } if !info.IsDir() { return nil } |
