(dir: &Path, name: &str, value: &str)
| 615 | } |
| 616 | |
| 617 | fn atomic_write_text(dir: &Path, name: &str, value: &str) -> Result<(), RepositoryError> { |
| 618 | std::fs::create_dir_all(dir)?; |
| 619 | let path = dir.join(name); |
| 620 | let mut temp = tempfile::NamedTempFile::new_in(dir)?; |
| 621 | temp.as_file_mut().write_all(value.as_bytes())?; |
| 622 | temp.as_file_mut().write_all(b"\n")?; |
| 623 | temp.as_file().sync_all()?; |
| 624 | temp.persist(&path).map_err(|error| { |
| 625 | RepositoryError::Io(std::io::Error::other(format!( |
| 626 | "failed to persist '{}': {}", |
| 627 | path.display(), |
| 628 | error |
| 629 | ))) |
| 630 | })?; |
| 631 | #[cfg(unix)] |
| 632 | std::fs::File::open(dir)?.sync_all()?; |
| 633 | Ok(()) |
| 634 | } |
| 635 | |
| 636 | fn migration_required(layout: &RepositoryLayout, reason: impl Into<String>) -> RepositoryError { |
| 637 | RepositoryError::WorkingCopyMigrationRequired { |
no test coverage detected