]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/ctx.go
Move ensureRxDir to ctx file
[nncp.git] / src / cypherpunks.ru / nncp / ctx.go
index 3defbeab5a6d948368e25656f9aa528b0036072c..0d00803a8aa3b432252e1524bb03819e9c25b75b 100644 (file)
@@ -20,6 +20,8 @@ package nncp
 
 import (
        "errors"
+       "os"
+       "path/filepath"
 )
 
 type Ctx struct {
@@ -51,3 +53,18 @@ func (ctx *Ctx) FindNode(id string) (*Node, error) {
        }
        return node, nil
 }
+
+func (ctx *Ctx) ensureRxDir(nodeId *NodeId) error {
+       dirPath := filepath.Join(ctx.Spool, nodeId.String(), string(TRx))
+       if err := os.MkdirAll(dirPath, os.FileMode(0700)); err != nil {
+               ctx.LogE("llp-ensure", SDS{"dir": dirPath, "err": err}, "")
+               return err
+       }
+       fd, err := os.Open(dirPath)
+       if err != nil {
+               ctx.LogE("llp-ensure", SDS{"dir": dirPath, "err": err}, "")
+               return err
+       }
+       fd.Close()
+       return nil
+}