summaryrefslogtreecommitdiff
path: root/systems/_framework/src/space.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-11 15:01:55 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-11 15:01:55 +0800
commite49128388e3b2f73523d82bf7f16fa1eae019c37 (patch)
tree6531b20126434be9087ce0ab97e2412816e8e4f7 /systems/_framework/src/space.rs
parenta6b38c2918ece9d763a1eb1d581268d94b2bdcf0 (diff)
Fix handling of dot dir names in find_space_root_with
Diffstat (limited to 'systems/_framework/src/space.rs')
-rw-r--r--systems/_framework/src/space.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/systems/_framework/src/space.rs b/systems/_framework/src/space.rs
index 8a82467..47d3c0d 100644
--- a/systems/_framework/src/space.rs
+++ b/systems/_framework/src/space.rs
@@ -374,6 +374,21 @@ pub fn find_space_root(pattern: SpaceRootFindPattern) -> Result<PathBuf, SpaceEr
/// # use std::path::PathBuf;
/// # use framework::space::SpaceRootFindPattern;
/// # use framework::space::find_space_root_with;
+/// // Find the `.cargo` directory
+/// let path = find_space_root_with(
+/// current_dir().unwrap(),
+/// SpaceRootFindPattern::IncludeDotDir(
+/// ".cargo".into()
+/// )
+/// );
+/// assert!(path.is_ok());
+/// assert!(path.unwrap().join(".cargo").is_dir())
+/// ```
+/// ```rust
+/// # use std::env::current_dir;
+/// # use std::path::PathBuf;
+/// # use framework::space::SpaceRootFindPattern;
+/// # use framework::space::find_space_root_with;
/// // Find the `Cargo.toml` file
/// let path = find_space_root_with(
/// current_dir().unwrap(),
@@ -391,8 +406,13 @@ pub fn find_space_root_with(
// Get the pattern used for matching
let match_pattern: Box<dyn Fn(&Path) -> bool> = match pattern {
SpaceRootFindPattern::IncludeDotDir(dot_dir_name) => Box::new(move |path| {
- path.join(format!(".{}", dot_dir_name.to_string_lossy()))
- .is_dir()
+ let dir_name = dot_dir_name.to_string_lossy();
+ let dir_name = if dir_name.starts_with('.') {
+ dir_name.to_string()
+ } else {
+ format!(".{}", dir_name)
+ };
+ path.join(dir_name).is_dir()
}),
SpaceRootFindPattern::IncludeFile(file_name) => {
Box::new(move |path| path.join(&file_name).is_file())