From 4150feddf0931b78060097515756a6123eda3422 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 27 Aug 2019 09:51:37 -0700 Subject: [PATCH] skip checking each file each time --- src/croc/croc.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/croc/croc.go b/src/croc/croc.go index 18014ce..957d220 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -72,6 +72,7 @@ type Client struct { // send / receive information of all files FilesToTransfer []FileInfo FilesToTransferCurrentNum int + FilesHasFinished map[int]struct{} // send / receive information of current file CurrentFile *os.File @@ -121,6 +122,7 @@ type SenderInfo struct { // New establishes a new connection for transfering files between two instances. func New(ops Options) (c *Client, err error) { c = new(Client) + c.FilesHasFinished = make(map[int]struct{}) // setup basic info c.Options = ops @@ -667,6 +669,9 @@ func (c *Client) updateState() (err error) { finished := true for i, fileInfo := range c.FilesToTransfer { + if _, ok := c.FilesHasFinished[i]; ok { + continue + } log.Debugf("checking %+v", fileInfo) if i < c.FilesToTransferCurrentNum { continue @@ -733,6 +738,7 @@ func (c *Client) updateState() (err error) { panic(err) } c.SuccessfulTransfer = true + c.FilesHasFinished[c.FilesToTransferCurrentNum] = struct{}{} } // start initiating the process to receive a new file