]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/dirwatch.go
Raise copyright years
[nncp.git] / src / dirwatch.go
index 69a200b364ef122e0902c585f1768f650d079554..1dab640ba6b8f3a1bcf14184024b5257f736ecbf 100644 (file)
@@ -3,7 +3,7 @@
 
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -22,7 +22,6 @@ package nncp
 
 import (
        "fmt"
-       "os"
        "time"
 
        "github.com/fsnotify/fsnotify"
@@ -39,21 +38,14 @@ func (ctx *Ctx) NewDirWatcher(dir string, d time.Duration) (*DirWatcher, error)
        if err != nil {
                return nil, err
        }
+       err = ensureDir(dir)
+       if err != nil {
+               return nil, err
+       }
        err = w.Add(dir)
        if err != nil {
-               if !os.IsNotExist(err) {
-                       w.Close()
-                       return nil, err
-               }
-               if err = os.MkdirAll(dir, os.FileMode(0777)); err != nil {
-                       w.Close()
-                       return nil, err
-               }
-               err = w.Add(dir)
-               if err != nil {
-                       w.Close()
-                       return nil, err
-               }
+               w.Close()
+               return nil, err
        }
        dw := DirWatcher{
                w:      w,