gitscope
← rgit / Diff · 7f95c54 → 7f95c54
Changes 7f95c54..7f95c54
Patch commit
diff --git a/Cargo.lock b/Cargo.lock
index 236dd48..cae5da3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -237,7 +237,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.43",
]
[[package]]
diff --git a/src/database/schema/repository.rs b/src/database/schema/repository.rs
index 8eb48e5..42b0f62 100644
--- a/src/database/schema/repository.rs
+++ b/src/database/schema/repository.rs
@@ -33,6 +33,12 @@ pub struct Repository<'a> {
pub type YokedRepository = Yoked<Repository<'static>>;
impl Repository<'_> {
+ pub fn exists<P: AsRef<Path>>(database: &sled::Db, path: P) -> bool {
+ database
+ .contains_key(TreePrefix::repository_id(path))
+ .unwrap_or_default()
+ }
+
pub fn fetch_all(database: &sled::Db) -> Result<BTreeMap<String, YokedRepository>> {
database
.scan_prefix([TreePrefix::Repository as u8])
diff --git a/src/methods/repo/mod.rs b/src/methods/repo/mod.rs
index 1b818eb..8bf8040 100644
--- a/src/methods/repo/mod.rs
+++ b/src/methods/repo/mod.rs
@@ -123,6 +123,16 @@ where
let uri = uri_parts.into_iter().collect::<PathBuf>().clean();
let path = scan_path.join(&uri);
+ let db = request
+ .extensions()
+ .get::<sled::Db>()
+ .expect("db extension missing");
+ if path.as_os_str().is_empty()
+ || !crate::database::schema::repository::Repository::exists(db, &uri)
+ {
+ return RepositoryNotFound.into_response();
+ }
+
request.extensions_mut().insert(ChildPath(child_path));
request.extensions_mut().insert(Repository(uri));
request.extensions_mut().insert(RepositoryPath(path));
@@ -161,6 +171,14 @@ impl Deref for RepositoryPath {
pub type Result<T, E = Error> = std::result::Result<T, E>;
+pub struct RepositoryNotFound;
+
+impl IntoResponse for RepositoryNotFound {
+ fn into_response(self) -> Response {
+ (StatusCode::NOT_FOUND, "Repository not found").into_response()
+ }
+}
+
pub struct Error(anyhow::Error);
impl From<Arc<anyhow::Error>> for Error {