@@ -184,35 +184,32 @@ pub fn group_without_target(group: &str) -> &str {
184184}
185185
186186fn platform_is_under_wsl ( ) -> bool {
187- if ! cfg ! ( target_os = "linux" ) {
187+ if cfg ! ( not ( target_os = "linux" ) ) {
188188 return false ;
189189 }
190190
191191 for file in & [ "/proc/sys/kernel/osrelease" , "/proc/version" ] {
192- if let Ok ( content) = std:: fs:: read ( file) {
193- let Ok ( content) = std:: str:: from_utf8 ( & content) else {
194- return false ;
195- } ;
192+ let Ok ( content) = std:: fs:: read ( file) else {
193+ continue ;
194+ } ;
196195
197- if content. contains ( "microsoft" ) || content. contains ( "WSL" ) {
198- return true ;
199- }
196+ let Ok ( content) = std:: str:: from_utf8 ( & content) else {
197+ continue ;
198+ } ;
199+
200+ if content. contains ( "microsoft" ) || content. contains ( "WSL" ) {
201+ return true ;
200202 }
201203 }
202204
203- let Ok ( wsl_interop_exists) = std:: fs:: exists ( "/proc/sys/fs/binfmt_misc/WSLInterop" ) else {
204- return false ;
205- } ;
206-
207- wsl_interop_exists
205+ std:: fs:: exists ( "/proc/sys/fs/binfmt_misc/WSLInterop" ) . is_ok ( )
208206}
209207
210208/// Returns true if a group with specified name can be used by current platform.
211209/// Checks if a group should be linked on current platform. For unconditional
212210/// groups, this function returns true; for conditional groups, this function
213211/// returns true when group suffix matches current target_os or target_family.
214212pub fn group_is_valid_target ( group : & str , custom_targets : & [ impl AsRef < str > ] ) -> bool {
215- // Gets the current OS and OS family
216213 let current_target_os = format ! ( "_{}" , env:: consts:: OS ) ;
217214 let current_target_family = format ! ( "_{}" , env:: consts:: FAMILY ) ;
218215
@@ -247,7 +244,7 @@ impl Dotfile {
247244 return false ;
248245 } ;
249246
250- let home_dir = dirs :: home_dir ( ) . unwrap ( ) ;
247+ let home_dir = get_dotfiles_target_dir_path ( ) . unwrap ( ) ;
251248 !target. starts_with ( home_dir)
252249 }
253250
@@ -409,9 +406,13 @@ pub fn get_target_basepath(target: &path::Path) -> Option<PathBuf> {
409406}
410407
411408pub fn get_dotfiles_target_dir_path ( ) -> Result < PathBuf , String > {
412- #[ cfg( test) ]
413- {
414- unsafe { std:: env:: remove_var ( "TUCKR_TARGET" ) } ;
409+ if cfg ! ( test) {
410+ return Ok ( std:: env:: temp_dir ( ) . join ( format ! (
411+ "tuckr-target-{}" ,
412+ // this will return a namespace but `::` is invalid on paths in windows
413+ // so we need to change it to prevent panics when interacting with the file system there
414+ std:: thread:: current( ) . name( ) . unwrap( ) . replace( "::" , "_" )
415+ ) ) ) ;
415416 }
416417
417418 if let Ok ( dir) = std:: env:: var ( "TUCKR_TARGET" )
@@ -554,7 +555,7 @@ mod tests {
554555
555556 assert_eq ! (
556557 Dotfile :: try_from( group) . unwrap( ) . to_target_path( ) . unwrap( ) ,
557- dirs :: home_dir ( ) . unwrap( ) . join( ".zshrc" )
558+ super :: get_dotfiles_target_dir_path ( ) . unwrap( ) . join( ".zshrc" )
558559 ) ;
559560 }
560561
0 commit comments