(path: &PathBuf, bytes: &[u8], _executable: bool)
| 515 | } |
| 516 | |
| 517 | fn write_file_atomically(path: &PathBuf, bytes: &[u8], _executable: bool) -> Result<()> { |
| 518 | let parent = path |
| 519 | .parent() |
| 520 | .context("Target file has no parent directory")?; |
| 521 | std::fs::create_dir_all(parent)?; |
| 522 | |
| 523 | let ts = chrono::Utc::now().timestamp_nanos_opt().unwrap_or_default(); |
| 524 | let pid = std::process::id(); |
| 525 | let tmp_path = parent.join(format!( |
| 526 | ".{}.tmp-{}-{}", |
| 527 | path.file_name() |
| 528 | .and_then(|s| s.to_str()) |
| 529 | .unwrap_or("download"), |
| 530 | pid, |
| 531 | ts |
| 532 | )); |
| 533 | |
| 534 | std::fs::write(&tmp_path, bytes)?; |
| 535 | |
| 536 | #[cfg(unix)] |
| 537 | { |
| 538 | use std::os::unix::fs::PermissionsExt; |
| 539 | let mode = if _executable { 0o755 } else { 0o644 }; |
| 540 | std::fs::set_permissions(&tmp_path, std::fs::Permissions::from_mode(mode))?; |
| 541 | } |
| 542 | |
| 543 | std::fs::rename(&tmp_path, path)?; |
| 544 | Ok(()) |
| 545 | } |
| 546 | |
| 547 | fn get_platform_asset_name() -> String { |
| 548 | #[cfg(all(target_os = "linux", target_arch = "x86_64"))] |
no test coverage detected