From 1ea8d9196f79ddea2f5746b26278d6b0cb24e42e Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 22 Oct 2017 10:44:18 -0600 Subject: [PATCH] Better UI and check for overwriting file --- connect.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/connect.go b/connect.go index ea0aad14..cd53a64a 100644 --- a/connect.go +++ b/connect.go @@ -13,6 +13,7 @@ import ( "sync" "time" + humanize "github.com/dustin/go-humanize" "github.com/verybluebot/tarinator-go" "github.com/gosuri/uiprogress" @@ -193,9 +194,9 @@ func (c *Connection) Run() error { } if c.File.IsDir { - fmt.Printf("Sending %d byte folder named '%s'\n", c.File.Size, c.File.Name[:len(c.File.Name)-4]) + fmt.Printf("Sending %s folder named '%s'\n", humanize.Bytes(uint64(c.File.Size)), c.File.Name[:len(c.File.Name)-4]) } else { - fmt.Printf("Sending %d byte file named '%s'\n", c.File.Size, c.File.Name) + fmt.Printf("Sending %s file named '%s'\n", humanize.Bytes(uint64(c.File.Size)), c.File.Name) } fmt.Printf("Code is: %s\n", c.Code) @@ -316,7 +317,11 @@ func (c *Connection) runClient() error { log.Debugf("meta data received: %v", c.File) // have the main thread ask for the okay if id == 0 { - fmt.Printf("Receiving file (%d bytes) into: %s\n", c.File.Size, path.Join(c.Path, c.File.Name)) + if _, err := os.Stat(path.Join(c.Path, c.File.Name)); os.IsNotExist(err) { + fmt.Printf("Receiving file (%s) into: %s\n", humanize.Bytes(uint64(c.File.Size)), path.Join(c.Path, c.File.Name)) + } else { + fmt.Printf("Overwriting file %s (%s)\n", path.Join(c.Path, c.File.Name), humanize.Bytes(uint64(c.File.Size))) + } var sentFileNames []string if c.AskPath {