Skip to content

Commit

Permalink
Rename GetFileDigest to StoreFileByDigest
Browse files Browse the repository at this point in the history
Add a comment explaining why it exists.
  • Loading branch information
illicitonion committed Dec 18, 2017
1 parent d74904a commit 8d69418
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/rust/engine/fs/fs_util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -327,8 +327,8 @@ struct FileSaver {
posix_fs: Arc<fs::PosixFS>,
}

impl GetFileDigest<String> for FileSaver {
fn digest(&self, file: &fs::File) -> BoxFuture<fs::Digest, String> {
impl StoreFileByDigest<String> for FileSaver {
fn store_by_digest(&self, file: &fs::File) -> BoxFuture<fs::Digest, String> {
let file_copy = file.clone();
let store = self.store.clone();
self
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 15 additions & 11 deletions src/rust/engine/fs/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ pub struct Snapshot {
pub path_stats: Vec<PathStat>,
}

pub trait GetFileDigest<Error> {
fn digest(&self, file: &File) -> BoxFuture<Digest, Error>;
// 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<Error> {
fn store_by_digest(&self, file: &File) -> BoxFuture<Digest, Error>;
}

impl Snapshot {
pub fn from_path_stats<
GFD: GetFileDigest<Error> + Sized + Clone,
SFBD: StoreFileByDigest<Error> + Sized + Clone,
Error: fmt::Debug + 'static + Send,
>(
store: Arc<Store>,
file_digester: GFD,
file_digester: SFBD,
path_stats: Vec<PathStat>,
) -> BoxFuture<Snapshot, String> {
let mut sorted_path_stats = path_stats.clone();
Expand All @@ -42,11 +46,11 @@ impl Snapshot {
}

fn ingest_directory_from_sorted_path_stats<
GFD: GetFileDigest<Error> + Sized + Clone,
SFBD: StoreFileByDigest<Error> + Sized + Clone,
Error: fmt::Debug + 'static + Send,
>(
store: Arc<Store>,
file_digester: GFD,
file_digester: SFBD,
path_stats: Vec<PathStat>,
) -> BoxFuture<Digest, String> {
let mut file_futures: Vec<BoxFuture<bazel_protos::remote_execution::FileNode, String>> =
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -452,8 +456,8 @@ mod tests {
#[derive(Clone)]
struct FileSaver(Arc<Store>, Arc<PosixFS>);

impl GetFileDigest<String> for FileSaver {
fn digest(&self, file: &File) -> BoxFuture<Digest, String> {
impl StoreFileByDigest<String> for FileSaver {
fn store_by_digest(&self, file: &File) -> BoxFuture<Digest, String> {
let file_copy = file.clone();
let store = self.0.clone();
self
Expand Down
7 changes: 4 additions & 3 deletions src/rust/engine/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -104,8 +105,8 @@ impl Context {
}
}

impl GetFileDigest<Failure> for Context {
fn digest(&self, file: &File) -> BoxFuture<Digest, Failure> {
impl StoreFileByDigest<Failure> for Context {
fn store_by_digest(&self, file: &File) -> BoxFuture<Digest, Failure> {
self.get(DigestFile(file.clone()))
}
}
Expand Down

0 comments on commit 8d69418

Please sign in to comment.