blob: 0b27084a041bd5c033c755d2cfa9d8e6e3fc62db (
plain)
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
|
//! The `get-chunk` subcommand.
use crate::chunkid::ChunkId;
use crate::client::BackupClient;
use crate::config::ClientConfig;
use crate::error::ObnamError;
use std::io::{stdout, Write};
use structopt::StructOpt;
use tokio::runtime::Runtime;
/// Fetch a chunk from the server.
#[derive(Debug, StructOpt)]
pub struct GetChunk {
/// Identifier of chunk to fetch.
#[structopt()]
chunk_id: String,
}
impl GetChunk {
/// Run the command.
pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> {
let rt = Runtime::new()?;
rt.block_on(self.run_async(config))
}
async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> {
let client = BackupClient::new(config)?;
let chunk_id: ChunkId = self.chunk_id.parse().unwrap();
let chunk = client.fetch_chunk(&chunk_id).await?;
let stdout = stdout();
let mut handle = stdout.lock();
handle.write_all(chunk.data())?;
Ok(())
}
}
|