fix: admin/fs: "add" browsing stops working with of system files
Massimo Melina committed
Feb 10, 2022 at 18:45 UTC
82a03390282e8a594519a63463e946db57055361
1 file changed
+18
-13
src/api.vfs.ts
+18
-13
@@ -2,8 +2,8 @@ import { getNodeName, nodeIsDirectory, saveVfs, vfs, VfsNode } from './vfs'
2
import _ from 'lodash'
3
import { stat } from 'fs/promises'
4
import { ApiError, ApiHandlers } from './apis'
5
-import { dirname } from 'path'
6
-import glob, { Entry } from 'fast-glob'
5
+import { dirname, join } from 'path'
6
+import glob from 'fast-glob'
7
import { enforceFinal, isWindows, isWindowsDrive } from './misc'
8
import { exec } from 'child_process'
9
import { promisify } from 'util'
@@ -113,22 +113,27 @@ const apis: ApiHandlers = {
113
cwd: path,
114
dot: true,
115
onlyFiles: false,
116
- stats: true,
116
+ suppressErrors: true,
117
})
118
- for await (const entry of dirStream) {
118
+ for await (let name of dirStream) {
119
if (ctx.req.aborted)
120
return
121
- let { name, stats } = entry as any as Entry
122
- if (!stats) continue
123
- yield {
124
- add: {
125
- n: name,
126
- s: stats.size,
127
- c: stats.ctime,
128
- m: stats.mtime,
129
- k: stats.isDirectory() ? 'd' : undefined,
121
+ if (name instanceof Buffer)
122
+ name = name.toString('utf8')
123
+ try {
124
+ const full = join(path, name)
125
+ const stats = await stat(full)
126
+ yield {
127
+ add: {
128
+ n: name,
129
+ s: stats.size,
130
+ c: stats.ctime,
131
+ m: stats.mtime,
132
+ k: stats.isDirectory() ? 'd' : undefined,
133
+ }
134
}
135
}
136
+ catch {} // just ignore entries we can't stat
137
}
138
} catch (e) {
139
if ((e as any).code !== 'ENOTDIR')