From 6d9c8295798421f686b4ec06b35b6f61a3f9b39e Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 22 Sep 2018 06:13:14 -0700 Subject: [PATCH] prompt user if its okay to receive file --- src/recipient/recipient.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/recipient/recipient.go b/src/recipient/recipient.go index 387cea2..f16c7a2 100644 --- a/src/recipient/recipient.go +++ b/src/recipient/recipient.go @@ -10,6 +10,7 @@ import ( "time" "github.com/briandowns/spinner" + humanize "github.com/dustin/go-humanize" "github.com/schollz/croc/src/zipper" log "github.com/cihub/seelog" @@ -93,11 +94,34 @@ func receive(c *websocket.Conn, codephrase string) (err error) { case 2: spin.Stop() + // unmarshal the file info log.Debugf("[%d] recieve file info", step) err = json.Unmarshal(message, &fstats) if err != nil { return err } + + // prompt user if its okay to receive file + overwritingOrReceiving := "Receiving" + if utils.Exists(fstats.Name) { + overwritingOrReceiving = "Overwriting" + } + fileOrFolder := "file" + if fstats.IsDir { + fileOrFolder = "folder" + } + if "y" != utils.GetInput(fmt.Sprintf( + `%s %s (%s) into: %s + ok? (y/N): `, + overwritingOrReceiving, + fileOrFolder, + humanize.Bytes(uint64(fstats.Size)), + fstats.Name, + )) { + fmt.Fprintf(os.Stderr, "cancelling request") + return nil + } + // await file f, err := os.Create(fstats.SentName) if err != nil {