Skip to content

Commit

Permalink
make directory ignored attribute look more like file ignored attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwblair committed Oct 8, 2024
1 parent e16e85b commit 3ef60b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 5 additions & 5 deletions bids-validator/src/files/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Deno specific implementation for reading files
*/
import { basename, join } from '@std/path'
import { existsSync } from '@std/fs'
import * as posix from '@std/path/posix'
import { type BIDSFile, FileTree } from '../types/filetree.ts'
import { requestReadPermission } from '../setup/requestPermissions.ts'
Expand Down Expand Up @@ -119,7 +120,7 @@ async function _readFileTree(
): Promise<FileTree> {
await requestReadPermission()
const name = basename(relativePath)
const tree = new FileTree(relativePath, name, parent, ignore.test(join(rootPath, relativePath)))
const tree = new FileTree(relativePath, name, parent, ignore)

for await (const dirEntry of Deno.readDir(join(rootPath, relativePath))) {
if (dirEntry.isFile || dirEntry.isSymlink) {
Expand All @@ -129,10 +130,6 @@ async function _readFileTree(
ignore,
)
file.parent = tree
// For .bidsignore, read in immediately and add the rules
if (dirEntry.name === '.bidsignore') {
ignore.add(await readBidsIgnore(file))
}
tree.files.push(file)
}
if (dirEntry.isDirectory) {
Expand All @@ -153,5 +150,8 @@ async function _readFileTree(
*/
export function readFileTree(rootPath: string): Promise<FileTree> {
const ignore = new FileIgnoreRules([])
if (existsSync(join(rootPath, '.bidsignore'))) {
ignore.add(readBidsIgnore(join(rootPath, '.bidsignore')))
}
return _readFileTree(rootPath, '/', ignore)
}
4 changes: 2 additions & 2 deletions bids-validator/src/files/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { BIDSFile } from '../types/filetree.ts'
import { default as ignore } from '@ignore'
import type { Ignore } from '@ignore'

export async function readBidsIgnore(file: BIDSFile) {
const value = await file.text()
export function readBidsIgnore(file: string) {
const value = Deno.readTextFileSync(file)
if (value) {
const lines = value.split('\n')
return lines
Expand Down
12 changes: 9 additions & 3 deletions bids-validator/src/types/filetree.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FileIgnoreRules } from '../files/ignore.ts'

export interface BIDSFile {
// Filename
name: string
Expand Down Expand Up @@ -29,18 +31,22 @@ export class FileTree {
name: string
files: BIDSFile[]
directories: FileTree[]
ignored: boolean
viewed: boolean
parent?: FileTree
#ignore: FileIgnoreRules

constructor(path: string, name: string, parent?: FileTree, ignored?: boolean) {
constructor(path: string, name: string, parent?: FileTree, ignore?: FileIgnoreRules) {
this.path = path
this.files = []
this.directories = []
this.name = name
this.parent = parent
this.viewed = false
this.ignored = ignored || false
this.#ignore = ignore ?? new FileIgnoreRules([])
}

get ignored(): boolean {
return this.#ignore.test(this.path)
}

_get(parts: string[]): BIDSFile | FileTree | undefined {
Expand Down

0 comments on commit 3ef60b7

Please sign in to comment.