diff --git a/iroh-bytes/src/store/traits.rs b/iroh-bytes/src/store/traits.rs index b4c53ed4e8..115ce0e2db 100644 --- a/iroh-bytes/src/store/traits.rs +++ b/iroh-bytes/src/store/traits.rs @@ -611,7 +611,7 @@ pub enum ImportMode { /// does not make any sense. E.g. an in memory implementation will always have /// to copy the file into memory. Also, a disk based implementation might choose /// to copy small files even if the mode is `Reference`. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize, Serialize)] pub enum ExportMode { /// This mode will copy the file to the target directory. /// diff --git a/iroh/src/client.rs b/iroh/src/client.rs index 661dd8c62c..2d8085643c 100644 --- a/iroh/src/client.rs +++ b/iroh/src/client.rs @@ -18,7 +18,7 @@ use futures::{SinkExt, Stream, StreamExt, TryStreamExt}; use iroh_bytes::export::ExportProgress; use iroh_bytes::format::collection::Collection; use iroh_bytes::provider::AddProgress; -use iroh_bytes::store::ValidateProgress; +use iroh_bytes::store::{ExportMode, ValidateProgress}; use iroh_bytes::Hash; use iroh_bytes::{BlobFormat, Tag}; use iroh_net::ticket::BlobTicket; @@ -889,6 +889,7 @@ where &self, entry: Entry, path: impl AsRef, + mode: ExportMode, ) -> Result { self.ensure_open()?; let stream = self @@ -897,6 +898,7 @@ where .server_streaming(DocExportFileRequest { entry: entry.0, path: path.as_ref().into(), + mode, }) .await?; Ok(DocExportFileProgress::new(stream)) @@ -1427,6 +1429,7 @@ mod tests { .export_file( entry, crate::util::fs::key_to_path(key, None, Some(out_root))?, + ExportMode::Copy, ) .await .context("export file")? diff --git a/iroh/src/node.rs b/iroh/src/node.rs index 5c45382c66..4aacc02927 100644 --- a/iroh/src/node.rs +++ b/iroh/src/node.rs @@ -1050,7 +1050,7 @@ impl RpcHandler { progress: flume::Sender, ) -> anyhow::Result<()> { let progress = FlumeProgressSender::new(progress); - let DocExportFileRequest { entry, path } = msg; + let DocExportFileRequest { entry, path, mode } = msg; let key = bytes::Bytes::from(entry.key().to_vec()); let export_progress = progress.clone().with_map(move |mut x| { // assign the doc key to the `meta` field of the initial progress event @@ -1064,7 +1064,7 @@ impl RpcHandler { entry.content_hash(), path, false, - ExportMode::Copy, + mode, export_progress, ) .await?; diff --git a/iroh/src/rpc_protocol.rs b/iroh/src/rpc_protocol.rs index fee7611025..6bd35f1dc4 100644 --- a/iroh/src/rpc_protocol.rs +++ b/iroh/src/rpc_protocol.rs @@ -30,6 +30,7 @@ use quic_rpc::{ use serde::{Deserialize, Serialize}; pub use iroh_base::rpc::{RpcError, RpcResult}; +use iroh_bytes::store::ExportMode; pub use iroh_bytes::{provider::AddProgress, store::ValidateProgress}; use crate::sync_engine::LiveEvent; @@ -781,6 +782,9 @@ pub struct DocExportFileRequest { /// the node runs. Usually the cli will run on the same machine as the /// node, so this should be an absolute path on the cli machine. pub path: PathBuf, + /// The mode of exporting. Setting to `ExportMode::TryReference` means attempting + /// to use references for keeping file + pub mode: ExportMode, } impl Msg for DocExportFileRequest {