From d95eedcc83f8d07a49c25c5240beb8a0105d877a Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Tue, 30 Aug 2022 19:35:29 +0200 Subject: registry: ensure that files have been closed before calculating checksums --- planetwars-server/src/modules/registry.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/planetwars-server/src/modules/registry.rs b/planetwars-server/src/modules/registry.rs index 297404a..4a79d59 100644 --- a/planetwars-server/src/modules/registry.rs +++ b/planetwars-server/src/modules/registry.rs @@ -300,8 +300,10 @@ async fn put_upload( while let Some(Ok(chunk)) = stream.next().await { file.write_all(&chunk).await.unwrap(); } - file.flush().await.unwrap(); let range_end = last_byte_pos(&file).await.unwrap(); + // Close the file to ensure all data has been flushed to the kernel. + // If we don't do this, calculating the checksum can fail. + std::mem::drop(file); let expected_digest = params.digest.strip_prefix("sha256:").unwrap(); let digest = file_sha256_digest(&upload_path).unwrap(); -- cgit v1.2.3