]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-bundle/main.go
Major namespace version was already updated
[nncp.git] / src / cmd / nncp-bundle / main.go
index 0dbe3ba34a45b9ac1e3ab97562891cab77385937..d7813a97f79e3f5cbca0acdd3c7346fcce340a6a 100644 (file)
@@ -33,7 +33,7 @@ import (
        "strings"
 
        xdr "github.com/davecgh/go-xdr/xdr2"
-       "go.cypherpunks.ru/nncp/v5"
+       "go.cypherpunks.ru/nncp/v6"
        "golang.org/x/crypto/blake2b"
 )
 
@@ -125,13 +125,16 @@ func main() {
                                {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,
@@ -155,7 +158,7 @@ func main() {
                                        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},
@@ -164,7 +167,9 @@ func main() {
                                ); 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)
                                }
@@ -172,8 +177,10 @@ func main() {
                                        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}), "")
@@ -298,7 +305,10 @@ func main() {
                                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"), "")
@@ -407,6 +417,9 @@ func main() {
                                        if err = nncp.DirSync(dstDirPath); err != nil {
                                                log.Fatalln("Error during syncing:", err)
                                        }
+                                       if ctx.HdrUsage {
+                                               ctx.HdrWrite(pktEncBuf, dstPath)
+                                       }
                                }
                        }
                        for _, le := range les {