File tree 1 file changed +7
-1
lines changed 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -142,14 +142,19 @@ function try_read_file_sync(file_name) {
142
142
try {
143
143
return fs . readFileSync ( file_name , 'utf8' ) ;
144
144
} catch ( err ) {
145
- if ( err . code === 'ENOENT' ) {
145
+ if ( is_not_exist_err_code ( err ) ) {
146
146
// file does not exist
147
147
return ;
148
148
}
149
149
throw err ;
150
150
}
151
151
}
152
152
153
+ // returns true if the error is ENOENT or ENOTDIR
154
+ // ENOTDIR is relevant for cases where a directory in the middle of the path is a file and not a directory
155
+ function is_not_exist_err_code ( err ) {
156
+ return err && ( err . code === 'ENOENT' || err . code === 'ENOTDIR' ) ;
157
+ }
153
158
154
159
// returns the first line in the file that contains the substring
155
160
async function find_line_in_file ( file_name , line_sub_string ) {
@@ -373,3 +378,4 @@ exports.PRIVATE_DIR_PERMISSIONS = PRIVATE_DIR_PERMISSIONS;
373
378
exports . file_exists = file_exists ;
374
379
exports . file_not_exists = file_not_exists ;
375
380
exports . try_read_file_sync = try_read_file_sync ;
381
+ exports . is_not_exist_err_code = is_not_exist_err_code ;
You can’t perform that action at this time.
0 commit comments