Skip to content

Commit

Permalink
prevent .net projects clobbering unity or godot projects
Browse files Browse the repository at this point in the history
  • Loading branch information
tbillington committed Dec 11, 2023
1 parent 8b76375 commit d48771c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions kondo-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{
borrow::Cow,
error::{self, Error},
fs, path,
fs,
path::{self, Path},
time::SystemTime,
};

Expand Down Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down

0 comments on commit d48771c

Please sign in to comment.