type Reader = FilesystemReader;
fn read(&self, namespace: &str, key: &str) -> std::io::Result<Self::Reader> {
- let mut outer_lock = self.locks.lock().unwrap();
- let lock_key = (namespace.to_string(), key.to_string());
- let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key).or_default());
-
if key.is_empty() {
let msg = format!("Failed to read {}/{}: key may not be empty.", namespace, key);
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
}
+ let mut outer_lock = self.locks.lock().unwrap();
+ let lock_key = (namespace.to_string(), key.to_string());
+ let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key).or_default());
+
let mut dest_file_path = self.data_dir.clone();
dest_file_path.push(namespace);
dest_file_path.push(key);
}
fn write(&self, namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()> {
- let mut outer_lock = self.locks.lock().unwrap();
- let lock_key = (namespace.to_string(), key.to_string());
- let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key).or_default());
- let _guard = inner_lock_ref.write().unwrap();
-
if key.is_empty() {
let msg = format!("Failed to write {}/{}: key may not be empty.", namespace, key);
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
}
+ let mut outer_lock = self.locks.lock().unwrap();
+ let lock_key = (namespace.to_string(), key.to_string());
+ let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key).or_default());
+ let _guard = inner_lock_ref.write().unwrap();
+
let mut dest_file_path = self.data_dir.clone();
dest_file_path.push(namespace);
dest_file_path.push(key);
}
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<()> {
+ if key.is_empty() {
+ let msg = format!("Failed to remove {}/{}: key may not be empty.", namespace, key);
+ return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
+ }
+
let mut outer_lock = self.locks.lock().unwrap();
let lock_key = (namespace.to_string(), key.to_string());
let inner_lock_ref = Arc::clone(&outer_lock.entry(lock_key.clone()).or_default());
let _guard = inner_lock_ref.write().unwrap();
- if key.is_empty() {
- let msg = format!("Failed to remove {}/{}: key may not be empty.", namespace, key);
- return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
- }
-
let mut dest_file_path = self.data_dir.clone();
dest_file_path.push(namespace);
dest_file_path.push(key);