+
+ for _, node := range ctx.Neigh {
+ if nodeId != nil && node.Id != nodeId {
+ continue
+ }
+ remove := func(xx nncp.TRxTx) error {
+ p := filepath.Join(ctx.Spool, node.Id.String(), string(xx))
+ if _, err := os.Stat(p); err != nil && os.IsNotExist(err) {
+ return nil
+ }
+ 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
+ }
+ 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", 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: pth}}, func(les nncp.LEs) string {
+ return fmt.Sprintf("File %s: too fresh, skipping", pth)
+ })
+ continue
+ }
+ 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 {
+ continue
+ }
+ 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: pth}}, logMsg)
+ if *dryRun {
+ continue
+ }
+ os.Remove(nncp.JobPath2Hdr(pth))
+ if err = os.Remove(pth); err != nil {
+ return err
+ }
+ }
+ }
+ }
+ 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 {
+ if err = remove(nncp.TTx); err != nil {
+ log.Fatalln("Can not remove:", err)
+ }
+ }
+ removeSub := func(p string) error {
+ return filepath.Walk(p, func(path string, info os.FileInfo, err error) error {