)
const (
- SeenSuffix = ".seen"
+ SeenDir = "seen"
)
+func jobPath2Seen(jobPath string) string {
+ return filepath.Join(filepath.Dir(jobPath), SeenDir, filepath.Base(jobPath))
+}
+
func newNotification(fromTo *FromToJSON, subject string, body []byte) io.Reader {
lines := []string{
"From: " + fromTo.From,
} else {
cmd.Stdin = pipeR
}
- output, err := cmd.Output()
+ output, err := cmd.CombinedOutput()
if err != nil {
- ctx.LogE("rx-hande", les, err, func(les LEs) string {
+ les = append(les, LE{"Output", strings.Split(
+ strings.Trim(string(output), "\n"), "\n"),
+ })
+ ctx.LogE("rx-handle", les, err, func(les LEs) string {
return fmt.Sprintf(
"Tossing exec %s/%s (%s): %s: handling",
sender.Name, pktName,
})
if !dryRun && jobPath != "" {
if doSeen {
- if fd, err := os.Create(jobPath + SeenSuffix); err == nil {
+ if err := ensureDir(filepath.Dir(jobPath), SeenDir); err != nil {
+ return err
+ }
+ if fd, err := os.Create(jobPath2Seen(jobPath)); err == nil {
fd.Close()
if err = DirSync(filepath.Dir(jobPath)); err != nil {
ctx.LogE("rx-dirsync", les, err, func(les LEs) string {
})
return err
} else if ctx.HdrUsage {
- os.Remove(jobPath + HdrSuffix)
+ os.Remove(JobPath2Hdr(jobPath))
}
}
return err
}
if err = bufW.Flush(); err != nil {
- tmp.Close() // #nosec G104
+ tmp.Close()
ctx.LogE("rx-flush", les, err, func(les LEs) string {
return fmt.Sprintf(
"Tossing file %s/%s (%s): %s: flushing",
return err
}
if err = tmp.Sync(); err != nil {
- tmp.Close() // #nosec G104
+ tmp.Close()
ctx.LogE("rx-sync", les, err, func(les LEs) string {
return fmt.Sprintf(
"Tossing file %s/%s (%s): %s: syncing",
if !dryRun {
if jobPath != "" {
if doSeen {
- if fd, err := os.Create(jobPath + SeenSuffix); err == nil {
+ if err := ensureDir(filepath.Dir(jobPath), SeenDir); err != nil {
+ return err
+ }
+ if fd, err := os.Create(jobPath2Seen(jobPath)); err == nil {
fd.Close()
if err = DirSync(filepath.Dir(jobPath)); err != nil {
ctx.LogE("rx-dirsync", les, err, func(les LEs) string {
})
return err
} else if ctx.HdrUsage {
- os.Remove(jobPath + HdrSuffix)
+ os.Remove(JobPath2Hdr(jobPath))
}
}
if len(sendmail) > 0 && ctx.NotifyFile != nil {
if !dryRun {
if jobPath != "" {
if doSeen {
- if fd, err := os.Create(jobPath + SeenSuffix); err == nil {
+ if err := ensureDir(filepath.Dir(jobPath), SeenDir); err != nil {
+ return err
+ }
+ if fd, err := os.Create(jobPath2Seen(jobPath)); err == nil {
fd.Close()
if err = DirSync(filepath.Dir(jobPath)); err != nil {
ctx.LogE("rx-dirsync", les, err, func(les LEs) string {
})
return err
} else if ctx.HdrUsage {
- os.Remove(jobPath + HdrSuffix)
+ os.Remove(JobPath2Hdr(jobPath))
}
}
if len(sendmail) > 0 && ctx.NotifyFreq != nil {
})
if !dryRun && jobPath != "" {
if doSeen {
- if fd, err := os.Create(jobPath + SeenSuffix); err == nil {
+ if err := ensureDir(filepath.Dir(jobPath), SeenDir); err != nil {
+ return err
+ }
+ if fd, err := os.Create(jobPath2Seen(jobPath)); err == nil {
fd.Close()
if err = DirSync(filepath.Dir(jobPath)); err != nil {
ctx.LogE("rx-dirsync", les, err, func(les LEs) string {
})
return err
} else if ctx.HdrUsage {
- os.Remove(jobPath + HdrSuffix)
+ os.Remove(JobPath2Hdr(jobPath))
}
}
seenDir := filepath.Join(
ctx.Spool, nodeId.String(), AreaDir, area.Id.String(),
)
- seenPath := filepath.Join(seenDir, msgHash+SeenSuffix)
+ seenPath := filepath.Join(seenDir, msgHash)
logMsgNode := func(les LEs) string {
return fmt.Sprintf(
"%s: echoing to: %s", logMsg(les), node.Name,
seenDir := filepath.Join(
ctx.Spool, nodeId.String(), AreaDir, area.Id.String(),
)
- seenPath := filepath.Join(seenDir, msgHash+SeenSuffix)
+ seenPath := filepath.Join(seenDir, msgHash)
logMsgNode := func(les LEs) string {
return fmt.Sprintf("%s: echo to: %s", logMsg(les), node.Name)
}
seenDir := filepath.Join(
ctx.Spool, ctx.SelfId.String(), AreaDir, area.Id.String(),
)
- seenPath := filepath.Join(seenDir, msgHash+SeenSuffix)
+ seenPath := filepath.Join(seenDir, msgHash)
if _, err := os.Stat(seenPath); err == nil {
ctx.LogD("rx-area-seen", les, func(les LEs) string {
return logMsg(les) + ": already seen"
})
return err
} else if ctx.HdrUsage {
- os.Remove(jobPath + HdrSuffix)
+ os.Remove(JobPath2Hdr(jobPath))
}
}
return nil
nil,
)
if err != nil {
+ ctx.LogE("rx-area-pkt-enc-read2", les, err, logMsg)
pipeW.CloseWithError(err)
<-errs
return err
})
return err
} else if ctx.HdrUsage {
- os.Remove(jobPath + HdrSuffix)
+ os.Remove(JobPath2Hdr(jobPath))
}
}
nice uint8,
doSeen, noFile, noFreq, noExec, noTrns, noArea bool,
) (chan struct{}, chan bool) {
+ dw, err := ctx.NewDirWatcher(
+ filepath.Join(ctx.Spool, nodeId.String(), string(TRx)),
+ time.Second,
+ )
+ if err != nil {
+ log.Fatalln(err)
+ }
finish := make(chan struct{})
badCode := make(chan bool)
go func() {
for {
select {
case <-finish:
+ dw.Close()
badCode <- bad
- break
- default:
+ return
+ case <-dw.C:
+ bad = !ctx.Toss(
+ nodeId, TRx, nice, false,
+ doSeen, noFile, noFreq, noExec, noTrns, noArea) || bad
}
- time.Sleep(time.Second)
- bad = !ctx.Toss(
- nodeId, TRx, nice, false,
- doSeen, noFile, noFreq, noExec, noTrns, noArea) || bad
}
}()
return finish, badCode