+ 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
+ }
+ }
+ }