MCPcopy Create free account
hub / github.com/DNSCrypt/encrypted-dns-server / async_save

Method async_save

src/config.rs:168–182  ·  view source on GitHub ↗
(&self, path: impl AsRef<Path>)

Source from the content-addressed store, hash-verified

166 }
167
168 pub async fn async_save(&self, path: impl AsRef<Path>) -> Result<(), Error> {
169 let path = path.as_ref();
170 let path_tmp = path.with_extension("tmp");
171 let mut fpb = tokio::fs::OpenOptions::new();
172 let fpb = fpb.create(true).write(true).truncate(true);
173 let mut fp = fpb.open(&path_tmp).await?;
174 let state_str = toml::to_string(&self)?;
175 fp.write_all(state_str.as_bytes()).await?;
176 fp.sync_data().await?;
177 mem::drop(fp);
178 tokio::fs::rename(path_tmp, path).await?;
179 let dir = tokio::fs::File::open(path.parent().unwrap_or_else(|| Path::new("."))).await?;
180 dir.sync_all().await?;
181 Ok(())
182 }
183
184 pub fn from_file(path: impl AsRef<Path>, key_cache_capacity: usize) -> Result<Self, Error> {
185 let state_str = fs::read_to_string(path)?;

Callers 2

mainFunction · 0.80
updateMethod · 0.80

Calls 2

newFunction · 0.85
as_bytesMethod · 0.45

Tested by

no test coverage detected