@@ -6,6 +6,7 @@ import * as posix from '@std/path/posix'
6
6
import { type BIDSFile , FileTree } from '../types/filetree.ts'
7
7
import { requestReadPermission } from '../setup/requestPermissions.ts'
8
8
import { FileIgnoreRules , readBidsIgnore } from './ignore.ts'
9
+ import { logger } from '../utils/logger.ts'
9
10
10
11
/**
11
12
* Thrown when a text file is decoded as UTF-8 but contains UTF-16 characters
@@ -119,7 +120,7 @@ async function _readFileTree(
119
120
) : Promise < FileTree > {
120
121
await requestReadPermission ( )
121
122
const name = basename ( relativePath )
122
- const tree = new FileTree ( relativePath , name , parent )
123
+ const tree = new FileTree ( relativePath , name , parent , ignore )
123
124
124
125
for await ( const dirEntry of Deno . readDir ( join ( rootPath , relativePath ) ) ) {
125
126
if ( dirEntry . isFile || dirEntry . isSymlink ) {
@@ -129,10 +130,6 @@ async function _readFileTree(
129
130
ignore ,
130
131
)
131
132
file . parent = tree
132
- // For .bidsignore, read in immediately and add the rules
133
- if ( dirEntry . name === '.bidsignore' ) {
134
- ignore . add ( await readBidsIgnore ( file ) )
135
- }
136
133
tree . files . push ( file )
137
134
}
138
135
if ( dirEntry . isDirectory ) {
@@ -151,7 +148,19 @@ async function _readFileTree(
151
148
/**
152
149
* Read in the target directory structure and return a FileTree
153
150
*/
154
- export function readFileTree ( rootPath : string ) : Promise < FileTree > {
151
+ export async function readFileTree ( rootPath : string ) : Promise < FileTree > {
155
152
const ignore = new FileIgnoreRules ( [ ] )
153
+ try {
154
+ const ignoreFile = new BIDSFileDeno (
155
+ rootPath ,
156
+ '.bidsignore' ,
157
+ ignore ,
158
+ )
159
+ ignore . add ( await readBidsIgnore ( ignoreFile ) )
160
+ } catch ( err ) {
161
+ if ( ! Object . hasOwn ( err , 'code' ) || err . code !== 'ENOENT' ) {
162
+ logger . error ( `Failed to read '.bidsignore' file with the following error:\n${ err } ` )
163
+ }
164
+ }
156
165
return _readFileTree ( rootPath , '/' , ignore )
157
166
}
0 commit comments