Skip to content

Commit

Permalink
feat(iroh-bytes): expose ExportMode in API
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Feb 16, 2024
1 parent e7af74d commit 2240953
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion iroh-bytes/src/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
5 changes: 4 additions & 1 deletion iroh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -889,6 +889,7 @@ where
&self,
entry: Entry,
path: impl AsRef<Path>,
mode: ExportMode,
) -> Result<DocExportFileProgress> {
self.ensure_open()?;
let stream = self
Expand All @@ -897,6 +898,7 @@ where
.server_streaming(DocExportFileRequest {
entry: entry.0,
path: path.as_ref().into(),
mode,
})
.await?;
Ok(DocExportFileProgress::new(stream))
Expand Down Expand Up @@ -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")?
Expand Down
4 changes: 2 additions & 2 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ impl<D: BaoStore> RpcHandler<D> {
progress: flume::Sender<ExportProgress>,
) -> 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
Expand All @@ -1064,7 +1064,7 @@ impl<D: BaoStore> RpcHandler<D> {
entry.content_hash(),
path,
false,
ExportMode::Copy,
mode,
export_progress,
)
.await?;
Expand Down
4 changes: 4 additions & 0 deletions iroh/src/rpc_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProviderService> for DocExportFileRequest {
Expand Down

0 comments on commit 2240953

Please sign in to comment.