asimov_cli/commands/source/snap/
compact.rs1use crate::{BoxError, StandardOptions};
4use asimov_env::paths::asimov_root;
5use asimov_module::normalization::normalize_url;
6use asimov_registry::Registry;
7use asimov_snapshot::{Options, Snapshotter};
8
9pub async fn compact(urls: &[String], _flags: &StandardOptions) -> Result<(), BoxError> {
10 let storage = asimov_snapshot::storage::Fs::for_dir(asimov_root().join("snapshots"))?;
11 let ss = Snapshotter::new(Registry::default(), storage, Options::default());
12
13 let urls: Vec<String> = if !urls.is_empty() {
14 urls.iter()
15 .map(|url| {
16 normalize_url(url).unwrap_or_else(|e| {
17 tracing::error!(
18 url,
19 "proceeding with given unmodified URL, normalization failed: {e}"
20 );
21 url.clone()
22 })
23 })
24 .collect()
25 } else {
26 ss.list()
27 .await
28 .inspect_err(|e| tracing::error!("failed to read previously snapshotted URLs: {e}"))?
29 .into_iter()
30 .map(|(url, _)| url)
31 .collect()
32 };
33
34 for url in urls {
35 ss.compact(&url)
36 .await
37 .inspect_err(|e| tracing::error!("failed to compact snapshots for `{url}`: {e}"))?;
38 }
39 Ok(())
40}