Skip to content

Instantly share code, notes, and snippets.

@kwlzn
Created June 13, 2018 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwlzn/fe28eeb4779c1e865f519fcde0d0f44a to your computer and use it in GitHub Desktop.
Save kwlzn/fe28eeb4779c1e865f519fcde0d0f44a to your computer and use it in GitHub Desktop.
diff --git a/src/rust/engine/process_execution/src/local.rs b/src/rust/engine/process_execution/src/local.rs
index 05e8e3a..73ecf5a 100644
--- a/src/rust/engine/process_execution/src/local.rs
+++ b/src/rust/engine/process_execution/src/local.rs
@@ -1,10 +1,12 @@
extern crate tempfile;
use boxfuture::{BoxFuture, Boxable};
-use fs::{self, GlobMatching, PathGlobs, PathStatGetter, StrictGlobMatching};
+use fs::{self, GlobMatching, PathGlobs, PathStatGetter, Snapshot, StrictGlobMatching};
use futures::{future, Future};
use std::process::Command;
use std::sync::Arc;
+use std::collections::BTreeSet;
+use std::path::PathBuf;
use tokio_process::CommandExt;
@@ -21,6 +23,57 @@ impl CommandRunner {
pub fn new(store: fs::Store, fs_pool: Arc<fs::ResettablePool>) -> CommandRunner {
CommandRunner { store, fs_pool }
}
+
+ fn construct_output_snapshot(
+ &self,
+ posix_fs: Arc<fs::PosixFS>,
+ output_file_paths: BTreeSet<PathBuf>,
+ output_dir_paths: BTreeSet<PathBuf>
+ ) -> BoxFuture<Snapshot, String> {
+ let output_dirs_glob_strings: Result<Vec<String>, String> =
+ output_dir_paths
+ .into_iter()
+ .map(|p|
+ p
+ .into_os_string()
+ .into_string()
+ .map_err(|e| format!("Error stringifying output_directories: {:?}", e))
+ .map(|s| format!("{}/**", s))
+ )
+ .collect();
+
+ let output_dirs_future = posix_fs
+ .expand(
+ PathGlobs::create(
+ &try_future!(output_dirs_glob_strings),
+ &[],
+ StrictGlobMatching::Ignore
+ ).unwrap()
+ )
+ .map_err(|e| format!("Error stating output dirs: {}", e));
+
+ let output_files_future = posix_fs
+ .path_stats(output_file_paths.into_iter().collect())
+ .map_err(|e| format!("Error stating output files: {}", e));
+
+ output_files_future.join(output_dirs_future)
+ .and_then(|(output_files_stats, output_dirs_stats)| {
+ let paths: Vec<_> = output_files_stats
+ .into_iter()
+ .chain(
+ output_dirs_stats
+ .into_iter()
+ .map(|p| Some(p))
+ )
+ .collect();
+
+ fs::Snapshot::from_path_stats(
+ self.store.clone(),
+ fs::OneOffStoreFileByDigest::new(self.store, posix_fs),
+ paths.into_iter().filter_map(|v| v).collect(),
+ )
+ }).to_boxed()
+ }
}
impl super::CommandRunner for CommandRunner {
@@ -65,66 +118,27 @@ impl super::CommandRunner for CommandRunner {
future::ok(fs::Snapshot::empty()).to_boxed()
} else {
// Use no ignore patterns, because we are looking for explicitly listed paths.
- future::done(fs::PosixFS::new(
- workdir.path(),
- fs_pool,
- vec![],
- )).map_err(|err| {
- format!(
- "Error making posix_fs to fetch local process execution output files: {}",
- err
- )
- })
- .map(|posix_fs| Arc::new(posix_fs))
- .and_then(|posix_fs| {
- let output_dirs_glob_strings: Result<Vec<String>, String> =
- output_dir_paths
- .into_iter()
- .map(|p|
- p
- .into_os_string()
- .into_string()
- .map_err(|e| format!("Error stringifying output_directories: {:?}", e))
- .map(|s| format!("{}/**", s))
- )
- .collect();
-
- let output_dirs_future = posix_fs
- .expand(
- PathGlobs::create(
- &try_future!(output_dirs_glob_strings),
- &[],
- StrictGlobMatching::Ignore
- ).unwrap()
- )
- .map_err(|e| format!("Error stating output dirs: {}", e));
-
- let output_files_future = posix_fs
- .path_stats(output_file_paths.into_iter().collect())
- .map_err(|e| format!("Error stating output files: {}", e));
-
- output_files_future.join(output_dirs_future)
- .and_then(|(output_files_stats, output_dirs_stats)| {
- let paths: Vec<_> = output_files_stats
- .into_iter()
- .chain(
- output_dirs_stats
- .into_iter()
- .map(|p| Some(p))
- )
- .collect();
-
- fs::Snapshot::from_path_stats(
- store.clone(),
- fs::OneOffStoreFileByDigest::new(store, posix_fs),
- paths.into_iter().filter_map(|v| v).collect(),
- )
- }).to_boxed()
- })
- // Force workdir not to get dropped until after we've ingested the outputs
- .map(|result| (result, workdir))
- .map(|(result, _workdir)| result)
- .to_boxed()
+ future::done(
+ fs::PosixFS::new(
+ workdir.path(),
+ fs_pool,
+ vec![],
+ )
+ )
+ .map_err(|err| {
+ format!(
+ "Error making posix_fs to fetch local process execution output files: {}",
+ err
+ )
+ })
+ .map(|posix_fs| Arc::new(posix_fs))
+ .and_then(|posix_fs| {
+ self.construct_output_snapshot(posix_fs, output_file_paths, output_dir_paths)
+ })
+ // Force workdir not to get dropped until after we've ingested the outputs
+ .map(|result| (result, workdir))
+ .map(|(result, _workdir)| result)
+ .to_boxed()
};
output_snapshot
@@ -145,6 +159,7 @@ impl super::CommandRunner for CommandRunner {
}
}
+
#[cfg(test)]
mod tests {
extern crate tempfile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment