@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
"log"
"os"
"path/filepath"
+ "strings"
"cypherpunks.ru/nncp"
)
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")
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)
+ }
}
}