From 2d36e0195bf7766c85f8df0f46d836705324842b Mon Sep 17 00:00:00 2001 From: postmannen Date: Wed, 15 Jun 2022 20:55:20 +0200 Subject: [PATCH] fixed wrong file size when writing at dst --- requests_copy.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/requests_copy.go b/requests_copy.go index 1777b24..4a7dd5d 100644 --- a/requests_copy.go +++ b/requests_copy.go @@ -369,7 +369,7 @@ func copySrcSubProcFunc(proc process, cia copyInitialData) func(context.Context, log.Printf(" * RECEIVED in copySrcSubProcFunc from dst * copyStatus=copyReady: %v\n\n", csa.CopyStatus) b := make([]byte, cia.SplitChunkSize) - _, err := fh.Read(b) + n, err := fh.Read(b) if err != nil && err != io.EOF { log.Printf("error: copySrcSubHandler: failed to read chuck from file: %v\n", err) } @@ -377,6 +377,14 @@ func copySrcSubProcFunc(proc process, cia copyInitialData) func(context.Context, status = copyDone } + // Testing here! + if n < cia.SplitChunkSize { + bb := make([]byte, n) + nr := copy(bb, b[:n]) + b = bb + fmt.Printf(" ********************* DEBUG: copied %v elements, length of b=%v\n", nr, len(b)) + } + lastReadChunk = b // Create a hash of the bytes @@ -662,11 +670,19 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message) func b := make([]byte, cia.SplitChunkSize) - _, err = fh.Read(b) + n, err := fh.Read(b) if err != nil { return err } + // Testing here! + if n < cia.SplitChunkSize { + bb := make([]byte, n) + nr := copy(bb, b[:n]) + b = bb + fmt.Printf(" ********************* DEBUG: copied %v elements, length of b=%v\n", nr, len(b)) + } + fmt.Printf(" * DEBUG: read: %v\n", b) _, err = mainfh.Write(b)