warn admins about hidden-files slowdown
Massimo Melina committed
Sep 12, 2024 at 23:59 UTC
e6b9a19fc4668513e0f7db703b51cfe4a5de1e49
1 file changed
+8
-1
src/dirStream.ts
+8
-1
@@ -4,7 +4,7 @@ import { runCmd } from './util-os'
4
import { IS_WINDOWS } from './const'
5
import { join } from 'path'
6
import { Readable } from 'stream'
7
-import { pendingPromise } from './cross'
7
+import { DAY, pendingPromise } from './cross'
8
import { Stats, Dirent } from 'node:fs'
9
10
export interface DirStreamEntry extends Dirent {
@@ -95,9 +95,16 @@ export function createDirStream(startPath: string, { depth=0, hidden=true }) {
95
}
96
}
97
98
+let lastNotice = 0
99
async function getWindowsHiddenFiles(path: string, depth=false) {
100
+ const t = Date.now()
101
const out = await runCmd('dir', ['/ah', '/b', depth ? '/s' : '/c', path.replaceAll('/', '\\')]) // cannot pass '', so we pass /c as a noop parameter
102
.catch(()=>'') // error in case of no matching file
103
+ const now = Date.now()
104
+ if ((now - t) > 10_000 && (now - lastNotice) > DAY) {
105
+ lastNotice = now
106
+ console.log("A file list was heavily delayed. You can avoid this by enabling the option to show hidden files.")
107
+ }
108
const slice = !depth ? 0 : path.length + (path.at(-1) === '\\' ? 0 : 1)
109
return out.trimEnd().split('\n').map(x => x.slice(slice).replaceAll('\\', '/'))
110
}