(path: &Path, temp_path: &Path, contents: &[u8])
| 492 | } |
| 493 | |
| 494 | pub fn write_file_atomically(path: &Path, temp_path: &Path, contents: &[u8]) -> io::Result<()> { |
| 495 | if path_parent(path) != path_parent(temp_path) { |
| 496 | return Err(invalid_input( |
| 497 | "private store atomic write temp path must share the target directory", |
| 498 | )); |
| 499 | } |
| 500 | if path == temp_path { |
| 501 | return Err(invalid_input( |
| 502 | "private store atomic write temp path must differ from the target", |
| 503 | )); |
| 504 | } |
| 505 | if let Some(parent) = path.parent() { |
| 506 | Self::create_dir_all(parent)?; |
| 507 | } |
| 508 | reject_symlink_components(path, "private store file")?; |
| 509 | reject_symlink_components(temp_path, "private store temp file")?; |
| 510 | fs::write(temp_path, contents)?; |
| 511 | set_private_file_permissions(temp_path)?; |
| 512 | fs::rename(temp_path, path)?; |
| 513 | set_private_file_permissions(path) |
| 514 | } |
| 515 | |
| 516 | pub fn copy_artifact(source: &Path, target: &Path) -> io::Result<u64> { |
| 517 | let meta = source.symlink_metadata()?; |
nothing calls this directly
no test coverage detected