Skip to content

Commit

Permalink
Yet more rustfmt (#5597)
Browse files Browse the repository at this point in the history
Somehow #5592 only half-formatted the files?
  • Loading branch information
illicitonion authored Mar 14, 2018
1 parent 07eee72 commit 68ce613
Show file tree
Hide file tree
Showing 23 changed files with 764 additions and 1,034 deletions.
200 changes: 95 additions & 105 deletions src/rust/engine/fs/fs_util/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ fn execute(top_match: clap::ArgMatches) -> Result<(), ExitError> {
let store = store_result.map_err(|e| {
format!(
"Failed to open/create store for directory {}: {}",
store_dir,
e
store_dir, e
)
})?;
(store, store_has_remote)
Expand Down Expand Up @@ -212,13 +211,9 @@ fn execute(top_match: clap::ArgMatches) -> Result<(), ExitError> {
let posix_fs = make_posix_fs(
path
.canonicalize()
.map_err(|e| {
format!("Error canonicalizing path {:?}: {}", path, e.description())
})?
.map_err(|e| format!("Error canonicalizing path {:?}: {}", path, e.description()))?
.parent()
.ok_or_else(|| {
format!("File being saved must have parent but {:?} did not", path)
})?,
.ok_or_else(|| format!("File being saved must have parent but {:?} did not", path))?,
pool,
);
let file = posix_fs
Expand All @@ -240,103 +235,100 @@ fn execute(top_match: clap::ArgMatches) -> Result<(), ExitError> {
o => Err(
format!(
"Tried to save file {:?} but it was not a file, was a {:?}",
path,
o
path, o
).into(),
),
}
}
(_, _) => unimplemented!(),
}
}
("directory", Some(sub_match)) => {
match sub_match.subcommand() {
("materialize", Some(args)) => {
let destination = PathBuf::from(args.value_of("destination").unwrap());
let fingerprint = Fingerprint::from_hex_string(args.value_of("fingerprint").unwrap())?;
let size_bytes = args
.value_of("size_bytes")
.unwrap()
.parse::<usize>()
.expect("size_bytes must be a non-negative number");
let digest = Digest(fingerprint, size_bytes);
store
.materialize_directory(destination, digest)
.wait()
.map_err(|err| if err.contains("not found") {
("directory", Some(sub_match)) => match sub_match.subcommand() {
("materialize", Some(args)) => {
let destination = PathBuf::from(args.value_of("destination").unwrap());
let fingerprint = Fingerprint::from_hex_string(args.value_of("fingerprint").unwrap())?;
let size_bytes = args
.value_of("size_bytes")
.unwrap()
.parse::<usize>()
.expect("size_bytes must be a non-negative number");
let digest = Digest(fingerprint, size_bytes);
store
.materialize_directory(destination, digest)
.wait()
.map_err(|err| {
if err.contains("not found") {
ExitError(err, ExitCode::NotFound)
} else {
err.into()
})
}
("save", Some(args)) => {
let posix_fs = Arc::new(make_posix_fs(args.value_of("root").unwrap(), pool));
let store_copy = store.clone();
let digest = posix_fs
.expand(fs::PathGlobs::create(
&args
.values_of("globs")
.unwrap()
.map(|s| s.to_string())
.collect::<Vec<String>>(),
&[],
)?)
.map_err(|e| format!("Error expanding globs: {}", e.description()))
.and_then(move |paths| {
Snapshot::from_path_stats(
store_copy.clone(),
FileSaver {
store: store_copy,
posix_fs: posix_fs,
},
paths,
)
})
.map(|snapshot| snapshot.digest)
.wait()?;
if store_has_remote {
store.ensure_remote_has_recursive(vec![digest]).wait()?;
}
Ok(println!("{} {}", digest.0, digest.1))
}
("cat-proto", Some(args)) => {
let fingerprint = Fingerprint::from_hex_string(args.value_of("fingerprint").unwrap())?;
let size_bytes = args
.value_of("size_bytes")
.unwrap()
.parse::<usize>()
.expect("size_bytes must be a non-negative number");
let digest = Digest(fingerprint, size_bytes);
let proto_bytes = match args.value_of("output-format").unwrap() {
"binary" => {
store.load_directory(digest).wait().map(|maybe_d| {
maybe_d.map(|d| d.write_to_bytes().unwrap())
})
}
"text" => {
store.load_directory(digest).wait().map(|maybe_p| {
maybe_p.map(|p| format!("{:?}\n", p).as_bytes().to_vec())
})
}
format => Err(format!(
"Unexpected value of --output-format arg: {}",
format
)),
}?;
match proto_bytes {
Some(bytes) => {
io::stdout().write(&bytes).unwrap();
Ok(())
}
None => Err(ExitError(
format!("Directory with digest {:?} not found", digest),
ExitCode::NotFound,
)),
})
}
("save", Some(args)) => {
let posix_fs = Arc::new(make_posix_fs(args.value_of("root").unwrap(), pool));
let store_copy = store.clone();
let digest = posix_fs
.expand(fs::PathGlobs::create(
&args
.values_of("globs")
.unwrap()
.map(|s| s.to_string())
.collect::<Vec<String>>(),
&[],
)?)
.map_err(|e| format!("Error expanding globs: {}", e.description()))
.and_then(move |paths| {
Snapshot::from_path_stats(
store_copy.clone(),
FileSaver {
store: store_copy,
posix_fs: posix_fs,
},
paths,
)
})
.map(|snapshot| snapshot.digest)
.wait()?;
if store_has_remote {
store.ensure_remote_has_recursive(vec![digest]).wait()?;
}
Ok(println!("{} {}", digest.0, digest.1))
}
("cat-proto", Some(args)) => {
let fingerprint = Fingerprint::from_hex_string(args.value_of("fingerprint").unwrap())?;
let size_bytes = args
.value_of("size_bytes")
.unwrap()
.parse::<usize>()
.expect("size_bytes must be a non-negative number");
let digest = Digest(fingerprint, size_bytes);
let proto_bytes = match args.value_of("output-format").unwrap() {
"binary" => store
.load_directory(digest)
.wait()
.map(|maybe_d| maybe_d.map(|d| d.write_to_bytes().unwrap())),
"text" => store
.load_directory(digest)
.wait()
.map(|maybe_p| maybe_p.map(|p| format!("{:?}\n", p).as_bytes().to_vec())),
format => Err(format!(
"Unexpected value of --output-format arg: {}",
format
)),
}?;
match proto_bytes {
Some(bytes) => {
io::stdout().write(&bytes).unwrap();
Ok(())
}
None => Err(ExitError(
format!("Directory with digest {:?} not found", digest),
ExitCode::NotFound,
)),
}
(_, _) => unimplemented!(),
}
}
(_, _) => unimplemented!(),
},
("cat", Some(args)) => {
let fingerprint = Fingerprint::from_hex_string(args.value_of("fingerprint").unwrap())?;
let size_bytes = args
Expand All @@ -346,18 +338,18 @@ fn execute(top_match: clap::ArgMatches) -> Result<(), ExitError> {
.expect("size_bytes must be a non-negative number");
let digest = Digest(fingerprint, size_bytes);
let v = match store.load_file_bytes_with(digest, |bytes| bytes).wait()? {
None => {
store
.load_directory(digest)
.map(|maybe_dir| {
maybe_dir.map(|dir| {
Bytes::from(dir.write_to_bytes().expect(
"Error serializing Directory proto",
))
})
None => store
.load_directory(digest)
.map(|maybe_dir| {
maybe_dir.map(|dir| {
Bytes::from(
dir
.write_to_bytes()
.expect("Error serializing Directory proto"),
)
})
.wait()?
}
})
.wait()?,
some => some,
};
match v {
Expand Down Expand Up @@ -393,9 +385,7 @@ impl StoreFileByDigest<String> for FileSaver {
self
.posix_fs
.read_file(&file)
.map_err(move |err| {
format!("Error reading file {:?}: {}", file_copy, err.description())
})
.map_err(move |err| format!("Error reading file {:?}: {}", file_copy, err.description()))
.and_then(move |content| store.store_file_bytes(content.content, true))
.to_boxed()
}
Expand Down
Loading

0 comments on commit 68ce613

Please sign in to comment.