mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 21:30:41 +00:00
Refactor code to simplify handling and remove unused functions
- Removed `add_package` function from `FileBackend`, consolidating package indexing logic. - Allowed unused assignments using `#![allow(unused_assignments)]` where necessary. - Addressed unused imports in integration tests. - Simplified `Digest` error handling by removing unreachable branches for unknown algorithms.
This commit is contained in:
parent
1c0619ca55
commit
e1ce390abd
6 changed files with 5 additions and 94 deletions
|
|
@ -130,11 +130,6 @@ impl Digest {
|
||||||
DigestAlgorithm::SHA3512 => {
|
DigestAlgorithm::SHA3512 => {
|
||||||
format!("{:x}", sha3::Sha3_512::digest(b))
|
format!("{:x}", sha3::Sha3_512::digest(b))
|
||||||
}
|
}
|
||||||
x => {
|
|
||||||
return Err(DigestError::UnknownAlgorithm {
|
|
||||||
algorithm: x.to_string(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Digest {
|
Ok(Digest {
|
||||||
|
|
@ -186,11 +181,6 @@ impl Digest {
|
||||||
std::io::copy(&mut r, &mut hasher).map_err(DigestError::from)?;
|
std::io::copy(&mut r, &mut hasher).map_err(DigestError::from)?;
|
||||||
format!("{:x}", hasher.finalize())
|
format!("{:x}", hasher.finalize())
|
||||||
}
|
}
|
||||||
x => {
|
|
||||||
return Err(DigestError::UnknownAlgorithm {
|
|
||||||
algorithm: x.to_string(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Digest {
|
Ok(Digest {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
#![allow(unused_assignments)]
|
||||||
// This Source Code Form is subject to the terms of
|
// This Source Code Form is subject to the terms of
|
||||||
// the Mozilla Public License, v. 2.0. If a copy of the
|
// the Mozilla Public License, v. 2.0. If a copy of the
|
||||||
// MPL was not distributed with this file, You can
|
// MPL was not distributed with this file, You can
|
||||||
// obtain one at https://mozilla.org/MPL/2.0/.
|
// obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#[allow(clippy::result_large_err)]
|
#[allow(clippy::result_large_err)]
|
||||||
|
#[allow(unused_assignments)]
|
||||||
pub mod actions;
|
pub mod actions;
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod depend;
|
pub mod depend;
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ mod tests {
|
||||||
let mut source_repo = FileBackend::create(source_dir.path(), RepositoryVersion::V4)?;
|
let mut source_repo = FileBackend::create(source_dir.path(), RepositoryVersion::V4)?;
|
||||||
source_repo.add_publisher("test")?;
|
source_repo.add_publisher("test")?;
|
||||||
|
|
||||||
let fmri = Fmri::parse("pkg://test/pkgA@1.0").unwrap();
|
let _fmri = Fmri::parse("pkg://test/pkgA@1.0").unwrap();
|
||||||
let manifest_content = "set name=pkg.fmri value=pkg://test/pkgA@1.0\nset name=pkg.summary value=test\n";
|
let manifest_content = "set name=pkg.fmri value=pkg://test/pkgA@1.0\nset name=pkg.summary value=test\n";
|
||||||
|
|
||||||
// Manually write the manifest in IPS format to the source repo
|
// Manually write the manifest in IPS format to the source repo
|
||||||
|
|
|
||||||
|
|
@ -190,87 +190,6 @@ impl SearchIndex {
|
||||||
.push(entry);
|
.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a package to the index
|
|
||||||
fn add_package(&mut self, package: &PackageInfo, contents: Option<&PackageContents>) {
|
|
||||||
// Get the FMRI as a string
|
|
||||||
let fmri = package.fmri.to_string();
|
|
||||||
let stem = package.fmri.stem();
|
|
||||||
|
|
||||||
// Add package mapping
|
|
||||||
self.packages.insert(fmri.clone(), stem.to_string());
|
|
||||||
|
|
||||||
// 1. Index package stem (action=pkg, index=name)
|
|
||||||
// Note: Legacy pkg search often uses 'set' action for package attributes, but let's use what we have.
|
|
||||||
// Actually man page says `pkg_name` is implicit.
|
|
||||||
// Let's index it as: action="pkg", index="name", value=stem
|
|
||||||
self.add_term(stem, &fmri, "pkg", "name", stem, None);
|
|
||||||
|
|
||||||
// Also index parts of the stem if it contains '/'?
|
|
||||||
// Legacy behavior might index tokens.
|
|
||||||
for part in stem.split('/') {
|
|
||||||
if part != stem {
|
|
||||||
self.add_term(part, &fmri, "pkg", "name", stem, None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Index Publisher (action=pkg, index=publisher)
|
|
||||||
if let Some(publisher) = &package.fmri.publisher {
|
|
||||||
self.add_term(publisher, &fmri, "pkg", "publisher", publisher, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Index Version (action=pkg, index=version)
|
|
||||||
let version = package.fmri.version();
|
|
||||||
if !version.is_empty() {
|
|
||||||
self.add_term(&version, &fmri, "pkg", "version", &version, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Index Contents
|
|
||||||
if let Some(content) = contents {
|
|
||||||
// Add files
|
|
||||||
if let Some(files) = &content.files {
|
|
||||||
for file in files {
|
|
||||||
// index=path
|
|
||||||
self.add_term(file, &fmri, "file", "path", file, None);
|
|
||||||
// index=basename
|
|
||||||
if let Some(basename) = Path::new(file).file_name().and_then(|s| s.to_str()) {
|
|
||||||
self.add_term(basename, &fmri, "file", "basename", file, None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add directories
|
|
||||||
if let Some(directories) = &content.directories {
|
|
||||||
for dir in directories {
|
|
||||||
// index=path
|
|
||||||
self.add_term(dir, &fmri, "dir", "path", dir, None);
|
|
||||||
// index=basename
|
|
||||||
if let Some(basename) = Path::new(dir).file_name().and_then(|s| s.to_str()) {
|
|
||||||
self.add_term(basename, &fmri, "dir", "basename", dir, None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add dependencies
|
|
||||||
if let Some(dependencies) = &content.dependencies {
|
|
||||||
for dep in dependencies {
|
|
||||||
// dep is an FMRI string usually.
|
|
||||||
// index=fmri, value=dep
|
|
||||||
self.add_term(dep, &fmri, "depend", "fmri", dep, None);
|
|
||||||
// maybe parse stem from dep fmri?
|
|
||||||
if let Ok(dep_fmri) = Fmri::parse(dep) {
|
|
||||||
self.add_term(dep_fmri.stem(), &fmri, "depend", "fmri", dep, None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the timestamp
|
|
||||||
self.updated = SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.as_secs();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Search the index for packages matching a query
|
/// Search the index for packages matching a query
|
||||||
fn search(&self, query: &str, case_sensitive: bool, limit: Option<usize>) -> Vec<IndexEntry> {
|
fn search(&self, query: &str, case_sensitive: bool, limit: Option<usize>) -> Vec<IndexEntry> {
|
||||||
// Split the query into terms (whitespace)
|
// Split the query into terms (whitespace)
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ impl DepotRepo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_manifest_text(&self, publisher: &str, fmri: &Fmri) -> Result<String> {
|
pub fn get_manifest_text(&self, publisher: &str, fmri: &Fmri) -> Result<String> {
|
||||||
let backend = self
|
let mut backend = self
|
||||||
.backend
|
.backend
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|e| DepotError::Server(format!("Lock poisoned: {}", e)))?;
|
.map_err(|e| DepotError::Server(format!("Lock poisoned: {}", e)))?;
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ async fn test_depot_server() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_ini_only_repo_serving_catalog() {
|
async fn test_ini_only_repo_serving_catalog() {
|
||||||
use libips::repository::BatchOptions;
|
use libips::repository::BatchOptions;
|
||||||
use libips::repository::{ReadableRepository, WritableRepository};
|
use libips::repository::WritableRepository;
|
||||||
use std::io::Write as _;
|
use std::io::Write as _;
|
||||||
|
|
||||||
// Setup temp repo
|
// Setup temp repo
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue