Fix tripplet typo in function and variable names, replace unwrap with proper error handling, refine comments for clarity and grammar, and enhance file existence check by returning an error instead of a warning.

This commit is contained in:
Till Wegmueller 2025-07-26 23:49:26 +02:00
parent ad153a65ab
commit e222937201
No known key found for this signature in database

View file

@ -9,7 +9,7 @@ use std::collections::HashMap;
use std::fs::{read_dir, OpenOptions}; use std::fs::{read_dir, OpenOptions};
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use tracing::{debug, error, info, warn, trace}; use tracing::{debug, info, warn};
use tracing_subscriber::fmt; use tracing_subscriber::fmt;
use userland::repology::find_newest_version; use userland::repology::find_newest_version;
use userland::{Component, Makefile}; use userland::{Component, Makefile};
@ -84,7 +84,7 @@ fn main() -> Result<()> {
} }
} }
fn parse_tripplet_replacements(replacements: &[String]) -> HashMap<String, String> { fn parse_triplet_replacements(replacements: &[String]) -> HashMap<String, String> {
let mut map = HashMap::new(); let mut map = HashMap::new();
for pair in replacements for pair in replacements
.iter() .iter()
@ -124,7 +124,7 @@ fn diff_component(
}); });
} }
} }
let map = parse_tripplet_replacements(replacements); let map = parse_triplet_replacements(replacements);
Some(map) Some(map)
} else { } else {
None None
@ -146,7 +146,7 @@ fn diff_component(
.map(|e| e.path().into_os_string().into_string().unwrap()) .map(|e| e.path().into_os_string().into_string().unwrap())
.collect(); .collect();
// Check for sample manifest // Check for the sample manifest
let sample_manifest_file = &component_path_ref.join("manifests/sample-manifest.p5m"); let sample_manifest_file = &component_path_ref.join("manifests/sample-manifest.p5m");
if !sample_manifest_file.exists() { if !sample_manifest_file.exists() {
return Err(Pkg6DevError::ManifestNotFoundError { return Err(Pkg6DevError::ManifestNotFoundError {
@ -163,7 +163,7 @@ fn diff_component(
let sample_manifest = Manifest::parse_file(sample_manifest_file)?; let sample_manifest = Manifest::parse_file(sample_manifest_file)?;
// Unwrap manifests result // Unwrap manifests result
let manifests: Vec<Manifest> = manifests_res.unwrap(); let manifests: Vec<Manifest> = manifests_res?;
// Find missing files // Find missing files
let missing_files = let missing_files =
@ -210,7 +210,7 @@ fn show_component_info<P: AsRef<Path>>(component_path: P) -> Result<()> {
}); });
} }
// Get Makefile path // Get a Makefile path
let makefile_path = component_path_ref.join("Makefile"); let makefile_path = component_path_ref.join("Makefile");
if !makefile_path.exists() { if !makefile_path.exists() {
return Err(Pkg6DevError::MakefileParseError { return Err(Pkg6DevError::MakefileParseError {
@ -390,7 +390,7 @@ fn make_file_map(files: Vec<File>) -> HashMap<String, File> {
/// ///
/// This function: /// This function:
/// 1. Opens the repository at the specified path /// 1. Opens the repository at the specified path
/// 2. Parses the manifest file /// 2. Parses manifest file
/// 3. Uses the FileBackend's publish_files method to publish the files from the prototype directory /// 3. Uses the FileBackend's publish_files method to publish the files from the prototype directory
fn publish_package( fn publish_package(
manifest_path: &PathBuf, manifest_path: &PathBuf,
@ -462,15 +462,7 @@ fn publish_package(
// Check if the file exists // Check if the file exists
if !file_path.exists() { if !file_path.exists() {
// Instead of just a warning, we could return an error here, but that might be too strict return Err(Pkg6DevError::FileNotFoundInPrototypeError{path: file_path.clone()})
// For now, we'll keep the warning but use a more structured approach
warn!(
"File does not exist in prototype directory: {}",
file_path.display()
);
// We continue here instead of returning an error to allow the operation to proceed
// with the files that do exist
continue;
} }
// Add the file to the transaction // Add the file to the transaction