+ 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 {
+ if err != nil {
+ if errors.Is(err, fs.ErrNotExist) {
+ return nil
+ }