]> Cypherpunks.ru repositories - nncp.git/commitdiff
Refactored and tested nncp-rm
authorSergey Matveev <stargrave@stargrave.org>
Sun, 13 Mar 2022 08:38:22 +0000 (11:38 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 13 Mar 2022 13:17:12 +0000 (16:17 +0300)
doc/cmd/nncp-rm.texi
doc/news.ru.texi
doc/news.texi
src/cmd/nncp-rm/main.go
src/nncp.go
t/nncp-rm.t [new file with mode: 0755]

index 02676732165fcc136374e3163dc3f7640d061113..4444c3347dcd81a932bfcc77b89d44cf78f2d412 100644 (file)
@@ -3,15 +3,14 @@
 @section nncp-rm
 
 @example
-$ nncp-rm [options] -tmp
+$ nncp-rm [options] [-older X] -tmp
 $ nncp-rm [options] -lock
-$ nncp-rm [options] @{-all|-node NODE@} -part
-$ nncp-rm [options] @{-all|-node NODE@} -seen
-$ 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 <<EOF
+$ nncp-rm [options] [-older X] @{-all|-node NODE@} -part
+$ nncp-rm [options] [-older X] @{-all|-node NODE@} -seen
+$ nncp-rm [options] [-older X] @{-all|-node NODE@} -nock
+$ nncp-rm [options] [-older X] @{-all|-node NODE@} -area
+$ nncp-rm [options] [-older X] @{-all|-node NODE@} @{-rx|-tx@} [-hdr]
+$ nncp-rm [options] [-older X] @{-all|-node NODE@} -pkt <<EOF
 PKT1
 PKT2
 NODEx/PKT3
@@ -19,32 +18,34 @@ NODEx/PKT3
 EOF
 @end example
 
-This command is aimed to delete various files from your spool directory:
+This command is aimed to delete various files from your spool directory.
+@option{-older} option may limit the subset of files to be deleted for
+most commands.
 
 @itemize
 
-@item If @option{-tmp} option is specified, then it will delete all
+@item If @option{-tmp} option is specified, then it will delete
 temporary files in @file{spool/tmp} directory. Files may stay in it when
 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 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 If @option{-pkt} option is specified, then only the specified list
+of packets (Base32 names) will be deleted. It is read from @code{stdin}.
+This could be useful when you see some packet failing to be processed.
+Packet identifiers may 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.
+@item @option{-rx} and @option{-tx} options will delete packets in
+corresponding queue directories. Corresponding @file{hdr/} files are
+also automatically deleted.
 
-@item @option{-part} option deletes @file{.part}ly downloaded files.
+@item @option{-part} option limits that to @file{.part}ly downloaded packets.
 
-@item @option{-seen} option deletes @file{seen/} files. But it does not
-apply to @ref{Multicast, multicast areas} ones!
+@item @option{-nock} option limits that to non-checksummed
+(non-verified) @file{.nock} files.
 
-@item @option{-nock} option deletes non-checksummed (non-verified)
-@file{.nock} files.
+@item @option{-seen} option deletes @file{seen/} files.
 
 @item @option{-hdr} option deletes cached @file{hdr/} files.
 
@@ -54,6 +55,11 @@ apply to @ref{Multicast, multicast areas} ones!
 
 @option{-dryrun} option just prints what will be deleted.
 
-You can also select files that only have modification date older than specified
-@option{-older} time units (@code{10s} (10 seconds), @code{5m} (5 minutes),
-@code{12h} (12 hours), @code{2d} (2 days)).
+@option{-older} accepts an integer with appended time unit:
+
+@itemize
+@item @code{10s} -- 10 seconds
+@item @code{5m} -- 5 minutes
+@item @code{12h} -- 12 hours
+@item @code{2d} -- 2 days
+@end itemize
index cd8659532d8987f769e550236d9e2793823c80f2..bfc287c6221bf099c658a48d3604a6f28402c157 100644 (file)
@@ -1,6 +1,19 @@
 @node Новости
 @section Новости
 
+@node Релиз 8.7.2
+@subsection Релиз 8.7.2
+@itemize
+
+@item
+Более интуитивное, понятное и немного более гибкое поведение @command{nncp-rm}.
+
+@item
+@command{nncp-rm} также удаляет соответствующий @file{hdr/} файл для
+каждого удалённого пакета.
+
+@end itemize
+
 @node Релиз 8.7.1
 @subsection Релиз 8.7.1
 @itemize
index 9b0e59590f9239361682d194e3de049435aa8912..326308a808397de059a281e7cc20c763e46e7245 100644 (file)
@@ -4,6 +4,19 @@
 
 See also this page @ref{Новости, on russian}.
 
+@node Release 8_7_2
+@section Release 8.7.2
+@itemize
+
+@item
+More intuitive, clear and slightly more flexible behaviour of @command{nncp-rm}.
+
+@item
+@command{nncp-rm} also removes corresponding @file{hdr/} file for each
+removed packet.
+
+@end itemize
+
 @node Release 8_7_1
 @section Release 8.7.1
 @itemize
index 814028c74cc0a23002489d9f590e43bb35bc38e3..ef6c44d287f7e27e38b2488997b742e004b0925c 100644 (file)
@@ -36,15 +36,14 @@ import (
 func usage() {
        fmt.Fprintf(os.Stderr, nncp.UsageHeader())
        fmt.Fprintf(os.Stderr, "nncp-rm -- remove packet\n\n")
-       fmt.Fprintf(os.Stderr, "Usage: %s [options] -tmp\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options] [-older X] -tmp\n", os.Args[0])
        fmt.Fprintf(os.Stderr, "       %s [options] -lock\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} -part\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} -seen\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "       %s [options] {-all|-node NODE} -nock\n", os.Args[0])
-       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 < ...\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] [-older X] {-all|-node NODE} -part\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] [-older X] {-all|-node NODE} -seen\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] [-older X] {-all|-node NODE} -nock\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] [-older X] {-all|-node NODE} -area\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] [-older X] {-all|-node NODE} {-rx|-tx} [-hdr]\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "       %s [options] [-older X] {-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()
@@ -53,20 +52,20 @@ func usage() {
 func main() {
        var (
                cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               doAll     = flag.Bool("all", false, "Apply remove rules to all nodes")
-               doTmp     = flag.Bool("tmp", false, "Remove all temporary files")
-               doHdr     = flag.Bool("hdr", false, "Remove all hdr/ files")
+               doTmp     = flag.Bool("tmp", false, "Remove 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")
+               doAll     = flag.Bool("all", false, "Process all nodes")
+               nodeRaw   = flag.String("node", "", "Process only that node")
+               doRx      = flag.Bool("rx", false, "Process inbound packets")
+               doTx      = flag.Bool("tx", false, "Process outbound packets")
                doPart    = flag.Bool("part", false, "Remove only .part files")
                doSeen    = flag.Bool("seen", false, "Remove only seen/ files")
                doNoCK    = flag.Bool("nock", false, "Remove only .nock files")
+               doHdr     = flag.Bool("hdr", false, "Remove only hdr/ files")
                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")
-               doPkt     = flag.Bool("pkt", false, "Packet to remove TODO")
+               doPkt     = flag.Bool("pkt", false, "Remove only that packets")
                spoolPath = flag.String("spool", "", "Override path to spool")
                quiet     = flag.Bool("quiet", false, "Print only errors")
                debug     = flag.Bool("debug", false, "Print debug messages")
@@ -121,7 +120,7 @@ func main() {
                if err != nil {
                        log.Fatalln("can not read -pkt from stdin:", err)
                }
-               for _, line := range strings.Split(string(raw), "\n") {
+               for _, line := range strings.Fields(string(raw)) {
                        if len(line) == 0 {
                                continue
                        }
@@ -160,6 +159,7 @@ func main() {
                }
                return
        }
+
        if *doLock {
                err = filepath.Walk(ctx.Spool, func(path string, info os.FileInfo, err error) error {
                        if err != nil {
@@ -184,6 +184,7 @@ func main() {
                }
                return
        }
+
        var nodeId *nncp.NodeId
        if *nodeRaw == "" {
                if !*doAll {
@@ -197,6 +198,7 @@ func main() {
                }
                nodeId = node.Id
        }
+
        for _, node := range ctx.Neigh {
                if nodeId != nil && node.Id != nodeId {
                        continue
@@ -206,116 +208,146 @@ func main() {
                        if _, err := os.Stat(p); err != nil && os.IsNotExist(err) {
                                return nil
                        }
-                       return filepath.Walk(p,
-                               func(path string, info os.FileInfo, err error) error {
-                                       if err != nil {
-                                               return err
+                       dir, err := os.Open(p)
+                       if err != nil {
+                               if os.IsNotExist(err) {
+                                       return nil
+                               }
+                               return err
+                       }
+                       defer dir.Close()
+                       for {
+                               entries, err := dir.ReadDir(1 << 10)
+                               if err != nil {
+                                       if err == io.EOF {
+                                               break
                                        }
-                                       if info.IsDir() {
-                                               return nil
+                                       return err
+                               }
+                               for _, entry := range entries {
+                                       if entry.IsDir() {
+                                               continue
                                        }
+                                       pth := filepath.Join(p, entry.Name())
                                        logMsg := func(les nncp.LEs) string {
-                                               return fmt.Sprintf("File %s: removed", path)
+                                               return fmt.Sprintf("File %s: removed", pth)
+                                       }
+                                       if len(pkts) > 0 {
+                                               if _, exists := pkts[filepath.Base(entry.Name())]; exists {
+                                                       ctx.LogI("rm", nncp.LEs{{K: "File", V: pth}}, logMsg)
+                                                       if !*dryRun {
+                                                               os.Remove(nncp.JobPath2Hdr(pth))
+                                                               if err = os.Remove(pth); err != nil {
+                                                                       return err
+                                                               }
+                                                       }
+                                               }
+                                               continue
+                                       }
+                                       info, err := entry.Info()
+                                       if err != nil {
+                                               return err
                                        }
                                        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: pth}}, func(les nncp.LEs) string {
+                                                       return fmt.Sprintf("File %s: too fresh, skipping", pth)
                                                })
-                                               return nil
+                                               continue
                                        }
-                                       if (*doNoCK && strings.HasSuffix(info.Name(), nncp.NoCKSuffix)) ||
-                                               (*doPart && strings.HasSuffix(info.Name(), nncp.PartSuffix)) {
-                                               ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
+                                       if (*doNoCK && strings.HasSuffix(entry.Name(), nncp.NoCKSuffix)) ||
+                                               (*doPart && strings.HasSuffix(entry.Name(), nncp.PartSuffix)) {
+                                               ctx.LogI("rm", nncp.LEs{{K: "File", V: pth}}, logMsg)
                                                if *dryRun {
-                                                       return nil
+                                                       continue
                                                }
-                                               return os.Remove(path)
-                                       }
-                                       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)
+                                               if err = os.Remove(pth); err != nil {
+                                                       return err
                                                }
                                        }
                                        if !*doSeen && !*doNoCK && !*doHdr && !*doPart &&
                                                (*doRx || *doTx) &&
                                                ((*doRx && xx == nncp.TRx) || (*doTx && xx == nncp.TTx)) {
-                                               ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
+                                               ctx.LogI("rm", nncp.LEs{{K: "File", V: pth}}, logMsg)
                                                if *dryRun {
-                                                       return nil
+                                                       continue
+                                               }
+                                               os.Remove(nncp.JobPath2Hdr(pth))
+                                               if err = os.Remove(pth); err != nil {
+                                                       return err
                                                }
-                                               return os.Remove(path)
                                        }
-                                       return nil
-                               })
+                               }
+                       }
+                       return nil
                }
                if len(pkts) > 0 || *doRx || *doNoCK || *doPart {
                        if err = remove(nncp.TRx); err != nil {
                                log.Fatalln("Can not remove:", err)
                        }
                }
-               if len(pkts) > 0 || *doTx || *doHdr {
+               if len(pkts) > 0 || *doTx {
                        if err = remove(nncp.TTx); err != nil {
                                log.Fatalln("Can not remove:", err)
                        }
                }
-               removeSub := func(p string, everything bool) error {
-                       return filepath.Walk(
-                               p, func(path string, info os.FileInfo, err error) error {
-                                       if err != nil {
-                                               if os.IsNotExist(err) {
-                                                       return nil
-                                               }
-                                               return err
-                                       }
-                                       if info.IsDir() {
+               removeSub := func(p string) error {
+                       return filepath.Walk(p, func(path string, info os.FileInfo, err error) error {
+                               if err != nil {
+                                       if os.IsNotExist(err) {
                                                return nil
                                        }
-                                       logMsg := func(les nncp.LEs) string {
-                                               return fmt.Sprintf("File %s: removed", path)
-                                       }
-                                       if everything {
-                                               ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
-                                               if *dryRun {
-                                                       return nil
-                                               }
-                                               return os.Remove(path)
+                                       return err
+                               }
+                               if info.IsDir() {
+                                       return nil
+                               }
+                               logMsg := func(les nncp.LEs) string {
+                                       return fmt.Sprintf("File %s: removed", path)
+                               }
+                               if len(pkts) > 0 {
+                                       if _, exists := pkts[filepath.Base(info.Name())]; !exists {
+                                               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)
-                                                       },
-                                               )
-                                       } else if !*dryRun {
-                                               return os.Remove(path)
+                                       ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
+                                       if *dryRun {
+                                               return nil
                                        }
+                                       return os.Remove(path)
+                               }
+                               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)
+                                               },
+                                       )
                                        return nil
-                               },
-                       )
+                               }
+                               ctx.LogI("rm", nncp.LEs{{K: "File", V: path}}, logMsg)
+                               if *dryRun {
+                                       return nil
+                               }
+                               return os.Remove(path)
+                       })
                }
-               if *doRx || *doSeen {
+               if len(pkts) > 0 || *doSeen {
                        if err = removeSub(filepath.Join(
                                ctx.Spool, node.Id.String(), string(nncp.TRx), nncp.SeenDir,
-                       ), *doSeen); err != nil {
+                       )); err != nil {
                                log.Fatalln("Can not remove:", err)
                        }
                }
-               if *doRx || *doHdr {
+               if *doRx && *doHdr {
                        if err = removeSub(filepath.Join(
                                ctx.Spool, node.Id.String(), string(nncp.TRx), nncp.HdrDir,
-                       ), *doHdr); err != nil {
+                       )); err != nil {
                                log.Fatalln("Can not remove:", err)
                        }
                }
-               if *doTx || *doHdr {
+               if *doTx && *doHdr {
                        if err = removeSub(filepath.Join(
                                ctx.Spool, node.Id.String(), string(nncp.TTx), nncp.HdrDir,
-                       ), *doHdr); err != nil {
+                       )); err != nil {
                                log.Fatalln("Can not remove:", err)
                        }
                }
index 2647e4c891389d775019ccefce4d0a4fa446cc3e..e51f92528d15bd1022b16046b4f902ed2b3e755e 100644 (file)
@@ -40,7 +40,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.`
 const Base32Encoded32Len = 52
 
 var (
-       Version string = "8.7.1"
+       Version string = "8.7.2"
 
        Base32Codec *base32.Encoding = base32.StdEncoding.WithPadding(base32.NoPadding)
 )
diff --git a/t/nncp-rm.t b/t/nncp-rm.t
new file mode 100755 (executable)
index 0000000..aa7cc83
--- /dev/null
@@ -0,0 +1,278 @@
+#!/bin/sh
+
+testname=`basename "$0"`
+test_description="nncp-rm's behaviour"
+. $SHARNESS_TEST_SRCDIR/sharness.sh
+
+rand32() {
+    perl <<EOF
+open(\$rnd, "<", "/dev/urandom") or die \$!;
+read(\$rnd, \$data, 32) or die \$!;
+use MIME::Base32;
+print MIME::Base32::encode \$data;
+print "\n";
+EOF
+}
+
+randpkts() {
+    for i in $(seq $(jot -r 1 10 20)) ; do rand32 ; done
+}
+
+PKTS=""
+pkts_remove() {
+    perl <<EOF
+map { \$all{\$_} = 1 } qw($PKTS);
+map { delete \$all{\$_} } qw($@);
+print join " ", keys %all;
+EOF
+}
+
+assert_is_deleted() {
+    for pkt in $@ ; do
+        if [ -e $pkt ] ; then
+            echo unexpectedly existing: $pkt >&2
+            return 1
+        fi
+    done
+    local pkts=""
+    for pkt in `pkts_remove $@` ; do
+        if ! [ -e $pkt ] ; then
+            echo unexpectedly removed: $pkt >&2
+            return 1
+        fi
+        pkts="$pkts $pkt"
+    done
+    PKTS="$pkts"
+}
+
+now=`date +%s`
+nncp-cfgnew > cfg
+nncp-cfgdir -cfg cfg -dump cfgdir
+echo "$PWD/spool" > cfgdir/spool
+echo "$PWD/log" > cfgdir/log
+neigh=`rand32`
+mkdir -p cfgdir/neigh/neigh
+for w in id exchpub signpub ; do echo $neigh > cfgdir/neigh/neigh/$w ; done
+mkdir -p spool/tmp spool/$neigh/rx/hdr spool/$neigh/rx/seen spool/$neigh/tx/hdr
+date_old=$(date -j -f %s +%FT%T $(( $now - (3600 * 24 * 7) )))
+
+pkts_old_rx=""
+pkts_old_rx_hdr=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/$neigh/rx/$pkt spool/$neigh/rx/hdr/$pkt
+    pkts_old_rx="$pkts_old_rx spool/$neigh/rx/$pkt"
+    pkts_old_rx_hdr="$pkts_old_rx_hdr spool/$neigh/rx/hdr/$pkt"
+done
+
+pkts_old_tx=""
+pkts_old_tx_hdr=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/$neigh/tx/$pkt spool/$neigh/tx/hdr/$pkt
+    pkts_old_tx="$pkts_old_tx spool/$neigh/tx/$pkt"
+    pkts_old_tx_hdr="$pkts_old_tx_hdr spool/$neigh/tx/hdr/$pkt"
+done
+
+pkts_old_part=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/$neigh/rx/$pkt.part
+    pkts_old_part="$pkts_old_part spool/$neigh/rx/$pkt.part"
+done
+
+pkts_old_nock=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/$neigh/rx/$pkt.nock
+    pkts_old_nock="$pkts_old_nock spool/$neigh/rx/$pkt.nock"
+done
+
+pkts_old_seen=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/$neigh/rx/seen/$pkt
+    pkts_old_seen="$pkts_old_seen spool/$neigh/rx/seen/$pkt"
+done
+
+pkts_new_rx=""
+pkts_new_rx_hdr=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/rx/$pkt spool/$neigh/rx/hdr/$pkt
+    pkts_new_rx="$pkts_new_rx spool/$neigh/rx/$pkt"
+    pkts_new_rx_hdr="$pkts_new_rx_hdr spool/$neigh/rx/hdr/$pkt"
+done
+
+pkts_new_tx=""
+pkts_new_tx_hdr=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/tx/$pkt spool/$neigh/tx/hdr/$pkt
+    pkts_new_tx="$pkts_new_tx spool/$neigh/tx/$pkt"
+    pkts_new_tx_hdr="$pkts_new_tx_hdr spool/$neigh/tx/hdr/$pkt"
+done
+
+pkts_new_part=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/rx/$pkt.part
+    pkts_new_part="$pkts_new_part spool/$neigh/rx/$pkt.part"
+done
+
+pkts_new_nock=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/rx/$pkt.nock
+    pkts_new_nock="$pkts_new_nock spool/$neigh/rx/$pkt.nock"
+done
+
+pkts_new_seen=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/rx/seen/$pkt
+    pkts_new_seen="$pkts_new_seen spool/$neigh/rx/seen/$pkt"
+done
+
+pkts_tmp_old=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/tmp/$pkt
+    pkts_tmp_old="$pkts_tmp_old spool/tmp/$pkt"
+done
+
+pkts_tmp_new=""
+for pkt in `randpkts` ; do
+    touch spool/tmp/$pkt
+    pkts_tmp_new="$pkts_tmp_new spool/tmp/$pkt"
+done
+
+pkts_hdr_excess_old_rx=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/$neigh/rx/hdr/$pkt
+    pkts_hdr_excess_old_rx="$pkts_hdr_excess_old_rx spool/$neigh/rx/hdr/$pkt"
+done
+
+pkts_hdr_excess_old_tx=""
+for pkt in `randpkts` ; do
+    touch -d $date_old spool/$neigh/tx/hdr/$pkt
+    pkts_hdr_excess_old_tx="$pkts_hdr_excess_old_tx spool/$neigh/tx/hdr/$pkt"
+done
+
+pkts_hdr_excess_new_rx=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/rx/hdr/$pkt
+    pkts_hdr_excess_new_rx="$pkts_hdr_excess_new_rx spool/$neigh/rx/hdr/$pkt"
+done
+
+pkts_hdr_excess_new_tx=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/tx/hdr/$pkt
+    pkts_hdr_excess_new_tx="$pkts_hdr_excess_new_tx spool/$neigh/tx/hdr/$pkt"
+done
+
+pkts_area_old=""
+pkts_area_new=""
+for area in `randpkts` ; do
+    mkdir -p spool/$neigh/area/$area
+    for pkt in `randpkts` ; do
+        touch -d $date_old spool/$neigh/area/$area/$pkt
+        pkts_area_old="$pkts_area_old spool/$neigh/area/$area/$pkt"
+    done
+    for pkt in `randpkts` ; do
+        touch spool/$neigh/area/$area/$pkt
+        pkts_area_new="$pkts_area_new spool/$neigh/area/$area/$pkt"
+    done
+done
+
+pkts_specified=""
+for pkt in `randpkts` ; do
+    touch spool/$neigh/rx/$pkt
+    pkts_specified="$pkts_specified spool/$neigh/rx/$pkt"
+done
+for pkt in `randpkts` ; do
+    touch spool/$neigh/tx/$pkt
+    pkts_specified="$pkts_specified spool/$neigh/tx/$pkt"
+done
+for pkt in `randpkts` ; do
+    touch spool/$neigh/rx/seen/$pkt
+    pkts_specified="$pkts_specified spool/$neigh/rx/seen/$pkt"
+done
+
+PKTS="
+$pkts_old_rx
+$pkts_old_rx_hdr
+$pkts_old_tx
+$pkts_old_tx_hdr
+$pkts_old_part
+$pkts_old_nock
+$pkts_old_seen
+$pkts_new_rx
+$pkts_new_rx_hdr
+$pkts_new_tx
+$pkts_new_tx_hdr
+$pkts_new_part
+$pkts_new_nock
+$pkts_new_seen
+$pkts_tmp_old
+$pkts_tmp_new
+$pkts_hdr_excess_old_rx
+$pkts_hdr_excess_old_tx
+$pkts_hdr_excess_new_rx
+$pkts_hdr_excess_new_tx
+$pkts_area_old
+$pkts_area_new
+$pkts_specified
+"
+rmcmd="nncp-rm -quiet -cfg cfgdir -all"
+older="-older 6d"
+
+$rmcmd -pkt <<EOF
+$pkts_specified
+EOF
+test_expect_success "Only -pkt" "assert_is_deleted $pkts_specified"
+
+$rmcmd $older -tmp
+test_expect_success "Old -tmp" "assert_is_deleted $pkts_tmp_old"
+
+$rmcmd -tmp
+test_expect_success "All -tmp" "assert_is_deleted $pkts_tmp_new"
+
+$rmcmd $older -part
+test_expect_success "Old -part" "assert_is_deleted $pkts_old_part"
+
+$rmcmd -part
+test_expect_success "All -part" "assert_is_deleted $pkts_new_part"
+
+$rmcmd $older -nock
+test_expect_success "Old -nock" "assert_is_deleted $pkts_old_nock"
+
+$rmcmd -nock
+test_expect_success "All -nock" "assert_is_deleted $pkts_new_nock"
+
+$rmcmd $older -rx
+test_expect_success "Old -rx" "assert_is_deleted $pkts_old_rx $pkts_old_rx_hdr"
+
+$rmcmd $older -tx
+test_expect_success "Old -tx" "assert_is_deleted $pkts_old_tx $pkts_old_tx_hdr"
+
+$rmcmd -rx
+test_expect_success "All -rx" "assert_is_deleted $pkts_new_rx $pkts_new_rx_hdr"
+
+$rmcmd -tx
+test_expect_success "All -tx" "assert_is_deleted $pkts_new_tx $pkts_new_tx_hdr"
+
+$rmcmd $older -seen
+test_expect_success "Old -seen" "assert_is_deleted $pkts_old_seen"
+
+$rmcmd -seen
+test_expect_success "All -seen" "assert_is_deleted $pkts_new_seen"
+
+$rmcmd $older -rx -hdr
+test_expect_success "Old -rx -hdr" "assert_is_deleted $pkts_hdr_excess_old_rx"
+
+$rmcmd $older -tx -hdr
+test_expect_success "Old -tx -hdr" "assert_is_deleted $pkts_hdr_excess_old_tx"
+
+$rmcmd -rx -hdr
+test_expect_success "All -rx -hdr" "assert_is_deleted $pkts_hdr_excess_new_rx"
+
+$rmcmd -tx -hdr
+test_expect_success "All -tx -hdr" "assert_is_deleted $pkts_hdr_excess_new_tx"
+
+$rmcmd $older -area
+test_expect_success "Old -area" "assert_is_deleted $pkts_area_old"
+
+$rmcmd -area
+test_expect_success "All -area" "assert_is_deleted $pkts_area_new"
+
+test_done