Skip to content

Commit b859e78

Browse files
committed
handle PathNotFoundError instead of calling storage.source_file_exists
1 parent 65b5734 commit b859e78

File tree

2 files changed

+15
-52
lines changed

2 files changed

+15
-52
lines changed

src/storage/mod.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,6 @@ impl AsyncStorage {
201201
})
202202
}
203203

204-
pub(crate) async fn source_file_exists(
205-
&self,
206-
name: &str,
207-
version: &str,
208-
latest_build_id: i32,
209-
path: &str,
210-
archive_storage: bool,
211-
) -> Result<bool> {
212-
Ok(if archive_storage {
213-
self.exists_in_archive(&source_archive_path(name, version), latest_build_id, path)
214-
.await?
215-
} else {
216-
// Add sources prefix, name and version to the path for accessing the file stored in the database
217-
let remote_path = format!("sources/{name}/{version}/{path}");
218-
self.exists(&remote_path).await?
219-
})
220-
}
221-
222204
#[context("fetching {path} from {name} {version} (archive: {archive_storage})")]
223205
pub(crate) async fn fetch_source_file(
224206
&self,
@@ -665,23 +647,6 @@ impl Storage {
665647
))
666648
}
667649

668-
pub(crate) fn source_file_exists(
669-
&self,
670-
name: &str,
671-
version: &str,
672-
latest_build_id: i32,
673-
path: &str,
674-
archive_storage: bool,
675-
) -> Result<bool> {
676-
self.runtime.block_on(self.inner.source_file_exists(
677-
name,
678-
version,
679-
latest_build_id,
680-
path,
681-
archive_storage,
682-
))
683-
}
684-
685650
pub(crate) fn rustdoc_file_exists(
686651
&self,
687652
name: &str,

src/web/source.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{error::AxumResult, match_version_axum};
22
use crate::{
33
db::Pool,
44
impl_axum_webpage,
5+
storage::PathNotFoundError,
56
utils::get_correct_docsrs_style_file,
67
web::{
78
cache::CachePolicy, error::AxumNope, file::File as DbFile, headers::CanonicalUrl,
@@ -250,30 +251,27 @@ pub(crate) async fn source_browser_handler(
250251

251252
// try to get actual file first
252253
// skip if request is a directory
253-
let blob = if !path.ends_with('/')
254-
&& storage
255-
.source_file_exists(
254+
let blob = if !path.ends_with('/') {
255+
match storage
256+
.fetch_source_file(
256257
&name,
257258
&version,
258259
row.latest_build_id.unwrap_or(0),
259260
&path,
260261
row.archive_storage,
261262
)
262263
.await
263-
.context("error checking source file existence")?
264-
{
265-
Some(
266-
storage
267-
.fetch_source_file(
268-
&name,
269-
&version,
270-
row.latest_build_id.unwrap_or(0),
271-
&path,
272-
row.archive_storage,
273-
)
274-
.await
275-
.context("error fetching source file")?,
276-
)
264+
.context("error fetching source file")
265+
{
266+
Ok(blob) => Some(blob),
267+
Err(err) => {
268+
if err.downcast_ref::<PathNotFoundError>().is_some() {
269+
None
270+
} else {
271+
return Err(err.into());
272+
}
273+
}
274+
}
277275
} else {
278276
None
279277
};

0 commit comments

Comments
 (0)