treewide: fix clippy lints

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I411be69ff31f9cb39cd4cdebc8985b366a6a6964
This commit is contained in:
raf 2026-04-21 18:08:41 +03:00
commit 61ced09d25
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
43 changed files with 558 additions and 464 deletions

View file

@ -19,6 +19,10 @@ enum SyncChange {
Removal(String), // project_pakku_id
}
#[expect(
clippy::expect_used,
reason = "spinner template is a string literal and is always valid"
)]
pub async fn execute(
args: SyncArgs,
global_yes: bool,
@ -27,14 +31,14 @@ pub async fn execute(
) -> Result<()> {
log::info!("Synchronizing with lockfile");
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
let config_dir = config_path.parent().unwrap_or(Path::new("."));
let lockfile_dir = lockfile_path.parent().unwrap_or_else(|| Path::new("."));
let config_dir = config_path.parent().unwrap_or_else(|| Path::new("."));
let mut lockfile = LockFile::load(lockfile_dir)?;
let config = Config::load(config_dir)?;
// Detect changes
let changes = detect_changes(&lockfile, &config)?;
let changes = detect_changes(&lockfile, &config);
if changes.is_empty() {
println!("✓ Everything is in sync");
@ -59,7 +63,7 @@ pub async fn execute(
spinner.set_style(
ProgressStyle::default_spinner()
.template("{spinner:.green} {msg}")
.unwrap(),
.expect("spinner template is valid"),
);
if no_filter || args.additions {
@ -145,10 +149,7 @@ pub async fn execute(
Ok(())
}
fn detect_changes(
lockfile: &LockFile,
config: &Config,
) -> Result<Vec<SyncChange>> {
fn detect_changes(lockfile: &LockFile, config: &Config) -> Vec<SyncChange> {
let mut changes = Vec::new();
// Get paths for each project type
@ -177,23 +178,26 @@ fn detect_changes(
&& ext == "jar"
&& !lockfile_files.contains_key(&path)
{
let name = path.file_name().unwrap().to_string_lossy().to_string();
let name = path
.file_name()
.map(|n| n.to_string_lossy().to_string())
.unwrap_or_default();
changes.push(SyncChange::Addition(path, name));
}
}
}
// Check for removals (projects in lockfile but files missing)
let filesystem_files: HashSet<_> =
if let Ok(entries) = fs::read_dir(mods_path) {
let filesystem_files: HashSet<_> = fs::read_dir(mods_path).map_or_else(
|_| HashSet::new(),
|entries| {
entries
.flatten()
.map(|e| e.path())
.filter(|p| p.is_file())
.collect()
} else {
HashSet::new()
};
},
);
for (lockfile_path, pakku_id) in &lockfile_files {
if !filesystem_files.contains(lockfile_path) {
@ -201,7 +205,7 @@ fn detect_changes(
}
}
Ok(changes)
changes
}
async fn add_file_to_lockfile(
@ -209,14 +213,14 @@ async fn add_file_to_lockfile(
file_path: &Path,
_config: &Config,
) -> Result<()> {
use sha1::Digest;
// Try to identify the file by hash lookup
let modrinth = ModrinthPlatform::new();
let curseforge = CurseForgePlatform::new(None);
// Compute file hash
let file_data = fs::read(file_path)?;
// Compute SHA-1 hash from file bytes
use sha1::Digest;
let mut hasher = sha1::Sha1::new();
hasher.update(&file_data);
let hash = crate::utils::hash::hash_to_hex(hasher.finalize().as_slice());