Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit e1ce390

Browse files
committed
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.
1 parent 1c0619c commit e1ce390

6 files changed

Lines changed: 5 additions & 94 deletions

File tree

libips/src/digest/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ impl Digest {
130130
DigestAlgorithm::SHA3512 => {
131131
format!("{:x}", sha3::Sha3_512::digest(b))
132132
}
133-
x => {
134-
return Err(DigestError::UnknownAlgorithm {
135-
algorithm: x.to_string(),
136-
});
137-
}
138133
};
139134

140135
Ok(Digest {
@@ -186,11 +181,6 @@ impl Digest {
186181
std::io::copy(&mut r, &mut hasher).map_err(DigestError::from)?;
187182
format!("{:x}", hasher.finalize())
188183
}
189-
x => {
190-
return Err(DigestError::UnknownAlgorithm {
191-
algorithm: x.to_string(),
192-
});
193-
}
194184
};
195185

196186
Ok(Digest {

libips/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#![allow(unused_assignments)]
12
// This Source Code Form is subject to the terms of
23
// the Mozilla Public License, v. 2.0. If a copy of the
34
// MPL was not distributed with this file, You can
45
// obtain one at https://mozilla.org/MPL/2.0/.
56

67
#[allow(clippy::result_large_err)]
8+
#[allow(unused_assignments)]
79
pub mod actions;
810
pub mod api;
911
pub mod depend;

libips/src/recv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ mod tests {
246246
let mut source_repo = FileBackend::create(source_dir.path(), RepositoryVersion::V4)?;
247247
source_repo.add_publisher("test")?;
248248

249-
let fmri = Fmri::parse("pkg://test/pkgA@1.0").unwrap();
249+
let _fmri = Fmri::parse("pkg://test/pkgA@1.0").unwrap();
250250
let manifest_content = "set name=pkg.fmri value=pkg://test/pkgA@1.0\nset name=pkg.summary value=test\n";
251251

252252
// Manually write the manifest in IPS format to the source repo

libips/src/repository/file_backend.rs

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -190,87 +190,6 @@ impl SearchIndex {
190190
.push(entry);
191191
}
192192

193-
/// Add a package to the index
194-
fn add_package(&mut self, package: &PackageInfo, contents: Option<&PackageContents>) {
195-
// Get the FMRI as a string
196-
let fmri = package.fmri.to_string();
197-
let stem = package.fmri.stem();
198-
199-
// Add package mapping
200-
self.packages.insert(fmri.clone(), stem.to_string());
201-
202-
// 1. Index package stem (action=pkg, index=name)
203-
// Note: Legacy pkg search often uses 'set' action for package attributes, but let's use what we have.
204-
// Actually man page says `pkg_name` is implicit.
205-
// Let's index it as: action="pkg", index="name", value=stem
206-
self.add_term(stem, &fmri, "pkg", "name", stem, None);
207-
208-
// Also index parts of the stem if it contains '/'?
209-
// Legacy behavior might index tokens.
210-
for part in stem.split('/') {
211-
if part != stem {
212-
self.add_term(part, &fmri, "pkg", "name", stem, None);
213-
}
214-
}
215-
216-
// 2. Index Publisher (action=pkg, index=publisher)
217-
if let Some(publisher) = &package.fmri.publisher {
218-
self.add_term(publisher, &fmri, "pkg", "publisher", publisher, None);
219-
}
220-
221-
// 3. Index Version (action=pkg, index=version)
222-
let version = package.fmri.version();
223-
if !version.is_empty() {
224-
self.add_term(&version, &fmri, "pkg", "version", &version, None);
225-
}
226-
227-
// 4. Index Contents
228-
if let Some(content) = contents {
229-
// Add files
230-
if let Some(files) = &content.files {
231-
for file in files {
232-
// index=path
233-
self.add_term(file, &fmri, "file", "path", file, None);
234-
// index=basename
235-
if let Some(basename) = Path::new(file).file_name().and_then(|s| s.to_str()) {
236-
self.add_term(basename, &fmri, "file", "basename", file, None);
237-
}
238-
}
239-
}
240-
241-
// Add directories
242-
if let Some(directories) = &content.directories {
243-
for dir in directories {
244-
// index=path
245-
self.add_term(dir, &fmri, "dir", "path", dir, None);
246-
// index=basename
247-
if let Some(basename) = Path::new(dir).file_name().and_then(|s| s.to_str()) {
248-
self.add_term(basename, &fmri, "dir", "basename", dir, None);
249-
}
250-
}
251-
}
252-
253-
// Add dependencies
254-
if let Some(dependencies) = &content.dependencies {
255-
for dep in dependencies {
256-
// dep is an FMRI string usually.
257-
// index=fmri, value=dep
258-
self.add_term(dep, &fmri, "depend", "fmri", dep, None);
259-
// maybe parse stem from dep fmri?
260-
if let Ok(dep_fmri) = Fmri::parse(dep) {
261-
self.add_term(dep_fmri.stem(), &fmri, "depend", "fmri", dep, None);
262-
}
263-
}
264-
}
265-
}
266-
267-
// Update the timestamp
268-
self.updated = SystemTime::now()
269-
.duration_since(UNIX_EPOCH)
270-
.unwrap_or_default()
271-
.as_secs();
272-
}
273-
274193
/// Search the index for packages matching a query
275194
fn search(&self, query: &str, case_sensitive: bool, limit: Option<usize>) -> Vec<IndexEntry> {
276195
// Split the query into terms (whitespace)

pkg6depotd/src/repo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl DepotRepo {
5757
}
5858

5959
pub fn get_manifest_text(&self, publisher: &str, fmri: &Fmri) -> Result<String> {
60-
let backend = self
60+
let mut backend = self
6161
.backend
6262
.lock()
6363
.map_err(|e| DepotError::Server(format!("Lock poisoned: {}", e)))?;

pkg6depotd/tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async fn test_depot_server() {
213213
#[tokio::test]
214214
async fn test_ini_only_repo_serving_catalog() {
215215
use libips::repository::BatchOptions;
216-
use libips::repository::{ReadableRepository, WritableRepository};
216+
use libips::repository::WritableRepository;
217217
use std::io::Write as _;
218218

219219
// Setup temp repo

0 commit comments

Comments
 (0)