@@ -42,7 +42,6 @@ pub enum WorkerResult {
4242 // to box the Entry variant
4343 Entry ( DirEntry ) ,
4444 Error ( ignore:: Error ) ,
45- FatalError ( ignore:: Error ) ,
4645}
4746
4847/// A batch of WorkerResults to send over a channel.
@@ -230,12 +229,6 @@ impl<'a, W: Write> ReceiverBuffer<'a, W> {
230229 print_error ( err. to_string ( ) ) ;
231230 }
232231 }
233- WorkerResult :: FatalError ( err) => {
234- if self . config . show_filesystem_errors {
235- print_error ( err. to_string ( ) ) ;
236- }
237- return Err ( ExitCode :: GeneralError ) ;
238- }
239232 }
240233 }
241234
@@ -531,20 +524,7 @@ impl WorkerState {
531524 // Check the name first, since it doesn't require metadata
532525 let entry_path = entry. path ( ) ;
533526
534- let search_str = match search_str_for_entry ( entry_path, config. search_full_path ) {
535- Ok ( search_str) => search_str,
536- Err ( err) => {
537- let error = ignore:: Error :: WithPath {
538- path : entry_path. to_path_buf ( ) ,
539- err : Box :: new ( ignore:: Error :: Io ( err) ) ,
540- } ;
541-
542- return match tx. send ( WorkerResult :: FatalError ( error) ) {
543- Ok ( _) => WalkState :: Quit ,
544- Err ( _) => WalkState :: Quit ,
545- } ;
546- }
547- } ;
527+ let search_str = search_str_for_entry ( entry_path, config. cwd . as_deref ( ) ) ;
548528
549529 if !patterns
550530 . iter ( )
@@ -685,14 +665,14 @@ impl WorkerState {
685665
686666fn search_str_for_entry < ' a > (
687667 entry_path : & ' a std:: path:: Path ,
688- search_full_path : bool ,
689- ) -> io :: Result < Cow < ' a , OsStr > > {
690- if search_full_path {
691- let path_abs_buf = filesystem:: path_absolute_form ( entry_path) ? ;
692- Ok ( Cow :: Owned ( path_abs_buf . as_os_str ( ) . to_os_string ( ) ) )
668+ cwd : Option < & std :: path :: Path > ,
669+ ) -> Cow < ' a , OsStr > {
670+ if let Some ( cwd ) = cwd {
671+ let abs_path = filesystem:: make_absolute ( entry_path, cwd ) ;
672+ Cow :: Owned ( abs_path . as_os_str ( ) . to_os_string ( ) )
693673 } else {
694674 match entry_path. file_name ( ) {
695- Some ( filename) => Ok ( Cow :: Borrowed ( filename) ) ,
675+ Some ( filename) => Cow :: Borrowed ( filename) ,
696676 None => unreachable ! (
697677 "Encountered file system entry without a file name. This should only \
698678 happen for paths like 'foo/bar/..' or '/' which are not supposed to \
@@ -710,29 +690,3 @@ fn search_str_for_entry<'a>(
710690pub fn scan ( paths : & [ PathBuf ] , patterns : Vec < Regex > , config : Config ) -> Result < ExitCode > {
711691 WorkerState :: new ( patterns, config) . scan ( paths)
712692}
713-
714- #[ cfg( test) ]
715- mod tests {
716- use super :: search_str_for_entry;
717- use std:: env;
718- use std:: fs;
719- use std:: path:: Path ;
720-
721- #[ test]
722- #[ cfg( all( not( windows) , not( target_os = "illumos" ) ) ) ]
723- fn full_path_search_returns_error_for_invalid_cwd ( ) {
724- let original_dir = env:: current_dir ( ) . unwrap ( ) ;
725- let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
726- let cwd = temp_dir. path ( ) . join ( "cwd" ) ;
727-
728- fs:: create_dir ( & cwd) . unwrap ( ) ;
729- env:: set_current_dir ( & cwd) . unwrap ( ) ;
730- fs:: remove_dir ( & cwd) . unwrap ( ) ;
731-
732- let result = search_str_for_entry ( Path :: new ( "relative/path" ) , true ) ;
733-
734- env:: set_current_dir ( original_dir) . unwrap ( ) ;
735-
736- assert ! ( result. is_err( ) ) ;
737- }
738- }
0 commit comments