From 7595eb7bbea77479d59fdbdf5782e3ca34b5b7c9 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Thu, 27 Apr 2023 13:23:58 +0200 Subject: [PATCH] fix: error when upload failed before all bytes received --- src/server/repo.v | 2 +- src/util/stream.v | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server/repo.v b/src/server/repo.v index 051a7c2..8f8270d 100644 --- a/src/server/repo.v +++ b/src/server/repo.v @@ -68,7 +68,7 @@ fn (mut app App) put_package(repo_ string) web.Result { mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true }) util.reader_to_file(mut app.reader, length.int(), pkg_path) or { - app.lwarn("Failed to upload '${pkg_path}'") + app.lwarn("Failed to upload '${pkg_path}': ${err.msg()}") return app.status(.internal_server_error) } diff --git a/src/util/stream.v b/src/util/stream.v index 4b362fc..ef6e872 100644 --- a/src/util/stream.v +++ b/src/util/stream.v @@ -46,6 +46,10 @@ pub fn reader_to_file(mut reader io.BufferedReader, length int, path string) ! { to_write = to_write - bytes_written } } + + if bytes_left > 0 { + return error('Not all bytes were received.') + } } // match_array_in_array[T] returns how many elements of a2 overlap with a1. For