Expand a leading `~` in a destination path.
(dst: &str)
| 288 | |
| 289 | /// Expand a leading `~` in a destination path. |
| 290 | fn expand_dst(dst: &str) -> AgentResult<PathBuf> { |
| 291 | if dst == "~" { |
| 292 | return dirs::home_dir().ok_or_else(|| AgentError::Integration { |
| 293 | agent: "<any>".to_string(), |
| 294 | reason: "cannot resolve home directory".to_string(), |
| 295 | }); |
| 296 | } |
| 297 | if let Some(rest) = dst.strip_prefix("~/") { |
| 298 | return dirs::home_dir() |
| 299 | .map(|h| h.join(rest)) |
| 300 | .ok_or_else(|| AgentError::Integration { |
| 301 | agent: "<any>".to_string(), |
| 302 | reason: "cannot resolve home directory".to_string(), |
| 303 | }); |
| 304 | } |
| 305 | Ok(PathBuf::from(dst)) |
| 306 | } |
| 307 | |
| 308 | /// Reject `src` paths that would escape the package directory. |
| 309 | fn reject_parent_traversal(agent: &str, src: &str) -> AgentResult<()> { |