From ab417a17d0e3c9dddb5fa30ab9ac4ef7d85bdbe3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 25 Mar 2016 15:39:26 +0100 Subject: [PATCH] Truncate file to zero size before writing new content, so we do not partially write the file --- libimagstore/src/store.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index af10869e..73ffe1ae 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -90,6 +90,8 @@ impl StoreEntry { let file = try!(self.file.create_file()); assert_eq!(self.id, entry.location); + try!(file.set_len(0) + .map_err(|e| StoreError::new(StoreErrorKind::FileError, Some(Box::new(e))))); file.write_all(entry.to_str().as_bytes()) .map_err(|e| StoreError::new(StoreErrorKind::FileError, Some(Box::new(e)))) } else {