rivet_cli/destination/
local.rs1use std::path::Path;
2
3use crate::config::DestinationConfig;
4use crate::error::Result;
5
6pub struct LocalDestination {
7 base_path: String,
8}
9
10impl LocalDestination {
11 pub fn new(config: &DestinationConfig) -> Result<Self> {
12 let base_path = config
13 .path
14 .clone()
15 .or_else(|| config.prefix.clone())
16 .unwrap_or_else(|| ".".to_string());
17 Ok(Self { base_path })
18 }
19}
20
21impl super::Destination for LocalDestination {
22 fn write(&self, local_path: &Path, remote_key: &str) -> Result<()> {
23 let target = Path::new(&self.base_path).join(remote_key);
24 if let Some(parent) = target.parent() {
25 std::fs::create_dir_all(parent)?;
26 }
27 std::fs::copy(local_path, &target)?;
28 log::info!("wrote {}", target.display());
29 Ok(())
30 }
31}