- bufW := bufio.NewWriter(tmp)
- if _, err = CopyProgressed(
- bufW, pipeR, "Rx file",
- append(les, LE{"FullSize", pktSize}),
- ctx.ShowPrgrs,
- ); err != nil {
- ctx.LogE("rx-copy", les, err, func(les LEs) string {
- return fmt.Sprintf(
- "Tossing file %s/%s (%s): %s: copying",
- ctx.NodeName(job.PktEnc.Sender), pktName,
- humanize.IBytes(uint64(pktSize)), dst,
- )
- })
- isBad = true
- goto Closing
- }
- if err = bufW.Flush(); err != nil {
- tmp.Close() // #nosec G104
- ctx.LogE("rx-flush", les, err, func(les LEs) string {
- return fmt.Sprintf(
- "Tossing file %s/%s (%s): %s: flushing",
- ctx.NodeName(job.PktEnc.Sender), pktName,
- humanize.IBytes(uint64(pktSize)), dst,
- )
- })
- isBad = true
- goto Closing
- }
- if err = tmp.Sync(); err != nil {
- tmp.Close() // #nosec G104
- ctx.LogE("rx-sync", les, err, func(les LEs) string {
- return fmt.Sprintf(
- "Tossing file %s/%s (%s): %s: syncing",
- ctx.NodeName(job.PktEnc.Sender), pktName,
- humanize.IBytes(uint64(pktSize)), dst,
- )
- })
- isBad = true
- goto Closing
- }
- if err = tmp.Close(); err != nil {
- ctx.LogE("rx-close", les, err, func(les LEs) string {
+ return err
+ }
+ if err = tmp.Close(); err != nil {
+ ctx.LogE("rx-close", les, err, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s: closing",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ })
+ return err
+ }
+ dstPathOrig := filepath.Join(*incoming, dst)
+ dstPath := dstPathOrig
+ dstPathCtr := 0
+ for {
+ if _, err = os.Stat(dstPath); err != nil {
+ if os.IsNotExist(err) {
+ break
+ }
+ ctx.LogE("rx-stat", les, err, func(les LEs) string {