From b1797dafd2a9da4724de4b01eacf2c6e37f8f721 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Wed, 14 Jul 2021 19:11:46 -0400 Subject: [PATCH] Fix double write bug --- src/cache/fs.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cache/fs.rs b/src/cache/fs.rs index 5970637..89735d2 100644 --- a/src/cache/fs.rs +++ b/src/cache/fs.rs @@ -158,10 +158,11 @@ impl AsyncRead for EncryptedReader { cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { + let mut pinned = self.as_mut(); let previously_read = buf.filled().len(); - let res = self.as_mut().file.as_mut().poll_read(cx, buf); + let res = pinned.file.as_mut().poll_read(cx, buf); let bytes_modified = buf.filled().len() - previously_read; - self.keystream.apply_keystream( + pinned.keystream.apply_keystream( &mut buf.filled_mut()[previously_read..previously_read + bytes_modified], ); res @@ -214,7 +215,7 @@ impl<'a, R: AsyncBufRead> Future for MetadataFuture<'a, R> { // This needs to be outside the loop because we need to drop the // reader ref, since that depends on a mut self. - pinned.as_mut().consume(dbg!(bytes_consumed)); + pinned.as_mut().consume(bytes_consumed); return res; } } @@ -326,7 +327,9 @@ impl AsyncWrite for EncryptedDiskWriter { Poll::Ready(Ok(buf.len())) } Poll::Ready(Err(e)) => Poll::Ready(Err(e)), - Poll::Pending => Poll::Pending, + // We have written the data to our buffer, even if we haven't + // couldn't write the file to disk. + Poll::Pending => Poll::Ready(Ok(buf.len())), } }