Compare commits

...

1 Commits

Author SHA1 Message Date
Paul Masurel
37e7af322d Reverting atomic_write to the atomic_writes in order to address #866 2020-09-19 10:39:43 +09:00
2 changed files with 4 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ memmap = {version = "0.7", optional=true}
lz4 = {version="1.20", optional=true}
snap = "1"
tempfile = {version="3.0", optional=true}
atomicwrites = "0.2"
log = "0.4"
serde = {version="1.0", features=["derive"]}
serde_json = "1.0"

View File

@@ -1,4 +1,5 @@
use crate::core::META_FILEPATH;
use atomicwrites;
use crate::directory::error::LockError;
use crate::directory::error::{
DeleteError, IOError, OpenDirectoryError, OpenReadError, OpenWriteError,
@@ -490,11 +491,9 @@ impl Directory for MmapDirectory {
fn atomic_write(&mut self, path: &Path, content: &[u8]) -> io::Result<()> {
debug!("Atomic Write {:?}", path);
let mut tempfile = tempfile::Builder::new().tempfile_in(&self.inner.root_path)?;
tempfile.write_all(content)?;
tempfile.flush()?;
let full_path = self.resolve_path(path);
tempfile.into_temp_path().persist(full_path)?;
let meta_file = atomicwrites::AtomicFile::new(full_path, atomicwrites::AllowOverwrite);
meta_file.write(|f| f.write_all(content))?;
Ok(())
}