stdout should erase file

This commit is contained in:
Zack Scholl 2019-05-01 13:09:47 -06:00
parent eceddb364e
commit ecfdb2d440
1 changed files with 19 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path"
@ -367,16 +368,24 @@ func (c *Client) transfer(options TransferOptions) (err error) {
var done bool
data, err = c.conn[0].Receive()
if err != nil {
return
break
}
done, err = c.processMessage(data)
if err != nil {
return
break
}
if done {
break
}
}
if c.Options.Stdout && !c.Options.IsSender {
pathToFile := path.Join(
c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote,
c.FilesToTransfer[c.FilesToTransferCurrentNum].Name,
)
os.Remove(pathToFile)
}
return
}
@ -720,6 +729,14 @@ func (c *Client) receiveData(i int) {
if c.TotalChunksTransfered == len(c.CurrentFileChunks) || c.TotalSent == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size {
log.Debug("finished receiving!")
c.CurrentFile.Close()
if c.Options.Stdout {
pathToFile := path.Join(
c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote,
c.FilesToTransfer[c.FilesToTransferCurrentNum].Name,
)
b, _ := ioutil.ReadFile(pathToFile)
fmt.Print(string(b))
}
log.Debug("sending close-sender")
err = message.Send(c.conn[0], c.Key, message.Message{
Type: "close-sender",