MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / atomic_write_text

Function atomic_write_text

atomic-repository/src/repository/working_copy.rs:617–634  ·  view source on GitHub ↗
(dir: &Path, name: &str, value: &str)

Source from the content-addressed store, hash-verified

615}
616
617fn 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
636fn migration_required(layout: &RepositoryLayout, reason: impl Into<String>) -> RepositoryError {
637 RepositoryError::WorkingCopyMigrationRequired {

Callers 3

migrate_identityFunction · 0.85

Calls 2

openFunction · 0.85
as_bytesMethod · 0.45

Tested by

no test coverage detected