aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeerserverde@gmail.com>2024-02-24 18:21:27 +0100
committerHimbeer <himbeerserverde@gmail.com>2024-02-24 18:21:27 +0100
commitf5f9f4b916f4544f20602bc5c300a4e4af81b055 (patch)
tree36335fd57865c5ea1ec718690afa4be20af38d65
parent08649611b2e818acc32de72edb21d5deda5bbc7c (diff)
hbak + hbakd: wrap backup destination files (.part files) in BufWriter
-rw-r--r--hbak/src/main.rs5
-rw-r--r--hbak_common/src/conn.rs10
-rw-r--r--hbak_common/src/proto.rs4
-rw-r--r--hbakd/src/main.rs6
4 files changed, 14 insertions, 11 deletions
diff --git a/hbak/src/main.rs b/hbak/src/main.rs
index a12974b..94cef18 100644
--- a/hbak/src/main.rs
+++ b/hbak/src/main.rs
@@ -21,12 +21,13 @@ use hbak_common::config::{NodeConfig, RemoteNode, RemoteNodeAuth};
use hbak_common::conn::{AuthConn, DEFAULT_PORT};
use hbak_common::message::SyncInfo;
use hbak_common::proto::{LocalNode, Mode, Node, Snapshot, Volume};
+use hbak_common::stream::CHUNKSIZE;
use hbak_common::system;
use hbak_common::{LocalNodeError, RemoteError};
use std::collections::HashMap;
use std::fs::{self, File};
-use std::io::{BufRead, BufReader, Empty};
+use std::io::{BufRead, BufReader, BufWriter, Empty};
use std::net::SocketAddr;
use std::sync::Mutex;
@@ -481,7 +482,7 @@ fn sync(
eprintln!("Receiving {} from {}", snapshot, remote_node.address);
- Ok(file)
+ Ok(BufWriter::with_capacity(2 * CHUNKSIZE, file))
};
let rx_finish = |snapshot: Snapshot| {
diff --git a/hbak_common/src/conn.rs b/hbak_common/src/conn.rs
index 412d6c8..ee44885 100644
--- a/hbak_common/src/conn.rs
+++ b/hbak_common/src/conn.rs
@@ -21,7 +21,7 @@ use crate::stream::CHUNKSIZE;
use crate::system;
use crate::{NetworkError, RemoteError};
-use std::io::{self, BufReader, BufWriter, Read, Write};
+use std::io::{self, BufRead, BufReader, BufWriter, Write};
use std::marker::PhantomData;
use std::net::{SocketAddr, TcpStream};
use std::ops::DerefMut;
@@ -357,16 +357,16 @@ impl StreamConn<Idle> {
impl StreamConn<Active> {
/// Transmits the passed [`std::io::Read`]s using their associated metadata.
/// Receives remote transmissions using the provided stream setup closure.
- pub fn data_sync<R, W, I, S, F>(
+ pub fn data_sync<B, W, I, S, F>(
self,
tx: I,
rx_setup: S,
rx_finish: F,
) -> Result<(), NetworkError>
where
- R: Read,
+ B: BufRead,
W: Write + Send,
- I: IntoIterator<Item = (R, Snapshot)> + Send,
+ I: IntoIterator<Item = (B, Snapshot)> + Send,
S: Fn(&Snapshot) -> Result<W, RemoteError> + Sync,
F: Fn(Snapshot) -> Result<(), RemoteError> + Sync,
{
@@ -435,7 +435,7 @@ impl StreamConn<Active> {
Ok(false)
};
- let send_chunk = |r: &mut R| -> Result<bool, NetworkError> {
+ let send_chunk = |r: &mut B| -> Result<bool, NetworkError> {
let mut chunk = vec![0; 16 + CHUNKSIZE];
let n = r.read(&mut chunk)?;
chunk.truncate(n);
diff --git a/hbak_common/src/proto.rs b/hbak_common/src/proto.rs
index 15f4a48..670bf4b 100644
--- a/hbak_common/src/proto.rs
+++ b/hbak_common/src/proto.rs
@@ -22,7 +22,7 @@ use crate::{LocalNodeError, SnapshotParseError, VolumeParseError};
use std::cmp::Ordering;
use std::ffi::OsStr;
use std::fs::File;
-use std::io::{self, BufRead, BufReader, BufWriter, Read};
+use std::io::{self, BufRead, BufReader, BufWriter};
use std::path::{Path, PathBuf};
use std::process::{Child, ChildStdin, ChildStdout, Command, Stdio};
use std::{fmt, fs};
@@ -589,7 +589,7 @@ impl LocalNode {
/// Returns a new [`Read`] wrapping the provided snapshot or backup.
/// Performs encryption if exporting a local [`Snapshot`].
- pub fn export(&self, snapshot: &Snapshot) -> Result<Box<dyn Read + Send>, LocalNodeError> {
+ pub fn export(&self, snapshot: &Snapshot) -> Result<Box<dyn BufRead + Send>, LocalNodeError> {
if self.owns_backup(snapshot) {
Ok(Box::new(self.send_snapshot(snapshot)?))
} else {
diff --git a/hbakd/src/main.rs b/hbakd/src/main.rs
index 6923481..2f0bf7d 100644
--- a/hbakd/src/main.rs
+++ b/hbakd/src/main.rs
@@ -20,15 +20,17 @@ use error::*;
use hbak_common::conn::{AuthServ, DEFAULT_PORT, READ_TIMEOUT};
use hbak_common::message::SyncInfo;
use hbak_common::proto::{LocalNode, Mode, Node, Snapshot};
+use hbak_common::stream::CHUNKSIZE;
use hbak_common::RemoteError;
use std::collections::HashMap;
use std::fs::{self, File};
+use std::io::{self, BufWriter};
use std::net::{IpAddr, Ipv6Addr, SocketAddr, TcpListener, TcpStream};
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
-use std::{cmp, io, process, thread};
+use std::{cmp, process, thread};
use clap::Parser;
use daemonizr::{Daemonizr, DaemonizrError, Stderr, Stdout};
@@ -263,7 +265,7 @@ fn handle_client(debug: bool, local_node: &LocalNode, stream: TcpStream) -> Resu
);
}
- Ok(file)
+ Ok(BufWriter::with_capacity(2 * CHUNKSIZE, file))
};
let rx_finish = |snapshot: Snapshot| {