feat: re-implement package remove route

concurrent-repos
Jef Roosens 2024-05-29 09:58:19 +02:00
parent 044d3a33eb
commit 60d4478d83
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
7 changed files with 45 additions and 38 deletions

1
Cargo.lock generated
View File

@ -1660,7 +1660,6 @@ dependencies = [
"futures",
"http-body-util",
"libarchive",
"regex",
"sea-orm",
"sea-orm-migration",
"serde",

View File

@ -22,6 +22,13 @@ Another usecase for this would be creating a local mirror of your
distribution's repositories, which can greatly reduce your update times
depending on your internet connection.
Most users however don't need a full copy of a distro's package repository, so
Rieter also provides a "smart mirror" mode. In this mode, a Rieter instance
only syncs packages that have been requested before, e.g. from a previous
system update. This way, your updates will still be a lot faster as the
required packages are cached, but packages you don't use don't get stored,
saving you a lot of storage space.
### Build system
The second goal is to create an easy-to-use build system for Pacman packages.

View File

@ -13,7 +13,6 @@ clap = { version = "4.3.12", features = ["env", "derive"] }
futures = "0.3.28"
http-body-util = "0.1.1"
libarchive = { path = "../libarchive" }
regex = "1.10.4"
sea-orm-migration = "0.12.1"
serde = { version = "1.0.178", features = ["derive"] }
sha256 = "1.1.4"

View File

@ -83,13 +83,10 @@ impl Cli {
};
let repo_manager = MetaRepoMgr::new(&self.data_dir.join("repos"));
let pkg_filename_re = regex::Regex::new(r"^([a-z0-9@_+][a-z0-9@_+-.]*)-((?:[0-9]+:)?[a-z0-9._]+-[0-9.]+)-([a-z0-9_]+)\.pkg\.tar\.([a-z0-9]+)$").unwrap();
let global = Global {
config,
repo_manager: Arc::new(RwLock::new(repo_manager)),
db,
pkg_filename_re,
};
// build our application with a single route

View File

@ -21,7 +21,6 @@ pub struct Global {
config: Config,
repo_manager: Arc<RwLock<MetaRepoMgr>>,
db: sea_orm::DbConn,
pkg_filename_re: regex::Regex,
}
#[tokio::main]

View File

@ -107,8 +107,10 @@ impl MetaRepoMgr {
ar_db.close().await?;
ar_files.close().await?;
tokio::fs::remove_file(desc_tmp_file_path).await?;
tokio::fs::remove_file(files_tmp_file_path).await?;
// If this fails there's no point in failing the function + if there were no packages in
// the repo, this fails anyway because the temp file doesn't exist
let _ = tokio::fs::remove_file(desc_tmp_file_path).await;
let _ = tokio::fs::remove_file(files_tmp_file_path).await;
Ok(())
}
@ -188,8 +190,21 @@ impl MetaRepoMgr {
let pkg = db::query::package::by_fields(conn, repo.id, arch, name, None, None).await?;
if let Some(pkg) = pkg {
// Remove package from database
// Remove package from database & file system
tokio::fs::remove_file(
self.repo_dir
.join(&repo.name)
.join(super::package::filename(&pkg)),
)
.await?;
pkg.delete(conn).await?;
if arch == ANY_ARCH {
self.generate_archives_all(conn, &repo.name).await?;
} else {
self.generate_archives(conn, &repo.name, arch).await?;
}
Ok(true)
} else {
Ok(false)

View File

@ -126,34 +126,25 @@ async fn delete_arch_repo(
async fn delete_package(
State(global): State<crate::Global>,
Path((repo, arch, file_name)): Path<(String, String, String)>,
Path((repo, arch, pkg_name)): Path<(String, String, String)>,
) -> crate::Result<StatusCode> {
Ok(StatusCode::NOT_FOUND)
//global.repo_manager.write().unwrap().remove_pkg(&global.db, &repo, &arch, name)
//let clone = Arc::clone(&global.repo_manager);
//let path = PathBuf::from(&repo).join(arch).join(&file_name);
//
//let res = tokio::task::spawn_blocking(move || {
// clone.write().unwrap().remove_pkg_from_path(path, true)
//})
//.await??;
//
//if let Some((name, version, release, arch)) = res {
// let res = db::query::repo::by_name(&global.db, &repo).await?;
//
// if let Some(repo_entry) = res {
// let res =
// db::query::package::by_fields(&global.db, repo_entry.id, &arch, &name).await?;
//
// if let Some(entry) = res {
// entry.delete(&global.db).await?;
// }
// }
//
// tracing::info!("Removed '{}' from repository '{}'", file_name, repo);
//
// Ok(StatusCode::OK)
//} else {
// Ok(StatusCode::NOT_FOUND)
//}
let pkg_removed = global
.repo_manager
.write()
.await
.remove_pkg(&global.db, &repo, &arch, &pkg_name)
.await?;
if pkg_removed {
tracing::info!(
"Removed package '{}' ({}) from repository '{}'",
pkg_name,
arch,
repo
);
Ok(StatusCode::OK)
} else {
Ok(StatusCode::NOT_FOUND)
}
}