skip hidden files on windows

Massimo Melina committed Apr 13, 2022 at 23:09 UTC 4cb615bfc69854466218efca8f0e014b3c7e4018
1 file changed +19 -5
server/src/vfs.ts
+19 -5
@@ -12,6 +12,7 @@ import { FORBIDDEN, IS_WINDOWS } from './const'
12 import events from './events'
13 import { getCurrentUsernameExpanded } from './perm'
14 import { with_ } from './misc'
15 +import { execFile } from 'child_process'
16
17 const WHO_ANYONE = true
18 const WHO_NO_ONE = false
@@ -161,12 +162,13 @@ export async function* walkNode(parent:VfsNode, ctx: Koa.Context, depth:number=0
162 cwd: base,
163 suppressErrors: true,
164 })
165 + const skip = await getItemsToSkip(base)
166 for await (let path of dirStream) {
167 if (ctx.req.aborted)
168 return
169 if (path instanceof Buffer)
170 path = path.toString('utf8')
169 - if (shouldSkipFile(path))
171 + if (skip?.includes(path))
172 continue
173 let { rename } = parent
174 const renamed = rename?.[path]
@@ -204,6 +206,22 @@ export async function* walkNode(parent:VfsNode, ctx: Koa.Context, depth:number=0
206 }
207 }
208
209 +async function getItemsToSkip(path: string) {
210 + if (!IS_WINDOWS) return
211 + const out = await run('dir', ['/ah', '/b', path.replace(/\//g, '\\')])
212 + return out.split('\r\n').slice(0,-1)
213 +}
214 +
215 +function run(cmd: string, args: string[] = []): Promise<string> {
216 + return new Promise((resolve, reject) =>
217 + execFile('cmd', ['/c', cmd, ...args], (err, stdout) => {
218 + if (err)
219 + reject(err)
220 + else
221 + resolve(stdout)
222 + }))
223 +}
224 +
225 function applyMasks(item: VfsNode, parent: VfsNode, name: string) {
226 const { masks } = parent
227 if (!masks) return
@@ -268,7 +286,3 @@ events.on('accountRenamed', (from, to) => {
286 }
287
288 })
271 -
272 -function shouldSkipFile(name: string) {
273 - return IS_WINDOWS && (name === '$RECYCLE.BIN' || name === 'System Volume Information')
274 -}