From 2548fa68e7390a7f371e5a53c4bd7b4073b0e97b Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Sat, 5 Feb 2022 16:09:07 +0300 Subject: [PATCH] Less syscalls to open files on the receiving end --- src/main.go | 2 +- src/node/node.go | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main.go b/src/main.go index f258926..e4dd7aa 100644 --- a/src/main.go +++ b/src/main.go @@ -30,7 +30,7 @@ import ( ) var ( - VERSION string = "v2.3.0" + VERSION string = "v2.3.1" versionInformation string = fmt.Sprintf("ftu %s\nfile transferring utility\n\nCopyright (C) 2021,2022 Kasyanov Nikolay Alexeevich (Unbewohnte (me@unbewohnte.xyz))\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain conditions; type \"ftu -l\" for details.\n", VERSION) diff --git a/src/node/node.go b/src/node/node.go index 503fd7e..1234cce 100644 --- a/src/node/node.go +++ b/src/node/node.go @@ -774,10 +774,11 @@ func (node *Node) receive() { // accepted // append provided bytes to the file - - err = acceptedFile.Open() - if err != nil { - panic(err) + if acceptedFile.Handler == nil { + err = acceptedFile.Open() + if err != nil { + panic(err) + } } fileBytes := fileBytesBuffer.Bytes() @@ -788,11 +789,6 @@ func (node *Node) receive() { } acceptedFile.SentBytes += uint64(wrote) node.transferInfo.Receiving.ReceivedBytes += uint64(wrote) - - err = acceptedFile.Close() - if err != nil { - panic(err) - } } } @@ -819,9 +815,11 @@ func (node *Node) receive() { fmt.Printf("\n[File] fully received \"%s\" -- %d bytes", acceptedFile.Name, acceptedFile.Size) } - err = acceptedFile.Open() - if err != nil { - panic(err) + if acceptedFile.Handler == nil { + err = acceptedFile.Open() + if err != nil { + panic(err) + } } // remove this file from the pool