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(
|
pub async fn remove_pkg(
|
||||||
&self,
|
&self,
|
||||||
conn: &DbConn,
|
conn: &DbConn,
|
||||||
|
|
|
@ -120,31 +120,20 @@ async fn delete_arch_repo(
|
||||||
State(global): State<crate::Global>,
|
State(global): State<crate::Global>,
|
||||||
Path((repo, arch)): Path<(String, String)>,
|
Path((repo, arch)): Path<(String, String)>,
|
||||||
) -> crate::Result<StatusCode> {
|
) -> crate::Result<StatusCode> {
|
||||||
Ok(StatusCode::NOT_FOUND)
|
let repo_removed = global
|
||||||
//let clone = Arc::clone(&global.repo_manager);
|
.repo_manager
|
||||||
//
|
.write()
|
||||||
//let arch_clone = arch.clone();
|
.await
|
||||||
//let repo_clone = repo.clone();
|
.remove_repo_arch(&global.db, &repo, &arch)
|
||||||
//let repo_removed = tokio::task::spawn_blocking(move || {
|
.await?;
|
||||||
// clone
|
|
||||||
// .write()
|
if repo_removed {
|
||||||
// .unwrap()
|
tracing::info!("Removed arch '{}' from repository '{}'", arch, repo);
|
||||||
// .remove_repo_arch(&repo_clone, &arch_clone)
|
|
||||||
//})
|
Ok(StatusCode::OK)
|
||||||
//.await??;
|
} else {
|
||||||
//
|
Ok(StatusCode::NOT_FOUND)
|
||||||
//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)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_package(
|
async fn delete_package(
|
||||||
|
|
Loading…
Reference in New Issue