]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/ctx.go
Free space checking
[nncp.git] / src / cypherpunks.ru / nncp / ctx.go
index 5d705968d680d2885494cefe31333a54ff622e6a..fb7246a5f15ff0e2943fe18ef3400a0075fc0020 100644 (file)
@@ -21,8 +21,11 @@ package nncp
 import (
        "errors"
        "io/ioutil"
+       "log"
        "os"
        "path/filepath"
+
+       "golang.org/x/sys/unix"
 )
 
 type Ctx struct {
@@ -103,3 +106,11 @@ func CtxFromCmdline(cfgPath, spoolPath, logPath string, quiet, debug bool) (*Ctx
        ctx.Debug = debug
        return ctx, nil
 }
+
+func (ctx *Ctx) IsEnoughSpace(want int64) bool {
+       var s unix.Statfs_t
+       if err := unix.Statfs(ctx.Spool, &s); err != nil {
+               log.Fatalln(err)
+       }
+       return s.Bavail*int64(s.Bsize) > want
+}