From 4fd172b6fcd6298ab9d82c8ae2d31b487d2f6558 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Fri, 21 Sep 2018 22:09:29 -0700 Subject: [PATCH] fix getting hash --- src/relay/conn.go | 2 +- src/sender/sender.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/relay/conn.go b/src/relay/conn.go index 59171fd..a82ec98 100644 --- a/src/relay/conn.go +++ b/src/relay/conn.go @@ -55,7 +55,7 @@ func (s subscription) readPump() { messageType, msg, err := c.ws.ReadMessage() if err != nil { if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) { - log.Errorf("error: %v", err) + log.Debugf("unexpected close: %v", err) } break } diff --git a/src/sender/sender.go b/src/sender/sender.go index 2889183..7db5b2e 100644 --- a/src/sender/sender.go +++ b/src/sender/sender.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "os" + "path/filepath" "strings" "time" @@ -41,6 +42,8 @@ func Send(done chan struct{}, c *websocket.Conn, fname string, codephrase string func send(c *websocket.Conn, fname string, codephrase string) (err error) { // check that the file exists + fname, err = filepath.Abs(fname) + _, filename := filepath.Split(fname) f, err := os.Open(fname) if err != nil { return @@ -50,10 +53,11 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) { return err } // get stats - fstats := models.FileStats{fstat.Name(), fstat.Size(), fstat.ModTime(), fstat.IsDir(), fstat.Name()} + fstats := models.FileStats{filename, fstat.Size(), fstat.ModTime(), fstat.IsDir(), fstat.Name()} if fstats.IsDir { // zip the directory fstats.SentName, err = zipper.ZipFile(fname, true) + fname = fstats.SentName if err != nil { return } @@ -165,7 +169,7 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) { bar.Finish() log.Debug("send hash to finish file") - fileHash, err := utils.HashFile(fstats.SentName) + fileHash, err := utils.HashFile(fname) if err != nil { return err }