mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 21:30:41 +00:00
Refactor catalog handling by replacing get_legacy_catalog with get_catalog_file_path for improved clarity and consistency.
- Removed now-redundant catalog path resolution logic in `repo.rs`. - Updated `file_backend` with a unified method for fetching catalog file paths, addressing invalid path prefixes. - Adjusted HTTP handler to use the updated method.
This commit is contained in:
parent
55decc16ff
commit
81bc7b8574
3 changed files with 20 additions and 18 deletions
|
|
@ -1695,9 +1695,23 @@ impl FileBackend {
|
||||||
}
|
}
|
||||||
Err(RepositoryError::NotFound(format!("manifest for {} not found", fmri)))
|
Err(RepositoryError::NotFound(format!("manifest for {} not found", fmri)))
|
||||||
}
|
}
|
||||||
/// Fetch legacy catalog content (stub)
|
/// Fetch catalog file path
|
||||||
pub fn fetch_legacy_catalog(&self, _publisher: &str, _filename: &str) -> Result<PathBuf> {
|
pub fn get_catalog_file_path(&self, publisher: &str, filename: &str) -> Result<PathBuf> {
|
||||||
todo!("Implement legacy catalog format for REST API");
|
if filename.contains('/') || filename.contains('\\') {
|
||||||
|
return Err(RepositoryError::PathPrefixError(filename.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let catalog_dir = Self::construct_catalog_path(&self.path, publisher);
|
||||||
|
let path = catalog_dir.join(filename);
|
||||||
|
|
||||||
|
if path.exists() {
|
||||||
|
Ok(path)
|
||||||
|
} else {
|
||||||
|
Err(RepositoryError::NotFound(format!(
|
||||||
|
"Catalog file {} for publisher {} not found",
|
||||||
|
filename, publisher
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Save the legacy pkg5.repository INI file for backward compatibility
|
/// Save the legacy pkg5.repository INI file for backward compatibility
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ pub async fn get_catalog_v1(
|
||||||
Path((publisher, filename)): Path<(String, String)>,
|
Path((publisher, filename)): Path<(String, String)>,
|
||||||
req: Request,
|
req: Request,
|
||||||
) -> Result<Response, DepotError> {
|
) -> Result<Response, DepotError> {
|
||||||
let path = repo.get_legacy_catalog(&publisher, &filename)?;
|
let path = repo.get_catalog_file_path(&publisher, &filename)?;
|
||||||
|
|
||||||
let service = ServeFile::new(path);
|
let service = ServeFile::new(path);
|
||||||
let result = service.oneshot(req).await;
|
let result = service.oneshot(req).await;
|
||||||
|
|
|
||||||
|
|
@ -36,23 +36,11 @@ impl DepotRepo {
|
||||||
backend.fetch_manifest_text(publisher, fmri).map_err(DepotError::Repo)
|
backend.fetch_manifest_text(publisher, fmri).map_err(DepotError::Repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_legacy_catalog(&self, publisher: &str, filename: &str) -> Result<PathBuf> {
|
pub fn get_catalog_file_path(&self, publisher: &str, filename: &str) -> Result<PathBuf> {
|
||||||
let backend = self.backend.lock().map_err(|e| DepotError::Server(format!("Lock poisoned: {}", e)))?;
|
let backend = self.backend.lock().map_err(|e| DepotError::Server(format!("Lock poisoned: {}", e)))?;
|
||||||
backend.fetch_legacy_catalog(publisher, filename).map_err(DepotError::Repo)
|
backend.get_catalog_file_path(publisher, filename).map_err(DepotError::Repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_catalog_file_path(&self, publisher: &str, filename: &str) -> Option<PathBuf> {
|
|
||||||
if filename.contains('/') || filename.contains('\\') {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let catalog_dir = self.get_catalog_path(publisher);
|
|
||||||
let path = catalog_dir.join(filename);
|
|
||||||
if path.exists() {
|
|
||||||
Some(path)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_info(&self) -> Result<libips::repository::RepositoryInfo> {
|
pub fn get_info(&self) -> Result<libips::repository::RepositoryInfo> {
|
||||||
let backend = self.backend.lock().map_err(|e| DepotError::Server(format!("Lock poisoned: {}", e)))?;
|
let backend = self.backend.lock().map_err(|e| DepotError::Server(format!("Lock poisoned: {}", e)))?;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue