]> Cypherpunks.ru repositories - nncp.git/commitdiff
Various file deletion capabilities
authorSergey Matveev <stargrave@stargrave.org>
Wed, 29 Nov 2017 20:41:06 +0000 (23:41 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 29 Nov 2017 20:41:06 +0000 (23:41 +0300)
doc/cmds.texi
doc/news.ru.texi
doc/news.texi
src/cypherpunks.ru/nncp/cmd/nncp-rm/main.go

index 6113aebd62fd5416f05f086c25ac71185a1b525f..51ea04fdd3d78ce3a09f1a83aad5c51966094eb5 100644 (file)
@@ -405,12 +405,29 @@ Checksums:
 @section nncp-rm
 
 @verbatim
-% nncp-rm [options] NODE PKT
+% nncp-rm [options] -tmp
+% nncp-rm [options] -lock
+% nncp-rm [options] -node NODE [-rx] [-tx] [-part] [-seen]
+% nncp-rm [options] -node NODE -pkt PKT
 @end verbatim
 
-Remove specified packet (Base32 name) in @option{NODE}'s queues. This
-command is useful when you want to remove the packet that is failing to
-be processed.
+This command is aimed to delete various files from your spool directory:
+
+@itemize
+@item If @option{-tmp} option is specified, then it will delete all
+temporary files in @file{spool/tmp} directory. Files may stay in it when
+commands like @ref{nncp-file} fail for some reason.
+@item If @option{-lock} option is specified, then all @file{.lock} files
+will be deleted in your spool directory.
+@item If @option{-pkt} option is specified, then @file{PKT} packet (its
+Base32 name) will be deleted. This is useful when you see some packet
+failing to be processed.
+@item When either @option{-rx} or @option{-tx} options are specified
+(maybe both of them), then delete all packets from that given queues. If
+@option{-part} is given, then delete only @file{.part}ly downloaded
+ones. If @option{-seen} option is specified, then delete only
+@file{.seen} files.
+@end itemize
 
 @node nncp-stat
 @section nncp-stat
index a8600ade1617493fb48d93528f57d5a06a98d8ae..ce983f37e2ee634d1d15e6cac71559b60c82cfa7 100644 (file)
@@ -22,6 +22,9 @@
 @item
 Возможность переопределить путь до spool директории и файла журнала
 через аргумент командной строки или переменную окружения.
+@item
+@command{nncp-rm} команда может удалять все исходящие/входящие,
+@file{.seen}, @file{.part}, @file{.lock} и временные файлы.
 @end itemize
 
 @node Релиз 0.12
index eae13ba609231a31dfc6de3d4421b8be55b43fa6..189311da4cee414f8984e567e70fc900d7464bcf 100644 (file)
@@ -24,6 +24,9 @@ packets could create many goroutines.
 @item
 Ability to override path to spool directory and logfile through either
 command line argument, or environment variable.
+@item
+@command{nncp-rm} is able to delete outbound/inbound, @file{.seen},
+@file{.part}, @file{.lock} and temporary files.
 @end itemize
 
 @node Release 0.12
index cfe4bbbc64328dcb19cba3276bd92f902eb89c83..d93a46a01bb903c990899a97c00ccac45e4923a3 100644 (file)
@@ -25,6 +25,7 @@ import (
        "log"
        "os"
        "path/filepath"
+       "strings"
 
        "cypherpunks.ru/nncp"
 )
@@ -32,15 +33,26 @@ import (
 func usage() {
        fmt.Fprintf(os.Stderr, nncp.UsageHeader())
        fmt.Fprintln(os.Stderr, "nncp-rm -- remove packet\n")
-       fmt.Fprintf(os.Stderr, "Usage: %s [options] NODE PKT\nOptions:\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options] -tmp\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] -lock\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] -node NODE [-rx] [-tx] [-part] [-seen]\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] -node NODE -pkt PKT\n", os.Args[0])
+       fmt.Fprintln(os.Stderr, "Options:")
        flag.PrintDefaults()
 }
 
 func main() {
        var (
                cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               doTmp     = flag.Bool("tmp", false, "Remove all temporary files")
+               doLock    = flag.Bool("lock", false, "Remove all lock files")
+               nodeRaw   = flag.String("node", "", "Node to remove files in")
+               doRx      = flag.Bool("rx", false, "Process received packets")
+               doTx      = flag.Bool("tx", false, "Process transfered packets")
+               doPart    = flag.Bool("part", false, "Remove only .part files")
+               doSeen    = flag.Bool("seen", false, "Remove only .seen files")
+               pktRaw    = flag.String("pkt", "", "Packet to remove")
                spoolPath = flag.String("spool", "", "Override path to spool")
-               logPath   = flag.String("log", "", "Override path to logfile")
                quiet     = flag.Bool("quiet", false, "Print only errors")
                debug     = flag.Bool("debug", false, "Print debug messages")
                version   = flag.Bool("version", false, "Print version information")
@@ -56,36 +68,72 @@ func main() {
                fmt.Println(nncp.VersionGet())
                return
        }
-       if flag.NArg() != 2 {
-               usage()
-               os.Exit(1)
-       }
 
-       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, "", *quiet, *debug)
        if err != nil {
                log.Fatalln("Error during initialization:", err)
        }
 
-       node, err := ctx.FindNode(flag.Arg(0))
+       if *doTmp {
+               err = filepath.Walk(filepath.Join(ctx.Spool, "tmp"), func(path string, info os.FileInfo, err error) error {
+                       if err != nil {
+                               return err
+                       }
+                       return os.Remove(info.Name())
+               })
+               if err != nil {
+                       log.Fatalln("Error during walking:", err)
+               }
+               return
+       }
+       if *doLock {
+               err = filepath.Walk(ctx.Spool, func(path string, info os.FileInfo, err error) error {
+                       if err != nil {
+                               return err
+                       }
+                       if strings.HasSuffix(info.Name(), ".lock") {
+                               return os.Remove(info.Name())
+                       }
+                       return nil
+               })
+               if err != nil {
+                       log.Fatalln("Error during walking:", err)
+               }
+               return
+       }
+       if *nodeRaw == "" {
+               usage()
+               os.Exit(1)
+       }
+       node, err := ctx.FindNode(*nodeRaw)
        if err != nil {
-               log.Fatalln("Invalid NODE specified:", err)
+               log.Fatalln("Invalid -node specified:", err)
        }
-
-       pktName := flag.Arg(1)
-       remove := func(xx nncp.TRxTx) bool {
-               for job := range ctx.Jobs(node.Id, xx) {
-                       job.Fd.Close()
-                       if filepath.Base(job.Fd.Name()) == pktName {
-                               if err = os.Remove(job.Fd.Name()); err != nil {
-                                       log.Fatalln("Can not remove packet:", err)
-                               }
-                               return true
+       remove := func(xx nncp.TRxTx) error {
+               return filepath.Walk(filepath.Join(ctx.Spool, node.Id.String(), string(xx)), func(path string, info os.FileInfo, err error) error {
+                       if err != nil {
+                               return err
+                       }
+                       if *doSeen && strings.HasSuffix(info.Name(), nncp.SeenSuffix) {
+                               return os.Remove(info.Name())
                        }
+                       if *doPart && strings.HasSuffix(info.Name(), nncp.PartSuffix) {
+                               return os.Remove(info.Name())
+                       }
+                       if *pktRaw == "" || filepath.Base(info.Name()) == *pktRaw {
+                               return os.Remove(info.Name())
+                       }
+                       return nil
+               })
+       }
+       if *pktRaw != "" || *doRx {
+               if err = remove(nncp.TRx); err != nil {
+                       log.Fatalln("Can not remove:", err)
                }
-               return false
        }
-
-       if !(remove(nncp.TRx) || remove(nncp.TTx)) {
-               log.Fatalln("Have not found specified packet")
+       if *pktRaw != "" || *doTx {
+               if err = remove(nncp.TTx); err != nil {
+                       log.Fatalln("Can not remove:", err)
+               }
        }
 }