+ }
+ if err = os.Remove(jobPath); err != nil {
+ ctx.LogE("rx-notify", les, err, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing exec %s/%s (%s): %s: notifying",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), argsStr,
+ )
+ })
+ return err
+ } else if ctx.HdrUsage {
+ os.Remove(JobPath2Hdr(jobPath))
+ }
+ }
+
+ case PktTypeFile:
+ if noFile {
+ return nil
+ }
+ dst := string(pkt.Path[:int(pkt.PathLen)])
+ les = append(les, LE{"Type", "file"}, LE{"Dst", dst})
+ if filepath.IsAbs(dst) {
+ err = errors.New("non-relative destination path")
+ ctx.LogE(
+ "rx-non-rel", les, err,
+ func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ },
+ )
+ return err
+ }
+ incoming := sender.Incoming
+ if incoming == nil {
+ err = errors.New("incoming is not allowed")
+ ctx.LogE(
+ "rx-no-incoming", les, err,
+ func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ },
+ )
+ return err
+ }
+ dir := filepath.Join(*incoming, path.Dir(dst))
+ if err = os.MkdirAll(dir, os.FileMode(0777)); err != nil {
+ ctx.LogE("rx-mkdir", les, err, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s: mkdir",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ })
+ return err
+ }
+ if !dryRun {
+ tmp, err := TempFile(dir, "file")
+ if err != nil {
+ ctx.LogE("rx-mktemp", les, err, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s: mktemp",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ })
+ return err
+ }
+ les = append(les, LE{"Tmp", tmp.Name()})
+ ctx.LogD("rx-tmp-created", les, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s: created: %s",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst, tmp.Name(),
+ )
+ })
+ bufW := bufio.NewWriter(tmp)
+ if _, err = CopyProgressed(
+ bufW, pipeR, "Rx file",
+ append(les, LE{"FullSize", int64(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",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ })
+ return err
+ }
+ if err = bufW.Flush(); err != nil {
+ tmp.Close()
+ ctx.LogE("rx-flush", les, err, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s: flushing",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ })
+ return err
+ }
+ if err = tmp.Sync(); err != nil {
+ tmp.Close()
+ ctx.LogE("rx-sync", les, err, func(les LEs) string {
+ return fmt.Sprintf(
+ "Tossing file %s/%s (%s): %s: syncing",
+ sender.Name, pktName,
+ humanize.IBytes(pktSize), dst,
+ )
+ })
+ 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