88 "path/filepath"
99 "strconv"
1010
11- "fyne.io/fyne/v2"
1211 "github.com/Jacalz/rymdport/v3/internal/util"
1312 "github.com/Jacalz/rymdport/v3/zip"
1413 "github.com/rymdport/wormhole/wormhole"
@@ -30,7 +29,6 @@ func bail(msg *wormhole.IncomingMessage, err error) error {
3029func (c * Client ) NewReceive (code string ) (* wormhole.IncomingMessage , error ) {
3130 msg , err := c .Receive (context .Background (), code )
3231 if err != nil {
33- fyne .LogError ("Error on receiving data" , err )
3432 return nil , bail (msg , err )
3533 }
3634
@@ -50,7 +48,6 @@ func (c *Client) SaveToDisk(msg *wormhole.IncomingMessage, targetPath string, pr
5048 if err == nil || os .IsExist (err ) {
5149 targetPath , err = addFileIncrement (targetPath )
5250 if err != nil {
53- fyne .LogError ("Error on trying to create non-duplicate filename" , err )
5451 return bail (msg , err )
5552 }
5653 }
@@ -66,65 +63,41 @@ func (c *Client) SaveToDisk(msg *wormhole.IncomingMessage, targetPath string, pr
6663 return writeToDirectory (targetPath , msg , contents , progress )
6764}
6865
69- func writeToDirectory (targetPath string , msg * wormhole.IncomingMessage , contents util.ProgressReader , progress func (int64 , int64 )) ( err error ) {
66+ func writeToDirectory (targetPath string , msg * wormhole.IncomingMessage , contents util.ProgressReader , progress func (int64 , int64 )) error {
7067 tmp , err := os .CreateTemp ("" , msg .Name + "-*.zip.tmp" )
7168 if err != nil {
72- fyne .LogError ("Error on creating tempfile" , err )
7369 return bail (msg , err )
7470 }
7571
76- defer func () {
77- if cerr := tmp .Close (); cerr != nil {
78- fyne .LogError ("Error on closing file" , err )
79- err = cerr
80- }
81-
82- if rerr := os .Remove (tmp .Name ()); rerr != nil {
83- fyne .LogError ("Error on removing temp file" , err )
84- err = rerr
85- }
86- }()
72+ defer tmp .Close ()
73+ defer os .Remove (tmp .Name ())
8774
8875 var n int64
8976 n , err = io .Copy (tmp , contents )
9077 if err != nil {
91- fyne .LogError ("Error on copying contents to file" , err )
92- return
78+ return err
9379 }
9480
9581 err = zip .ExtractSafe (util .NewProgressReaderAt (tmp , progress , contents .Max ),
9682 n , targetPath , msg .UncompressedBytes , msg .FileCount )
9783 if err != nil {
98- fyne .LogError ("Error on unzipping contents" , err )
99- return
84+ return err
10085 }
10186
10287 progress (0 , 1 ) // Workaround for progress sometimes stopping at 99%.
103-
104- return
88+ return nil
10589}
10690
107- func writeToFile (destination string , msg * wormhole.IncomingMessage , contents util.ProgressReader ) ( err error ) {
91+ func writeToFile (destination string , msg * wormhole.IncomingMessage , contents util.ProgressReader ) error {
10892 file , err := os .Create (destination ) // #nosec Path is cleaned by filepath.Join().
10993 if err != nil {
110- fyne .LogError ("Error on creating file" , err )
11194 return bail (msg , err )
11295 }
11396
114- defer func () {
115- if cerr := file .Close (); cerr != nil {
116- fyne .LogError ("Error on closing file" , err )
117- err = cerr
118- }
119- }()
97+ defer file .Close ()
12098
12199 _ , err = io .Copy (file , contents )
122- if err != nil {
123- fyne .LogError ("Error on copying contents to file" , err )
124- return
125- }
126-
127- return
100+ return err
128101}
129102
130103// addFileIncrement tries to add a number to the end of the filename if a duplicate exists.
0 commit comments