diff --git a/src/pairing/store.rs b/src/pairing/store.rs index c0175688..8a44f3b1 100644 --- a/src/pairing/store.rs +++ b/src/pairing/store.rs @@ -30,6 +30,9 @@ pub enum PairingStoreError { #[error("Invalid channel: {0}")] InvalidChannel(String), + #[error("Invalid path: {0}")] + InvalidPath(String), + #[error("IO error: {0}")] Io(#[from] std::io::Error), @@ -224,7 +227,10 @@ impl PairingStore { meta: Option, ) -> Result { let path = pairing_path(&self.base_dir, channel)?; - fs::create_dir_all(path.parent().unwrap())?; + let parent = path.parent().ok_or_else(|| { + PairingStoreError::InvalidPath(format!("path has no parent: {}", path.display())) + })?; + fs::create_dir_all(parent)?; let mut file = fs::OpenOptions::new() .read(true) @@ -319,7 +325,10 @@ impl PairingStore { fn record_failed_approve(&self, channel: &str) -> Result<(), PairingStoreError> { let path = approve_attempts_path(&self.base_dir, channel)?; - fs::create_dir_all(path.parent().unwrap())?; + let parent = path.parent().ok_or_else(|| { + PairingStoreError::InvalidPath(format!("path has no parent: {}", path.display())) + })?; + fs::create_dir_all(parent)?; // Open (or create) and lock before reading so concurrent callers // don't clobber each other's writes. @@ -462,7 +471,10 @@ impl PairingStore { } let path = allow_from_path(&self.base_dir, channel)?; - fs::create_dir_all(path.parent().unwrap())?; + let parent = path.parent().ok_or_else(|| { + PairingStoreError::InvalidPath(format!("path has no parent: {}", path.display())) + })?; + fs::create_dir_all(parent)?; let file = fs::OpenOptions::new() .read(true)