//! `warpgate warmup` — pre-cache a remote directory to local SSD. use std::process::Command; use anyhow::{Context, Result}; use crate::config::Config; use crate::rclone::config as rclone_config; pub fn run(config: &Config, path: &str, newer_than: Option<&str>) -> Result<()> { let remote_src = format!("nas:{}/{}", config.connection.remote_path, path); let local_dest = std::env::temp_dir().join("warpgate-warmup"); println!("Warming up: {}", remote_src); // Create temp destination for downloaded files std::fs::create_dir_all(&local_dest) .context("Failed to create temp directory for warmup")?; let mut cmd = Command::new("rclone"); cmd.arg("copy") .arg("--config") .arg(rclone_config::RCLONE_CONF_PATH) .arg(&remote_src) .arg(&local_dest) .arg("--no-traverse") .arg("--progress"); if let Some(age) = newer_than { cmd.arg("--max-age").arg(age); } println!("Downloading from remote NAS..."); let status = cmd.status().context("Failed to run rclone copy")?; // Clean up temp directory let _ = std::fs::remove_dir_all(&local_dest); if status.success() { println!("Warmup complete."); Ok(()) } else { anyhow::bail!("rclone copy exited with status {}", status); } }