"archive/tar"
"bufio"
"bytes"
+ "errors"
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"
- "strconv"
"strings"
xdr "github.com/davecgh/go-xdr/xdr2"
spoolPath = flag.String("spool", "", "Override path to spool")
logPath = flag.String("log", "", "Override path to logfile")
quiet = flag.Bool("quiet", false, "Print only errors")
+ showPrgrs = flag.Bool("progress", false, "Force progress showing")
+ omitPrgrs = flag.Bool("noprogress", false, "Omit progress showing")
debug = flag.Bool("debug", false, "Print debug messages")
version = flag.Bool("version", false, "Print version information")
warranty = flag.Bool("warranty", false, "Print warranty information")
log.Fatalln("At least one of -rx and -tx must be specified")
}
- ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
+ ctx, err := nncp.CtxFromCmdline(
+ *cfgPath,
+ *spoolPath,
+ *logPath,
+ *quiet,
+ *showPrgrs,
+ *omitPrgrs,
+ *debug,
+ )
if err != nil {
log.Fatalln("Error during initialization:", err)
}
}); err != nil {
log.Fatalln("Error writing tar header:", err)
}
- if _, err = io.Copy(tarWr, job.Fd); err != nil {
+ if _, err = nncp.CopyProgressed(
+ tarWr, job.Fd,
+ nncp.SdsAdd(sds, nncp.SDS{
+ "pkt": nncp.ToBase32(job.HshValue[:]),
+ "fullsize": job.Size,
+ }),
+ ctx.ShowPrgrs,
+ ); err != nil {
log.Fatalln("Error during copying to tar:", err)
}
job.Fd.Close()
log.Fatalln("Error during deletion:", err)
}
}
- ctx.LogI("nncp-bundle", nncp.SdsAdd(sds, nncp.SDS{
- "size": strconv.FormatInt(job.Size, 10),
- }), "")
+ ctx.LogI("nncp-bundle", nncp.SdsAdd(sds, nncp.SDS{"size": job.Size}), "")
}
}
if err = tarWr.Close(); err != nil {
}
pktName = filepath.Base(entry.Name)
if _, err = nncp.FromBase32(pktName); err != nil {
- ctx.LogD("nncp-bundle", sds, "Bad packet name")
+ ctx.LogD("nncp-bundle", nncp.SdsAdd(sds, nncp.SDS{"err": "bad packet name"}), "")
continue
}
if _, err = io.ReadFull(tarR, pktEncBuf); err != nil {
if _, err = hsh.Write(pktEncBuf); err != nil {
log.Fatalln("Error during writing:", err)
}
- if _, err = io.Copy(hsh, tarR); err != nil {
+ if _, err = nncp.CopyProgressed(
+ hsh, tarR,
+ nncp.SdsAdd(sds, nncp.SDS{"fullsize": entry.Size}),
+ ctx.ShowPrgrs,
+ ); err != nil {
log.Fatalln("Error during copying:", err)
}
if nncp.ToBase32(hsh.Sum(nil)) == pktName {
os.Remove(dstPath)
}
} else {
- ctx.LogE("nncp-bundle", sds, "bad checksum")
+ ctx.LogE("nncp-bundle", sds, errors.New("bad checksum"), "")
}
continue
}
}
sds["node"] = nncp.ToBase32(pktEnc.Recipient[:])
sds["pkt"] = pktName
+ sds["fullsize"] = entry.Size
selfPath = filepath.Join(ctx.Spool, ctx.SelfId.String(), string(nncp.TRx))
dstPath = filepath.Join(selfPath, pktName)
if _, err = os.Stat(dstPath); err == nil || !os.IsNotExist(err) {
if _, err = hsh.Write(pktEncBuf); err != nil {
log.Fatalln("Error during writing:", err)
}
- if _, err = io.Copy(hsh, tarR); err != nil {
+ if _, err = nncp.CopyProgressed(hsh, tarR, sds, ctx.ShowPrgrs); err != nil {
log.Fatalln("Error during copying:", err)
}
if nncp.ToBase32(hsh.Sum(nil)) != pktName {
- ctx.LogE("nncp-bundle", sds, "bad checksum")
+ ctx.LogE("nncp-bundle", sds, errors.New("bad checksum"), "")
continue
}
} else {
if _, err = tmp.W.Write(pktEncBuf); err != nil {
log.Fatalln("Error during writing:", err)
}
- if _, err = io.Copy(tmp.W, tarR); err != nil {
+ if _, err = nncp.CopyProgressed(tmp.W, tarR, sds, ctx.ShowPrgrs); err != nil {
log.Fatalln("Error during copying:", err)
}
if err = tmp.W.Flush(); err != nil {
log.Fatalln("Error during commiting:", err)
}
} else {
- ctx.LogE("nncp-bundle", sds, "bad checksum")
+ ctx.LogE("nncp-bundle", sds, errors.New("bad checksum"), "")
tmp.Cancel()
continue
}
}
} else {
if *dryRun {
- if _, err = io.Copy(ioutil.Discard, tarR); err != nil {
+ if _, err = nncp.CopyProgressed(ioutil.Discard, tarR, sds, ctx.ShowPrgrs); err != nil {
log.Fatalln("Error during copying:", err)
}
} else {
if _, err = bufTmp.Write(pktEncBuf); err != nil {
log.Fatalln("Error during writing:", err)
}
- if _, err = io.Copy(bufTmp, tarR); err != nil {
+ if _, err = nncp.CopyProgressed(bufTmp, tarR, sds, ctx.ShowPrgrs); err != nil {
log.Fatalln("Error during copying:", err)
}
if err = bufTmp.Flush(); err != nil {
}
}
ctx.LogI("nncp-bundle", nncp.SdsAdd(sds, nncp.SDS{
- "size": strconv.FormatInt(entry.Size, 10),
+ "size": sds["fullsize"],
}), "")
}
}