diff --git a/src/rust/engine/fs/fs_util/src/main.rs b/src/rust/engine/fs/fs_util/src/main.rs index 1cd5a62caa10..8436b606754b 100644 --- a/src/rust/engine/fs/fs_util/src/main.rs +++ b/src/rust/engine/fs/fs_util/src/main.rs @@ -7,7 +7,7 @@ extern crate protobuf; use boxfuture::{Boxable, BoxFuture}; use clap::{App, Arg, SubCommand}; -use fs::{Fingerprint, GetFileDigest, ResettablePool, Snapshot, Store, VFS}; +use fs::{Fingerprint, ResettablePool, Snapshot, Store, StoreFileByDigest, VFS}; use futures::future::{self, Future, join_all}; use protobuf::Message; use std::error::Error; @@ -196,7 +196,7 @@ fn execute(top_match: clap::ArgMatches) -> Result<(), ExitError> { let digest = FileSaver { store: store, posix_fs: Arc::new(posix_fs), - }.digest(&f) + }.store_by_digest(&f) .wait() .unwrap(); Ok(println!("{} {}", digest.0, digest.1)) @@ -327,8 +327,8 @@ struct FileSaver { posix_fs: Arc, } -impl GetFileDigest for FileSaver { - fn digest(&self, file: &fs::File) -> BoxFuture { +impl StoreFileByDigest for FileSaver { + fn store_by_digest(&self, file: &fs::File) -> BoxFuture { let file_copy = file.clone(); let store = self.store.clone(); self diff --git a/src/rust/engine/fs/src/lib.rs b/src/rust/engine/fs/src/lib.rs index daed7231a89d..c0a3a0b557ad 100644 --- a/src/rust/engine/fs/src/lib.rs +++ b/src/rust/engine/fs/src/lib.rs @@ -4,7 +4,7 @@ mod hash; pub use hash::Fingerprint; mod snapshot; -pub use snapshot::{GetFileDigest, Snapshot}; +pub use snapshot::{Snapshot, StoreFileByDigest}; mod store; pub use store::{Digest, Store}; mod pool; diff --git a/src/rust/engine/fs/src/snapshot.rs b/src/rust/engine/fs/src/snapshot.rs index f89703af689d..0edc77396b57 100644 --- a/src/rust/engine/fs/src/snapshot.rs +++ b/src/rust/engine/fs/src/snapshot.rs @@ -21,17 +21,21 @@ pub struct Snapshot { pub path_stats: Vec, } -pub trait GetFileDigest { - fn digest(&self, file: &File) -> BoxFuture; +// StoreFileByDigest allows a File to be saved to an underlying Store, in such a way that it can be +// looked up by the Digest produced by the store_by_digest method. +// It is a separate trait so that caching implementations can be written which wrap the Store (used +// to store the bytes) and VFS (used to read the files off disk if needed). +pub trait StoreFileByDigest { + fn store_by_digest(&self, file: &File) -> BoxFuture; } impl Snapshot { pub fn from_path_stats< - GFD: GetFileDigest + Sized + Clone, + SFBD: StoreFileByDigest + Sized + Clone, Error: fmt::Debug + 'static + Send, >( store: Arc, - file_digester: GFD, + file_digester: SFBD, path_stats: Vec, ) -> BoxFuture { let mut sorted_path_stats = path_stats.clone(); @@ -42,11 +46,11 @@ impl Snapshot { } fn ingest_directory_from_sorted_path_stats< - GFD: GetFileDigest + Sized + Clone, + SFBD: StoreFileByDigest + Sized + Clone, Error: fmt::Debug + 'static + Send, >( store: Arc, - file_digester: GFD, + file_digester: SFBD, path_stats: Vec, ) -> BoxFuture { let mut file_futures: Vec> = @@ -73,7 +77,7 @@ impl Snapshot { file_futures.push( file_digester .clone() - .digest(&stat) + .store_by_digest(&stat) .map_err(|e| format!("{:?}", e)) .and_then(move |digest| { let mut file_node = bazel_protos::remote_execution::FileNode::new(); @@ -275,8 +279,8 @@ mod tests { use tempdir::TempDir; use self::testutil::make_file; - use super::super::{Digest, File, FileContent, Fingerprint, GetFileDigest, PathGlobs, PathStat, - PosixFS, ResettablePool, Snapshot, Store, VFS}; + use super::super::{Digest, File, FileContent, Fingerprint, PathGlobs, PathStat, PosixFS, + ResettablePool, Snapshot, Store, StoreFileByDigest, VFS}; use std; use std::error::Error; @@ -452,8 +456,8 @@ mod tests { #[derive(Clone)] struct FileSaver(Arc, Arc); - impl GetFileDigest for FileSaver { - fn digest(&self, file: &File) -> BoxFuture { + impl StoreFileByDigest for FileSaver { + fn store_by_digest(&self, file: &File) -> BoxFuture { let file_copy = file.clone(); let store = self.0.clone(); self diff --git a/src/rust/engine/src/context.rs b/src/rust/engine/src/context.rs index f58cd8dea0a4..57492884cbac 100644 --- a/src/rust/engine/src/context.rs +++ b/src/rust/engine/src/context.rs @@ -8,7 +8,8 @@ use std::sync::Arc; use boxfuture::BoxFuture; use core::{Failure, TypeId}; use externs; -use fs::{Digest, File, GetFileDigest, PosixFS, Store, safe_create_dir_all_ioerror, ResettablePool}; +use fs::{Digest, File, PosixFS, Store, safe_create_dir_all_ioerror, ResettablePool, + StoreFileByDigest}; use graph::{EntryId, Graph}; use handles::maybe_drain_handles; use nodes::{DigestFile, Node, NodeFuture}; @@ -104,8 +105,8 @@ impl Context { } } -impl GetFileDigest for Context { - fn digest(&self, file: &File) -> BoxFuture { +impl StoreFileByDigest for Context { + fn store_by_digest(&self, file: &File) -> BoxFuture { self.get(DigestFile(file.clone())) } }