"strings"
xdr "github.com/davecgh/go-xdr/xdr2"
- "go.cypherpunks.ru/nncp/v5"
+ "go.cypherpunks.ru/nncp/v6"
"golang.org/x/crypto/blake2b"
)
{K: "Pkt", V: "dummy"},
}
for job := range ctx.Jobs(&nodeId, nncp.TTx) {
- pktName = filepath.Base(job.Fd.Name())
+ pktName = filepath.Base(job.Path)
les[len(les)-1].V = pktName
if job.PktEnc.Nice > nice {
ctx.LogD("nncp-bundle", les, "too nice")
- job.Fd.Close() // #nosec G104
continue
}
+ fd, err := os.Open(job.Path)
+ if err != nil {
+ log.Fatalln("Error during opening:", err)
+ }
if err = tarWr.WriteHeader(&tar.Header{
Format: tar.FormatUSTAR,
Name: nncp.NNCPBundlePrefix,
log.Fatalln("Error writing tar header:", err)
}
if _, err = nncp.CopyProgressed(
- tarWr, job.Fd, "Tx",
+ tarWr, bufio.NewReader(fd), "Tx",
append(les, nncp.LEs{
{K: "Pkt", V: nncp.Base32Codec.EncodeToString(job.HshValue[:])},
{K: "FullSize", V: job.Size},
); err != nil {
log.Fatalln("Error during copying to tar:", err)
}
- job.Fd.Close() // #nosec G104
+ if err = fd.Close(); err != nil {
+ log.Fatalln("Error during closing:", err)
+ }
if err = tarWr.Flush(); err != nil {
log.Fatalln("Error during tar flushing:", err)
}
log.Fatalln("Error during stdout flushing:", err)
}
if *doDelete {
- if err = os.Remove(job.Fd.Name()); err != nil {
+ if err = os.Remove(job.Path); err != nil {
log.Fatalln("Error during deletion:", err)
+ } else if ctx.HdrUsage {
+ os.Remove(job.Path + nncp.HdrSuffix)
}
}
ctx.LogI("nncp-bundle", append(les, nncp.LE{K: "Size", V: job.Size}), "")
if nncp.Base32Codec.EncodeToString(hsh.Sum(nil)) == pktName {
ctx.LogI("nncp-bundle", les, "removed")
if !*dryRun {
- os.Remove(dstPath) // #nosec G104
+ os.Remove(dstPath)
+ if ctx.HdrUsage {
+ os.Remove(dstPath + nncp.HdrSuffix)
+ }
}
} else {
ctx.LogE("nncp-bundle", les, errors.New("bad checksum"), "")
if err = nncp.DirSync(dstDirPath); err != nil {
log.Fatalln("Error during syncing:", err)
}
+ if ctx.HdrUsage {
+ ctx.HdrWrite(pktEncBuf, dstPath)
+ }
}
}
for _, le := range les {