File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ impl Compiler {
7979 . join ( Self :: expand_tilde ( & relative. cooked ) ?)
8080 . lexiclean ( ) ;
8181
82- if import . is_file ( ) {
82+ if filesystem :: is_file ( & import ) ? {
8383 if current. file_path . contains ( & import) {
8484 return Err ( Error :: CircularImport {
8585 current : current. path ,
@@ -121,7 +121,7 @@ impl Compiler {
121121 if let Some ( path) = path {
122122 let full = parent. join ( path) ;
123123
124- if full . is_file ( ) {
124+ if filesystem :: is_file ( & full ) ? {
125125 return Ok ( Some ( full) ) ;
126126 }
127127
Original file line number Diff line number Diff line change @@ -104,6 +104,10 @@ pub(crate) enum Error<'src> {
104104 ExpectedSubmoduleButFoundRecipe {
105105 path : String ,
106106 } ,
107+ FilesystemIo {
108+ io_error : io:: Error ,
109+ path : PathBuf ,
110+ } ,
107111 FlagWithValue {
108112 recipe : & ' src str ,
109113 option : Switch ,
@@ -551,6 +555,9 @@ impl ColorDisplay for Error<'_> {
551555 ExpectedSubmoduleButFoundRecipe { path } => {
552556 write ! ( f, "Expected submodule at `{path}` but found recipe." ) ?;
553557 }
558+ FilesystemIo { io_error, path } => {
559+ write ! ( f, "I/O error at `{}`: {io_error}" , path. display( ) ) ?;
560+ }
554561 FlagWithValue { recipe, option } => {
555562 write ! ( f, "Recipe `{recipe}` flag `{option}` does not take value" , ) ?;
556563 }
Original file line number Diff line number Diff line change 1+ use super :: * ;
2+
3+ pub ( crate ) fn is_file ( path : & Path ) -> RunResult < ' static , bool > {
4+ match path. metadata ( ) {
5+ Ok ( metadata) => Ok ( metadata. is_file ( ) ) ,
6+ Err ( io_error) => {
7+ if io_error. kind ( ) == io:: ErrorKind :: NotFound {
8+ Ok ( false )
9+ } else {
10+ Err ( Error :: FilesystemIo {
11+ path : path. into ( ) ,
12+ io_error,
13+ } )
14+ }
15+ }
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -224,6 +224,7 @@ mod evaluator;
224224mod execution_context;
225225mod executor;
226226mod expression;
227+ mod filesystem;
227228mod format_string_part;
228229mod fragment;
229230mod function;
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ pub(crate) fn load_dotenv(
2626
2727 if let Some ( path) = dotenv_path {
2828 let path = working_directory. join ( path) ;
29- if path . is_file ( ) {
29+ if filesystem :: is_file ( & path ) ? {
3030 return load_from_file ( & path, settings) ;
3131 }
3232 }
@@ -35,7 +35,7 @@ pub(crate) fn load_dotenv(
3535
3636 for directory in working_directory. ancestors ( ) {
3737 let path = directory. join ( filename) ;
38- if path . is_file ( ) {
38+ if filesystem :: is_file ( & path ) ? {
3939 return load_from_file ( & path, settings) ;
4040 }
4141 }
Original file line number Diff line number Diff line change @@ -380,7 +380,7 @@ impl Subcommand {
380380 config. ceiling . as_deref ( ) ,
381381 ) ?;
382382
383- if search. justfile . is_file ( ) {
383+ if filesystem :: is_file ( & search. justfile ) ? {
384384 return Err ( Error :: InitExists {
385385 justfile : search. justfile ,
386386 } ) ;
You can’t perform that action at this time.
0 commit comments