(root: &Path, state_dir: &Path)
| 4240 | } |
| 4241 | |
| 4242 | async fn remove_sandbox_state_dir(root: &Path, state_dir: &Path) -> Result<(), Status> { |
| 4243 | validate_sandbox_state_dir(root, state_dir)?; |
| 4244 | |
| 4245 | let metadata = match tokio::fs::symlink_metadata(state_dir).await { |
| 4246 | Ok(metadata) => metadata, |
| 4247 | Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(()), |
| 4248 | Err(err) => { |
| 4249 | return Err(Status::internal(format!( |
| 4250 | "failed to stat sandbox state dir: {err}" |
| 4251 | ))); |
| 4252 | } |
| 4253 | }; |
| 4254 | let file_type = metadata.file_type(); |
| 4255 | if file_type.is_symlink() { |
| 4256 | return Err(Status::internal(format!( |
| 4257 | "refusing to remove symlinked sandbox state dir: {}", |
| 4258 | state_dir.display() |
| 4259 | ))); |
| 4260 | } |
| 4261 | if !file_type.is_dir() { |
| 4262 | return Err(Status::internal(format!( |
| 4263 | "sandbox state path is not a directory: {}", |
| 4264 | state_dir.display() |
| 4265 | ))); |
| 4266 | } |
| 4267 | |
| 4268 | tokio::fs::remove_dir_all(state_dir) |
| 4269 | .await |
| 4270 | .map_err(|err| Status::internal(format!("failed to remove state dir: {err}"))) |
| 4271 | } |
| 4272 | |
| 4273 | fn image_cache_root_dir(root: &Path) -> PathBuf { |
| 4274 | root.join(IMAGE_CACHE_ROOT_DIR) |
no test coverage detected