|
1 | 1 | #[cfg(target_os = "windows")] |
2 | 2 | extern crate winapi; |
3 | 3 |
|
4 | | -use super::KVStore; |
| 4 | +use super::{get_namespace_and_key_from_prefixed, KVStore}; |
5 | 5 |
|
6 | 6 | use std::collections::HashMap; |
7 | 7 | use std::fs; |
8 | 8 | use std::io::{BufReader, Read, Write}; |
9 | 9 | use std::path::{Path, PathBuf}; |
10 | | -use std::str::FromStr; |
11 | 10 | use std::sync::{Arc, Mutex, RwLock}; |
12 | 11 |
|
13 | 12 | #[cfg(not(target_os = "windows"))] |
@@ -249,25 +248,8 @@ impl Read for FilesystemReader { |
249 | 248 |
|
250 | 249 | impl KVStorePersister for FilesystemStore { |
251 | 250 | fn persist<W: Writeable>(&self, prefixed_key: &str, object: &W) -> lightning::io::Result<()> { |
252 | | - let dest_file_path = PathBuf::from_str(prefixed_key).map_err(|_| { |
253 | | - let msg = format!("Could not persist file for key {}.", prefixed_key); |
254 | | - lightning::io::Error::new(lightning::io::ErrorKind::InvalidInput, msg) |
255 | | - })?; |
256 | | - |
257 | | - let parent_directory = dest_file_path.parent().ok_or_else(|| { |
258 | | - let msg = format!("Could not persist file for key {}.", prefixed_key); |
259 | | - lightning::io::Error::new(lightning::io::ErrorKind::InvalidInput, msg) |
260 | | - })?; |
261 | | - let namespace = parent_directory.display().to_string(); |
262 | | - |
263 | | - let dest_without_namespace = dest_file_path.strip_prefix(&namespace).map_err(|_| { |
264 | | - let msg = format!("Could not persist file for key {}.", prefixed_key); |
265 | | - lightning::io::Error::new(lightning::io::ErrorKind::InvalidInput, msg) |
266 | | - })?; |
267 | | - let key = dest_without_namespace.display().to_string(); |
268 | | - |
269 | | - self.write(&namespace, &key, &object.encode())?; |
270 | | - Ok(()) |
| 251 | + let (namespace, key) = get_namespace_and_key_from_prefixed(prefixed_key)?; |
| 252 | + self.write(&namespace, &key, &object.encode()) |
271 | 253 | } |
272 | 254 | } |
273 | 255 |
|
|
0 commit comments