2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // Remove packet from the queue
34 fmt.Fprintf(os.Stderr, nncp.UsageHeader())
35 fmt.Fprintln(os.Stderr, "nncp-rm -- remove packet\n")
36 fmt.Fprintf(os.Stderr, "Usage: %s [options] -tmp\n", os.Args[0])
37 fmt.Fprintf(os.Stderr, " %s [options] -lock\n", os.Args[0])
38 fmt.Fprintf(os.Stderr, " %s [options] -node NODE [-rx] [-tx] [-part] [-seen]\n", os.Args[0])
39 fmt.Fprintf(os.Stderr, " %s [options] -node NODE -pkt PKT\n", os.Args[0])
40 fmt.Fprintln(os.Stderr, "Options:")
46 cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
47 doTmp = flag.Bool("tmp", false, "Remove all temporary files")
48 doLock = flag.Bool("lock", false, "Remove all lock files")
49 nodeRaw = flag.String("node", "", "Node to remove files in")
50 doRx = flag.Bool("rx", false, "Process received packets")
51 doTx = flag.Bool("tx", false, "Process transfered packets")
52 doPart = flag.Bool("part", false, "Remove only .part files")
53 doSeen = flag.Bool("seen", false, "Remove only .seen files")
54 pktRaw = flag.String("pkt", "", "Packet to remove")
55 spoolPath = flag.String("spool", "", "Override path to spool")
56 quiet = flag.Bool("quiet", false, "Print only errors")
57 debug = flag.Bool("debug", false, "Print debug messages")
58 version = flag.Bool("version", false, "Print version information")
59 warranty = flag.Bool("warranty", false, "Print warranty information")
64 fmt.Println(nncp.Warranty)
68 fmt.Println(nncp.VersionGet())
72 ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, "", *quiet, *debug)
74 log.Fatalln("Error during initialization:", err)
78 err = filepath.Walk(filepath.Join(ctx.Spool, "tmp"), func(path string, info os.FileInfo, err error) error {
82 return os.Remove(info.Name())
85 log.Fatalln("Error during walking:", err)
90 err = filepath.Walk(ctx.Spool, func(path string, info os.FileInfo, err error) error {
94 if strings.HasSuffix(info.Name(), ".lock") {
95 return os.Remove(info.Name())
100 log.Fatalln("Error during walking:", err)
108 node, err := ctx.FindNode(*nodeRaw)
110 log.Fatalln("Invalid -node specified:", err)
112 remove := func(xx nncp.TRxTx) error {
113 return filepath.Walk(filepath.Join(ctx.Spool, node.Id.String(), string(xx)), func(path string, info os.FileInfo, err error) error {
117 if *doSeen && strings.HasSuffix(info.Name(), nncp.SeenSuffix) {
118 return os.Remove(info.Name())
120 if *doPart && strings.HasSuffix(info.Name(), nncp.PartSuffix) {
121 return os.Remove(info.Name())
123 if *pktRaw == "" || filepath.Base(info.Name()) == *pktRaw {
124 return os.Remove(info.Name())
129 if *pktRaw != "" || *doRx {
130 if err = remove(nncp.TRx); err != nil {
131 log.Fatalln("Can not remove:", err)
134 if *pktRaw != "" || *doTx {
135 if err = remove(nncp.TTx); err != nil {
136 log.Fatalln("Can not remove:", err)