diff options
| author | troido <troido@protonmail.com> | 2020-04-23 12:53:01 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-23 12:53:01 +0200 |
| commit | 080466200060d2d3ec64bec32a4959fa061b79ce (patch) | |
| tree | fbe602a0777583086b21799028f882d7b63d5c31 /src/persistence.rs | |
| parent | b41c30fa15aea0b01b8fa30e378d123da046a1e6 (diff) | |
accept authentication messages, and validate registrations
Diffstat (limited to 'src/persistence.rs')
| -rw-r--r-- | src/persistence.rs | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/persistence.rs b/src/persistence.rs index 1174ceb..2d927ee 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -1,5 +1,5 @@ -use std::path::{PathBuf, Path}; +use std::path::{PathBuf}; use std::fs; use std::env; use std::io::ErrorKind; @@ -12,7 +12,8 @@ use crate::{ playerstate::PlayerState, Timestamp, aerr, - errors::AnyError + errors::AnyError, + util::write_file_safe }; @@ -153,18 +154,4 @@ impl PersistentStorage for FileStorage { } } -fn write_file_safe<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<(), AnyError> { - 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(()) -} |
