Skip to content

Commit ac667bb

Browse files
b5ppodolsky
andauthored
feat(iroh): expose ExportMode in client API (#2031)
## Description <!-- A summary of what this pull request achieves and a rough list of changes. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] Documentation updates if relevant. - [ ] Tests if relevant. Co-authored-by: Pasha Podolsky <[email protected]>
1 parent fea92ac commit ac667bb

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

iroh-bytes/src/store/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ pub enum ImportMode {
611611
/// does not make any sense. E.g. an in memory implementation will always have
612612
/// to copy the file into memory. Also, a disk based implementation might choose
613613
/// to copy small files even if the mode is `Reference`.
614-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
614+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize, Serialize)]
615615
pub enum ExportMode {
616616
/// This mode will copy the file to the target directory.
617617
///

iroh/src/client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use futures::{SinkExt, Stream, StreamExt, TryStreamExt};
1818
use iroh_bytes::export::ExportProgress;
1919
use iroh_bytes::format::collection::Collection;
2020
use iroh_bytes::provider::AddProgress;
21-
use iroh_bytes::store::ValidateProgress;
21+
use iroh_bytes::store::{ExportMode, ValidateProgress};
2222
use iroh_bytes::Hash;
2323
use iroh_bytes::{BlobFormat, Tag};
2424
use iroh_net::ticket::BlobTicket;
@@ -889,6 +889,7 @@ where
889889
&self,
890890
entry: Entry,
891891
path: impl AsRef<Path>,
892+
mode: ExportMode,
892893
) -> Result<DocExportFileProgress> {
893894
self.ensure_open()?;
894895
let stream = self
@@ -897,6 +898,7 @@ where
897898
.server_streaming(DocExportFileRequest {
898899
entry: entry.0,
899900
path: path.as_ref().into(),
901+
mode,
900902
})
901903
.await?;
902904
Ok(DocExportFileProgress::new(stream))
@@ -1427,6 +1429,7 @@ mod tests {
14271429
.export_file(
14281430
entry,
14291431
crate::util::fs::key_to_path(key, None, Some(out_root))?,
1432+
ExportMode::Copy,
14301433
)
14311434
.await
14321435
.context("export file")?

iroh/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ impl<D: BaoStore> RpcHandler<D> {
10501050
progress: flume::Sender<ExportProgress>,
10511051
) -> anyhow::Result<()> {
10521052
let progress = FlumeProgressSender::new(progress);
1053-
let DocExportFileRequest { entry, path } = msg;
1053+
let DocExportFileRequest { entry, path, mode } = msg;
10541054
let key = bytes::Bytes::from(entry.key().to_vec());
10551055
let export_progress = progress.clone().with_map(move |mut x| {
10561056
// assign the doc key to the `meta` field of the initial progress event
@@ -1064,7 +1064,7 @@ impl<D: BaoStore> RpcHandler<D> {
10641064
entry.content_hash(),
10651065
path,
10661066
false,
1067-
ExportMode::Copy,
1067+
mode,
10681068
export_progress,
10691069
)
10701070
.await?;

iroh/src/rpc_protocol.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use quic_rpc::{
3030
use serde::{Deserialize, Serialize};
3131

3232
pub use iroh_base::rpc::{RpcError, RpcResult};
33+
use iroh_bytes::store::ExportMode;
3334
pub use iroh_bytes::{provider::AddProgress, store::ValidateProgress};
3435

3536
use crate::sync_engine::LiveEvent;
@@ -781,6 +782,9 @@ pub struct DocExportFileRequest {
781782
/// the node runs. Usually the cli will run on the same machine as the
782783
/// node, so this should be an absolute path on the cli machine.
783784
pub path: PathBuf,
785+
/// The mode of exporting. Setting to `ExportMode::TryReference` means attempting
786+
/// to use references for keeping file
787+
pub mode: ExportMode,
784788
}
785789

786790
impl Msg<ProviderService> for DocExportFileRequest {

0 commit comments

Comments
 (0)