use std::path::Path; pub fn is_on_system_drive(path: &Path) -> bool { let Some(system_drive) = std::env::var_os("SystemDrive") else { return false; }; let system_drive = system_drive.to_string_lossy().to_ascii_lowercase(); let path_text = path.as_os_str().to_string_lossy().to_ascii_lowercase(); path_text.starts_with(&system_drive) } pub fn system_drive_warning(path: &Path) -> Option<&'static str> { if is_on_system_drive(path) { Some( "当前数据位置位于Windows系统盘。帖子数据库、图片和视频可能持续增长,建议使用空间较充足的非系统盘。", ) } else { None } } #[cfg(test)] mod tests { use std::path::Path; use super::is_on_system_drive; #[test] fn detects_system_drive_prefix_without_panicking() { let _ = is_on_system_drive(Path::new("C:\\example")); } }