]> Cypherpunks.ru repositories - nncp.git/commitdiff
nncp-rm -pkt takes list of packets from stdin
authorSergey Matveev <stargrave@stargrave.org>
Fri, 4 Mar 2022 10:43:40 +0000 (13:43 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 4 Mar 2022 13:47:21 +0000 (16:47 +0300)
doc/cmd/nncp-rm.texi
doc/news.ru.texi
doc/news.texi
src/cmd/nncp-ack/main.go
src/cmd/nncp-rm/main.go

index 4c74f0aa1fb5b0bd12b1ec605c99ba4a581dc26a..02676732165fcc136374e3163dc3f7640d061113 100644 (file)
@@ -11,7 +11,12 @@ $ nncp-rm [options] @{-all|-node NODE@} -nock
 $ nncp-rm [options] @{-all|-node NODE@} -hdr
 $ nncp-rm [options] @{-all|-node NODE@} -area
 $ nncp-rm [options] @{-all|-node NODE@} [-rx] [-tx]
-$ nncp-rm [options] @{-all|-node NODE@} -pkt PKT
+$ nncp-rm [options] @{-all|-node NODE@} -pkt <<EOF
+PKT1
+PKT2
+NODEx/PKT3
+@dots{}
+EOF
 @end example
 
 This command is aimed to delete various files from your spool directory:
@@ -25,9 +30,10 @@ commands like @command{@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 If @option{-pkt} option is specified, then list of packets (Base32
+names) toe be deleted is read from @code{stdin}. This could be useful
+when you see some packet failing to be processed. Packet identifiers
+could have "directories" prepended, that are ignored.
 
 @item When either @option{-rx} or @option{-tx} options are specified
 (maybe both of them), then delete all packets from that given queues.
index f4bdb57ba46e02510d0fd8156f44e3fee2d3d37f..2570db19631487085387befa5e822093862ad5dc 100644 (file)
 @item
 В прошлом, @command{nncp-ack} не удаляла соответствующие @file{hdr/} файлы.
 
+@item
+@command{nncp-rm} теперь берёт список пакетов из @code{stdin}, при
+использовании @option{-pkt} опции.
+
 @end itemize
 
 @node Релиз 8.6.0
index 33d5384fbe6db6bf0231316a820af0f767bc5c40..393f160e1b90daabffa3dc2f751f1712e3a213f1 100644 (file)
@@ -15,6 +15,10 @@ endless loop of ACKs.
 @item
 @command{nncp-ack} previously did not remove corresponding @file{hdr/} files.
 
+@item
+@command{nncp-rm} now takes list of packet from @code{stdin} when
+@option{-pkt} option is used.
+
 @end itemize
 
 @node Release 8_6_0
index 950295a7d81029f7b8b4dfc11815b454d0ea4d42..370026f377fe95ff3fcad179e2525be9af483b74 100644 (file)
@@ -37,8 +37,8 @@ func usage() {
        fmt.Fprintf(os.Stderr, nncp.UsageHeader())
        fmt.Fprintf(os.Stderr, "nncp-ack -- send packet receipt acknowledgement\n\n")
        fmt.Fprintf(os.Stderr, "Usage: %s [options] -all\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "Usage: %s           -node NODE[,...]\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "Usage: %s           -node NODE -pkt PKT\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options] -node NODE[,...]\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options] -node NODE -pkt PKT\n", os.Args[0])
        fmt.Fprintln(os.Stderr, "Options:")
        flag.PrintDefaults()
 }
index 67f66574f1a9c5d48ced22f41c7a263c1861e306..814028c74cc0a23002489d9f590e43bb35bc38e3 100644 (file)
@@ -21,6 +21,7 @@ package main
 import (
        "flag"
        "fmt"
+       "io"
        "log"
        "os"
        "path/filepath"
@@ -43,7 +44,7 @@ func usage() {
        fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} -hdr\n", os.Args[0])
        fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} -area\n", os.Args[0])
        fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} {-rx|-tx}\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} -pkt PKT\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} -pkt < ...\n", os.Args[0])
        fmt.Fprintln(os.Stderr, "-older option's time units are: (s)econds, (m)inutes, (h)ours, (d)ays")
        fmt.Fprintln(os.Stderr, "Options:")
        flag.PrintDefaults()
@@ -65,7 +66,7 @@ func main() {
                doArea    = flag.Bool("area", false, "Remove only area/* seen files")
                older     = flag.String("older", "", "XXX{smhd}: only older than XXX number of time units")
                dryRun    = flag.Bool("dryrun", false, "Do not actually remove files")
-               pktRaw    = flag.String("pkt", "", "Packet to remove")
+               doPkt     = flag.Bool("pkt", false, "Packet to remove TODO")
                spoolPath = flag.String("spool", "", "Override path to spool")
                quiet     = flag.Bool("quiet", false, "Print only errors")
                debug     = flag.Bool("debug", false, "Print debug messages")
@@ -114,6 +115,21 @@ func main() {
        }
        oldBoundary := time.Second * time.Duration(oldBoundaryRaw)
 
+       pkts := make(map[string]struct{})
+       if *doPkt {
+               raw, err := io.ReadAll(os.Stdin)
+               if err != nil {
+                       log.Fatalln("can not read -pkt from stdin:", err)
+               }
+               for _, line := range strings.Split(string(raw), "\n") {
+                       if len(line) == 0 {
+                               continue
+                       }
+                       cols := strings.Split(line, "/")
+                       pkts[cols[len(cols)-1]] = struct{}{}
+               }
+       }
+
        now := time.Now()
        if *doTmp {
                err = filepath.Walk(
@@ -215,12 +231,14 @@ func main() {
                                                }
                                                return os.Remove(path)
                                        }
-                                       if *pktRaw != "" && filepath.Base(info.Name()) == *pktRaw {
-                                               ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
-                                               if *dryRun {
-                                                       return nil
+                                       if len(pkts) > 0 {
+                                               if _, exists := pkts[filepath.Base(info.Name())]; exists {
+                                                       ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
+                                                       if *dryRun {
+                                                               return nil
+                                                       }
+                                                       return os.Remove(path)
                                                }
-                                               return os.Remove(path)
                                        }
                                        if !*doSeen && !*doNoCK && !*doHdr && !*doPart &&
                                                (*doRx || *doTx) &&
@@ -234,12 +252,12 @@ func main() {
                                        return nil
                                })
                }
-               if *pktRaw != "" || *doRx || *doNoCK || *doPart {
+               if len(pkts) > 0 || *doRx || *doNoCK || *doPart {
                        if err = remove(nncp.TRx); err != nil {
                                log.Fatalln("Can not remove:", err)
                        }
                }
-               if *pktRaw != "" || *doTx || *doHdr {
+               if len(pkts) > 0 || *doTx || *doHdr {
                        if err = remove(nncp.TTx); err != nil {
                                log.Fatalln("Can not remove:", err)
                        }
@@ -315,9 +333,12 @@ func main() {
                                                return nil
                                        }
                                        if now.Sub(info.ModTime()) < oldBoundary {
-                                               ctx.LogD("rm-skip", nncp.LEs{{K: "File", V: path}}, func(les nncp.LEs) string {
-                                                       return fmt.Sprintf("File %s: too fresh, skipping", path)
-                                               })
+                                               ctx.LogD(
+                                                       "rm-skip", nncp.LEs{{K: "File", V: path}},
+                                                       func(les nncp.LEs) string {
+                                                               return fmt.Sprintf("File %s: too fresh, skipping", path)
+                                                       },
+                                               )
                                                return nil
                                        }
                                        ctx.LogI(