From d48771c08f1f9ddf0a97ec92cb63fb6496ff80c4 Mon Sep 17 00:00:00 2001 From: Trent <2771466+tbillington@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:14:36 +0100 Subject: [PATCH] prevent .net projects clobbering unity or godot projects --- kondo-lib/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/kondo-lib/src/lib.rs b/kondo-lib/src/lib.rs index 30a1d88..43748b6 100644 --- a/kondo-lib/src/lib.rs +++ b/kondo-lib/src/lib.rs @@ -1,7 +1,8 @@ use std::{ borrow::Cow, error::{self, Error}, - fs, path, + fs, + path::{self, Path}, time::SystemTime, }; @@ -375,7 +376,13 @@ impl Iterator for ProjectIter { if file_name.ends_with(FILE_CSPROJ_SUFFIX) || file_name.ends_with(FILE_FSPROJ_SUFFIX) => { - Some(ProjectType::Dotnet) + if dir_contains_file(entry.path(), FILE_GODOT_4_PROJECT) { + Some(ProjectType::Godot4) + } else if dir_contains_file(entry.path(), FILE_ASSEMBLY_CSHARP) { + Some(ProjectType::Unity) + } else { + Some(ProjectType::Dotnet) + } } _ => None, }; @@ -391,6 +398,16 @@ impl Iterator for ProjectIter { } } +fn dir_contains_file(path: &Path, file: &str) -> bool { + path.read_dir() + .map(|rd| { + rd.filter_map(|rd| rd.ok()).any(|de| { + de.file_type().is_ok_and(|t| t.is_file()) && de.file_name().to_str() == Some(file) + }) + }) + .unwrap_or(false) +} + #[derive(Clone, Debug)] pub struct ScanOptions { pub follow_symlinks: bool,