diff --git a/server/src/cli.rs b/server/src/cli.rs index 68658ae..1ceaf27 100644 --- a/server/src/cli.rs +++ b/server/src/cli.rs @@ -44,7 +44,7 @@ pub struct Cli { #[arg( long, value_name = "LOG_LEVEL", - default_value = "tower_http=debug,rieterd=debug", + default_value = "tower_http=debug,rieterd=debug,sea_orm=debug", env = "RIETER_LOG" )] pub log: String, diff --git a/server/src/repo/manager2.rs b/server/src/repo/manager2.rs index 67d36eb..9a10e0d 100644 --- a/server/src/repo/manager2.rs +++ b/server/src/repo/manager2.rs @@ -268,6 +268,19 @@ impl RepoMgr { }); } + pub async fn get_repo(&self, distro: &str, repo: &str) -> crate::Result> { + Ok(db::Repo::find() + .find_also_related(db::Distro) + .filter( + Condition::all() + .add(db::repo::Column::Name.eq(repo)) + .add(db::distro::Column::Name.eq(distro)), + ) + .one(&self.conn) + .await + .map(|res| res.map(|(repo, _)| repo.id))?) + } + pub async fn get_or_create_repo(&self, distro: &str, repo: &str) -> crate::Result { let mut repos = self.repos.write().await; diff --git a/server/src/repo/mod.rs b/server/src/repo/mod.rs index c5549ef..bb592c9 100644 --- a/server/src/repo/mod.rs +++ b/server/src/repo/mod.rs @@ -49,25 +49,29 @@ async fn get_file( Path((distro, repo, arch, file_name)): Path<(String, String, String, String)>, req: Request, ) -> crate::Result { - let repo_dir = global - .config - .data_dir - .join("distros") - .join(&distro) - .join(&repo); + if let Some(repo_id) = global.mgr.get_repo(&distro, &repo).await? { + let repo_dir = global + .config + .data_dir + .join("repos") + .join(repo_id.to_string()); - let file_name = - if file_name == format!("{}.db", repo) || file_name == format!("{}.db.tar.gz", repo) { - format!("{}.db.tar.gz", arch) - } else if file_name == format!("{}.files", repo) - || file_name == format!("{}.files.tar.gz", repo) - { - format!("{}.files.tar.gz", arch) - } else { - file_name - }; + let file_name = + if file_name == format!("{}.db", repo) || file_name == format!("{}.db.tar.gz", repo) { + format!("{}.db.tar.gz", arch) + } else if file_name == format!("{}.files", repo) + || file_name == format!("{}.files.tar.gz", repo) + { + format!("{}.files.tar.gz", arch) + } else { + file_name + }; - Ok(ServeFile::new(repo_dir.join(file_name)).oneshot(req).await) + let path = repo_dir.join(file_name); + Ok(ServeFile::new(path).oneshot(req).await) + } else { + Err(StatusCode::NOT_FOUND.into()) + } } async fn post_package_archive( @@ -84,18 +88,6 @@ async fn post_package_archive( global.mgr.queue_pkg(repo, tmp_path).await; - //let (name, version, arch) = mgr.add_pkg_from_path(&mut body, &repo).await?; - // - //tracing::info!( - // "Added '{}-{}' to repository '{}' ({})", - // name, - // version, - // repo, - // arch - //); - - //tokio::spawn(async move { mgr.sync_repo(&repo).await }); - Ok(()) }