summaryrefslogtreecommitdiff
path: root/src/persistence.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-03-05 18:35:11 +0100
committertroido <troido@protonmail.com>2020-03-05 18:35:11 +0100
commit74e1707722325f9c97b42c56fb710744528b11f1 (patch)
treec8917094a1c5696484b99f5171b35c70c304704c /src/persistence.rs
parenta8be1d11b929ffcc3cfb50880f4d489059fc9a0f (diff)
longer temp filename
Diffstat (limited to 'src/persistence.rs')
-rw-r--r--src/persistence.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/persistence.rs b/src/persistence.rs
index f1ed845..2903ec6 100644
--- a/src/persistence.rs
+++ b/src/persistence.rs
@@ -9,7 +9,8 @@ use crate::{
RoomId,
savestate::SaveState,
playerstate::PlayerState,
- Result
+ Result,
+ aerr
};
pub trait PersistentStorage {
@@ -103,7 +104,15 @@ impl PersistentStorage for FileStorage {
}
fn write_file_safe<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
- let temppath = path.as_ref().with_file_name(format!("tempfile_{}.tmp", rand::random::<u64>()));
+ let temppath = path
+ .as_ref()
+ .with_file_name(
+ format!(
+ "tempfile_{}_{}.tmp",
+ path.as_ref().file_name().ok_or(aerr!("writing to directory"))?.to_str().unwrap_or("invalid"),
+ rand::random::<u64>()
+ )
+ );
fs::write(&temppath, contents)?;
fs::rename(&temppath, path)?;
Ok(())