(&self, parent_dir: &Path, sub_dir: &str)
| 194 | } |
| 195 | |
| 196 | fn remove_cache(&self, parent_dir: &Path, sub_dir: &str) -> Result<()> { |
| 197 | if sub_dir.is_empty() { |
| 198 | return Ok(()); |
| 199 | } |
| 200 | |
| 201 | if sub_dir == "all" { |
| 202 | fs::remove_dir_all(parent_dir)?; |
| 203 | return Ok(()); |
| 204 | } |
| 205 | |
| 206 | if !sub_dir.chars().all(|c| c.is_ascii_hexdigit()) { |
| 207 | bail!("Invalid cache key"); |
| 208 | } |
| 209 | |
| 210 | let path = parent_dir.join(sub_dir); |
| 211 | |
| 212 | if path.is_dir() { |
| 213 | fs::remove_dir_all(path)?; |
| 214 | } else if path.is_file() { |
| 215 | fs::remove_file(path)?; |
| 216 | } |
| 217 | |
| 218 | Ok(()) |
| 219 | } |
| 220 | |
| 221 | fn ensure_admin(&self, token: &str) -> Result<()> { |
| 222 | let token_hash = sha2::Sha256::new_with_prefix(token).finalize(); |
no test coverage detected