From b859e78b36da41a5a55b975ea3e7cd6e0443a45f Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Wed, 22 Nov 2023 08:12:35 +0100 Subject: [PATCH] handle PathNotFoundError instead of calling storage.source_file_exists --- src/storage/mod.rs | 35 ----------------------------------- src/web/source.rs | 32 +++++++++++++++----------------- 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 4cfda0d09..05398de4a 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -201,24 +201,6 @@ impl AsyncStorage { }) } - pub(crate) async fn source_file_exists( - &self, - name: &str, - version: &str, - latest_build_id: i32, - path: &str, - archive_storage: bool, - ) -> Result { - Ok(if archive_storage { - self.exists_in_archive(&source_archive_path(name, version), latest_build_id, path) - .await? - } else { - // Add sources prefix, name and version to the path for accessing the file stored in the database - let remote_path = format!("sources/{name}/{version}/{path}"); - self.exists(&remote_path).await? - }) - } - #[context("fetching {path} from {name} {version} (archive: {archive_storage})")] pub(crate) async fn fetch_source_file( &self, @@ -665,23 +647,6 @@ impl Storage { )) } - pub(crate) fn source_file_exists( - &self, - name: &str, - version: &str, - latest_build_id: i32, - path: &str, - archive_storage: bool, - ) -> Result { - self.runtime.block_on(self.inner.source_file_exists( - name, - version, - latest_build_id, - path, - archive_storage, - )) - } - pub(crate) fn rustdoc_file_exists( &self, name: &str, diff --git a/src/web/source.rs b/src/web/source.rs index b6dd5660d..11da1ee48 100644 --- a/src/web/source.rs +++ b/src/web/source.rs @@ -2,6 +2,7 @@ use super::{error::AxumResult, match_version_axum}; use crate::{ db::Pool, impl_axum_webpage, + storage::PathNotFoundError, utils::get_correct_docsrs_style_file, web::{ cache::CachePolicy, error::AxumNope, file::File as DbFile, headers::CanonicalUrl, @@ -250,9 +251,9 @@ pub(crate) async fn source_browser_handler( // try to get actual file first // skip if request is a directory - let blob = if !path.ends_with('/') - && storage - .source_file_exists( + let blob = if !path.ends_with('/') { + match storage + .fetch_source_file( &name, &version, row.latest_build_id.unwrap_or(0), @@ -260,20 +261,17 @@ pub(crate) async fn source_browser_handler( row.archive_storage, ) .await - .context("error checking source file existence")? - { - Some( - storage - .fetch_source_file( - &name, - &version, - row.latest_build_id.unwrap_or(0), - &path, - row.archive_storage, - ) - .await - .context("error fetching source file")?, - ) + .context("error fetching source file") + { + Ok(blob) => Some(blob), + Err(err) => { + if err.downcast_ref::().is_some() { + None + } else { + return Err(err.into()); + } + } + } } else { None };