summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-05-13 08:25:34 +0300
committerLars Wirzenius <liw@liw.fi>2022-10-26 17:19:55 +0300
commit5cc1dc560ff605a6d582ea0d94ed65b0295cf324 (patch)
treec2e8db6e43faa1361b66fb16f64463b3c823b7db
parentc76569bbfdd3c40e427c99fa1a88158344cdfa67 (diff)
downloadobnam2-5cc1dc560ff605a6d582ea0d94ed65b0295cf324.tar.gz
change put to take a vector of bytes
Sponsored-by: author
-rw-r--r--src/chunkstore.rs16
-rw-r--r--src/client.rs3
2 files changed, 7 insertions, 12 deletions
diff --git a/src/chunkstore.rs b/src/chunkstore.rs
index 1f67e2f..cb78891 100644
--- a/src/chunkstore.rs
+++ b/src/chunkstore.rs
@@ -6,7 +6,6 @@
use crate::chunkid::ChunkId;
use crate::chunkmeta::ChunkMeta;
-use crate::cipher::EncryptedChunk;
use crate::config::{ClientConfig, ClientConfigError};
use crate::index::{Index, IndexError};
@@ -50,11 +49,7 @@ impl ChunkStore {
/// Store a chunk in the store.
///
/// The store chooses an id for the chunk.
- pub async fn put(
- &mut self,
- chunk: EncryptedChunk,
- meta: &ChunkMeta,
- ) -> Result<ChunkId, StoreError> {
+ pub async fn put(&mut self, chunk: Vec<u8>, meta: &ChunkMeta) -> Result<ChunkId, StoreError> {
match self {
Self::Local(store) => store.put(chunk, meta),
Self::Remote(store) => store.put(chunk, meta).await,
@@ -90,7 +85,7 @@ impl LocalStore {
.map_err(StoreError::Index)
}
- fn put(&mut self, chunk: EncryptedChunk, meta: &ChunkMeta) -> Result<ChunkId, StoreError> {
+ fn put(&mut self, chunk: Vec<u8>, meta: &ChunkMeta) -> Result<ChunkId, StoreError> {
let id = ChunkId::new();
let (dir, filename) = self.filename(&id);
@@ -98,8 +93,7 @@ impl LocalStore {
std::fs::create_dir_all(&dir).map_err(|err| StoreError::ChunkMkdir(dir, err))?;
}
- let data = chunk.ciphertext().to_vec();
- std::fs::write(&filename, &data)
+ std::fs::write(&filename, &chunk)
.map_err(|err| StoreError::WriteChunk(filename.clone(), err))?;
self.index
.insert_meta(id.clone(), meta.clone())
@@ -162,12 +156,12 @@ impl RemoteStore {
Ok(ids)
}
- async fn put(&self, chunk: EncryptedChunk, meta: &ChunkMeta) -> Result<ChunkId, StoreError> {
+ async fn put(&self, chunk: Vec<u8>, meta: &ChunkMeta) -> Result<ChunkId, StoreError> {
let res = self
.client
.post(&self.chunks_url())
.header("chunk-meta", meta.to_json())
- .body(chunk.ciphertext().to_vec())
+ .body(chunk)
.send()
.await
.map_err(StoreError::ReqwestError)?;
diff --git a/src/client.rs b/src/client.rs
index 7b15bba..7ae6581 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -131,7 +131,8 @@ impl BackupClient {
/// Upload a data chunk to the server.
pub async fn upload_chunk(&mut self, chunk: DataChunk) -> Result<ChunkId, ClientError> {
let enc = self.cipher.encrypt_chunk(&chunk)?;
- let id = self.store.put(enc, chunk.meta()).await?;
+ let data = enc.ciphertext().to_vec();
+ let id = self.store.put(data, chunk.meta()).await?;
Ok(id)
}