forked from attaca/attaca
/
write_all.rs
88 lines (72 loc) · 2.45 KB
/
write_all.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::path::Path;
use clap::{App, SubCommand, Arg, ArgMatches};
use futures::prelude::*;
use attaca::Repository;
use attaca::trace::Trace;
use errors::*;
use trace::Progress;
const HELP_STR: &'static str = r#"
This test will first hashsplit and marshal a file; then, it will attempt to connect to a remote and
send all objects created in the process of marshalling. By default, it will display the progress
made in a progress bar; if this test is being used as part of a larger test suite, it may be a good
idea to run with with the --quiet option, which will suppress all output.
"#;
pub fn command() -> App<'static, 'static> {
SubCommand::with_name("write_all")
.about("Chunk, marshal, and then send a file to a remote.")
.after_help(HELP_STR)
.arg(
Arg::with_name("INPUT")
.help("Sets the input file.")
.required(true)
.index(1),
)
.arg(
Arg::with_name("quiet")
.help("Don't display progress.")
.short("q")
.long("quiet"),
)
}
fn run<T: Trace>(repository: &mut Repository, matches: &ArgMatches, trace: T) -> Result<()> {
let path = matches.value_of("INPUT").unwrap();
let context = repository.remote("_debug", trace)?;
let chunk_stream = context.split_file(path);
let hash_future = context.hash_file(chunk_stream);
let write_future = context.close();
write_future.join(hash_future).wait()?;
Ok(())
}
pub fn go<P: AsRef<Path>>(
repository: &mut Repository,
conf_dir: P,
matches: &ArgMatches,
) -> Result<()> {
let conf = conf_dir.as_ref().join("ceph.conf");
let keyring = conf_dir.as_ref().join("ceph.client.admin.keyring");
// HACK: Ignore errors if adding the remote fails (it will fail if the remote's already
// there.)
let _ = ::remote::add::go(
repository,
&::remote::add::command().get_matches_from_safe(
&[
"add".as_ref(),
"_debug".as_ref(),
"--ceph".as_ref(),
"--ceph-conf".as_ref(),
conf.as_os_str(),
"--ceph-keyring".as_ref(),
keyring.as_os_str(),
],
)?,
);
if matches.is_present("quiet") {
run(repository, matches, ())
} else {
run(
repository,
matches,
Progress::new(Some("_debug".to_string())),
)
}
}