Decide what to do with a destination that may already exist.
(dst: &Path, previous: Option<&Receipt>, force: bool)
| 271 | |
| 272 | /// Decide what to do with a destination that may already exist. |
| 273 | fn install_decision(dst: &Path, previous: Option<&Receipt>, force: bool) -> AgentResult<Decision> { |
| 274 | if !dst.exists() { |
| 275 | return Ok(Decision::Install); |
| 276 | } |
| 277 | let recorded = previous.and_then(|r| r.recorded_hash(dst)); |
| 278 | match recorded { |
| 279 | // Ours and untouched since install → safe to refresh. |
| 280 | Some(hash) if hash == hash_file(dst)? => Ok(Decision::Refresh), |
| 281 | // Ours but the user changed it → hands off unless forced. |
| 282 | Some(_) if !force => Ok(Decision::Skip(SkipReason::UserModified)), |
| 283 | // Not ours → hands off unless forced. |
| 284 | None if !force => Ok(Decision::Skip(SkipReason::UserFile)), |
| 285 | _ => Ok(Decision::Refresh), |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /// Expand a leading `~` in a destination path. |
| 290 | fn expand_dst(dst: &str) -> AgentResult<PathBuf> { |
no test coverage detected