Hi,
Thanks for the update
On Fri, Jul 24, 2020 at 10:38:50PM +0300, Tero Koskinen wrote:
> diff --git a/worker/maildir/container.go b/worker/maildir/container.go> index cd9a447..fd46fd8 100644> --- a/worker/maildir/container.go> +++ b/worker/maildir/container.go> @@ -21,15 +21,27 @@ 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> + }> + s, _ := f.Stat()
Why are you ignoring the error instead of returning it?
If the error is non nil, chances are that s is the zero valued struct, which
isn't overly useful but you still try to call methods on it later.
> + f.Close()
defer please, and right after opening it (after the error check).
Not that important here, but you might as well get into the habit
> + if !s.IsDir() {> + return nil, fmt.Errorf("Given maildir '%s' not a directory", dir)> + }> + return &Container{dir: dir, uids: uidstore.NewStore(), log: l}, nil> }
Greetings,
Reto
Hi,
On Sat, 25 Jul 2020 08:23:16 +0200
Reto <reto@labrat.space> wrote:
> Hi,> Thanks for the update> > On Fri, Jul 24, 2020 at 10:38:50PM +0300, Tero Koskinen wrote:> > + f, err := os.Open(dir)> > + if err != nil {> > + return nil, err> > + }> > + s, _ := f.Stat()> Why are you ignoring the error instead of returning it?> If the error is non nil, chances are that s is the zero valued struct, which> isn't overly useful but you still try to call methods on it later.
I added the error checking in v3.
My initial assumption was that fstat() shouldn't fail if we have
successfully opened the directory. But now, after checking the manual
pages, I noticed at least on OpenBSD fstat() can return EIO if there
is a file system reading error during fstat() call.
> > + f.Close()> > defer please, and right after opening it (after the error check).
Added defer in v3.
Yours,
Tero