+ removeSub := func(p string) error {
+ return filepath.Walk(p, func(
+ path string, info os.FileInfo, err error,
+ ) error {
+ if err != nil {
+ if errors.Is(err, fs.ErrNotExist) {
+ return nil
+ }
+ 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
+ }
+ 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 len(pkts) > 0 || *doSeen {
+ if err = removeSub(filepath.Join(
+ ctx.Spool, node.Id.String(), string(nncp.TRx), nncp.SeenDir,
+ )); err != nil {
+ log.Fatalln("Can not remove:", err)
+ }
+ }
+ if *doRx && *doHdr {
+ if err = removeSub(filepath.Join(
+ ctx.Spool, node.Id.String(), string(nncp.TRx), nncp.HdrDir,
+ )); err != nil {
+ log.Fatalln("Can not remove:", err)
+ }
+ }
+ if *doTx && *doHdr {
+ if err = removeSub(filepath.Join(
+ ctx.Spool, node.Id.String(), string(nncp.TTx), nncp.HdrDir,
+ )); err != nil {
+ log.Fatalln("Can not remove:", err)
+ }
+ }