feat: implement repo arch remove
parent
513a760040
commit
bf100049b1
|
@ -133,6 +133,51 @@ impl MetaRepoMgr {
|
|||
}
|
||||
}
|
||||
|
||||
/// Remove all packages from the repository with the given arch.
|
||||
pub async fn remove_repo_arch(&self, conn: &DbConn, repo: &str, arch: &str) -> Result<bool> {
|
||||
let repo = db::query::repo::by_name(conn, repo).await?;
|
||||
|
||||
if let Some(repo) = repo {
|
||||
let mut pkgs = repo
|
||||
.find_related(db::Package)
|
||||
.filter(db::package::Column::Arch.eq(arch))
|
||||
.stream(conn)
|
||||
.await?;
|
||||
|
||||
while let Some(pkg) = pkgs.next().await.transpose()? {
|
||||
let path = self
|
||||
.repo_dir
|
||||
.join(&repo.name)
|
||||
.join(super::package::filename(&pkg));
|
||||
tokio::fs::remove_file(path).await?;
|
||||
|
||||
pkg.delete(conn).await?;
|
||||
}
|
||||
|
||||
tokio::fs::remove_file(
|
||||
self.repo_dir
|
||||
.join(&repo.name)
|
||||
.join(format!("{}.db.tar.gz", arch)),
|
||||
)
|
||||
.await?;
|
||||
tokio::fs::remove_file(
|
||||
self.repo_dir
|
||||
.join(&repo.name)
|
||||
.join(format!("{}.files.tar.gz", arch)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// If we removed all "any" packages, we need to resync all databases
|
||||
if arch == ANY_ARCH {
|
||||
self.generate_archives_all(conn, &repo.name).await?;
|
||||
}
|
||||
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn remove_pkg(
|
||||
&self,
|
||||
conn: &DbConn,
|
||||
|
|
|
@ -120,31 +120,20 @@ async fn delete_arch_repo(
|
|||
State(global): State<crate::Global>,
|
||||
Path((repo, arch)): Path<(String, String)>,
|
||||
) -> crate::Result<StatusCode> {
|
||||
Ok(StatusCode::NOT_FOUND)
|
||||
//let clone = Arc::clone(&global.repo_manager);
|
||||
//
|
||||
//let arch_clone = arch.clone();
|
||||
//let repo_clone = repo.clone();
|
||||
//let repo_removed = tokio::task::spawn_blocking(move || {
|
||||
// clone
|
||||
// .write()
|
||||
// .unwrap()
|
||||
// .remove_repo_arch(&repo_clone, &arch_clone)
|
||||
//})
|
||||
//.await??;
|
||||
//
|
||||
//if repo_removed {
|
||||
// let res = db::query::repo::by_name(&global.db, &repo).await?;
|
||||
//
|
||||
// if let Some(repo_entry) = res {
|
||||
// db::query::package::delete_with_arch(&global.db, repo_entry.id, &arch).await?;
|
||||
// }
|
||||
// tracing::info!("Removed architecture '{}' from repository '{}'", arch, repo);
|
||||
//
|
||||
// Ok(StatusCode::OK)
|
||||
//} else {
|
||||
// Ok(StatusCode::NOT_FOUND)
|
||||
//}
|
||||
let repo_removed = global
|
||||
.repo_manager
|
||||
.write()
|
||||
.await
|
||||
.remove_repo_arch(&global.db, &repo, &arch)
|
||||
.await?;
|
||||
|
||||
if repo_removed {
|
||||
tracing::info!("Removed arch '{}' from repository '{}'", arch, repo);
|
||||
|
||||
Ok(StatusCode::OK)
|
||||
} else {
|
||||
Ok(StatusCode::NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
||||
async fn delete_package(
|
||||
|
|
Loading…
Reference in New Issue