diff --git a/Cargo.lock b/Cargo.lock index 333bc72..d0c00b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1660,6 +1660,7 @@ dependencies = [ "futures", "http-body-util", "libarchive", + "regex", "sea-orm", "sea-orm-migration", "serde", diff --git a/README.md b/README.md index 1111131..ed400e6 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,6 @@ 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. diff --git a/server/Cargo.toml b/server/Cargo.toml index cd86713..03ff93e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -13,6 +13,7 @@ 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" diff --git a/server/src/cli.rs b/server/src/cli.rs index 036c70b..db7f705 100644 --- a/server/src/cli.rs +++ b/server/src/cli.rs @@ -83,10 +83,13 @@ 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 diff --git a/server/src/db/query/package.rs b/server/src/db/query/package.rs index 6cd709f..8a211bf 100644 --- a/server/src/db/query/package.rs +++ b/server/src/db/query/package.rs @@ -133,7 +133,7 @@ pub async fn insert(conn: &DbConn, repo_id: i32, pkg: crate::repo::package::Pack .chain( info.makedepends .iter() - .map(|s| (PackageRelatedEnum::Makedepend, s)), + .map(|s| (PackageRelatedEnum::Depend, s)), ) .chain( info.checkdepends diff --git a/server/src/main.rs b/server/src/main.rs index c57420a..c539b9e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -21,6 +21,7 @@ pub struct Global { config: Config, repo_manager: Arc>, db: sea_orm::DbConn, + pkg_filename_re: regex::Regex, } #[tokio::main] diff --git a/server/src/repo/manager_new.rs b/server/src/repo/manager_new.rs index adf37a9..4d60bcf 100644 --- a/server/src/repo/manager_new.rs +++ b/server/src/repo/manager_new.rs @@ -107,10 +107,8 @@ impl MetaRepoMgr { ar_db.close().await?; ar_files.close().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; + tokio::fs::remove_file(desc_tmp_file_path).await?; + tokio::fs::remove_file(files_tmp_file_path).await?; Ok(()) } @@ -190,21 +188,8 @@ 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 & file system - tokio::fs::remove_file( - self.repo_dir - .join(&repo.name) - .join(super::package::filename(&pkg)), - ) - .await?; + // Remove package from database 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) @@ -219,7 +204,7 @@ impl MetaRepoMgr { conn: &DbConn, reader: &mut R, repo: &str, - ) -> crate::Result<(String, String, String)> { + ) -> crate::Result<()> { // Copy file contents to temporary path so libarchive can work with it let uuid: uuid::fmt::Simple = Uuid::new_v4().into(); let path = self.repo_dir.join(uuid.to_string()); @@ -262,8 +247,6 @@ impl MetaRepoMgr { let dest_pkg_path = self.repo_dir.join(repo).join(pkg.file_name()); // Insert new package into database - let name = pkg.info.name.clone(); - let version = pkg.info.version.clone(); let arch = pkg.info.arch.clone(); db::query::package::insert(conn, repo_id, pkg).await?; @@ -273,11 +256,9 @@ impl MetaRepoMgr { // Synchronize archive databases if arch == ANY_ARCH { - self.generate_archives_all(conn, repo).await?; + self.generate_archives_all(conn, repo).await } else { - self.generate_archives(conn, repo, &arch).await?; + self.generate_archives(conn, repo, &arch).await } - - Ok((name, version, arch)) } } diff --git a/server/src/repo/mod.rs b/server/src/repo/mod.rs index f5e48d4..072ceef 100644 --- a/server/src/repo/mod.rs +++ b/server/src/repo/mod.rs @@ -69,17 +69,19 @@ async fn post_package_archive( Path(repo): Path, body: Body, ) -> crate::Result<()> { - let mut body = StreamReader::new(body.into_data_stream().map_err(std::io::Error::other)); - let (name, version, arch) = global + let body = body.into_data_stream(); + let body = body.map_err(std::io::Error::other); + let mut body = StreamReader::new(body); + global .repo_manager .write() .await .add_pkg_from_reader(&global.db, &mut body, &repo) .await?; - tracing::info!("Added '{}-{}' to repository '{}' ({})", name, version, repo, arch); - Ok(()) + + //tracing::info!("Added '{}' to repository '{}'", pkg.file_name(), repo); } async fn delete_repo( @@ -124,25 +126,34 @@ async fn delete_arch_repo( async fn delete_package( State(global): State, - Path((repo, arch, pkg_name)): Path<(String, String, String)>, + Path((repo, arch, file_name)): Path<(String, String, String)>, ) -> crate::Result { - 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) - } + 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) + //} }