dsh-sweeper 1.5.14 → 1.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/fs-tools.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -278,7 +278,7 @@ node test/browser/check.mjs # 需要本机有 Chrome/Edge,或 CHROME=<p
|
|
|
278
278
|
## 边界与自保
|
|
279
279
|
|
|
280
280
|
- **工具的遍历上限会说出来**:模型自己找文件时走到 400 个条目上限会收到一句「只看了前 400 个」,不会把「没扫完」当成「没有」。
|
|
281
|
-
- **不敢跟的链接、读不到的条目会被数出来**:`list_dir` / `find_files` 遇到符号链接(可能指向工作目录之外)和权限不足的条目时不再静默跳过,而是写「N 个链接未跟随」「N
|
|
281
|
+
- **不敢跟的链接、读不到的条目会被数出来**:`list_dir` / `find_files` 遇到符号链接(可能指向工作目录之外)和权限不足的条目时不再静默跳过,而是写「N 个链接未跟随」「N 个条目读不出来」;整目录读不进去时单独写「N 个目录读不出来」,不会把目录说成文件。
|
|
282
282
|
- **有日志读不出来,就不给「无脑删」**:一份会话日志打不开时,它可能用过任何文件;这一轮所有原本能一键清理的条目都会降到「需要你判断」,并在理由里写明原因。
|
|
283
283
|
- **看不到的路径会被点名**:权限不足或文件被占用的路径不能判断,会写成「另有 N 个路径读不到」,不会悄悄少列。
|
|
284
284
|
- **没列出来的对话会说明**:每轮最多分析 24 段,超出的段数会写成「另有 N 段没有列出」,而不是装作全都看过。
|
package/lib/fs-tools.js
CHANGED
|
@@ -40,6 +40,7 @@ export function makeFsTools(opts) {
|
|
|
40
40
|
// Tests inject a stat that fails, so the "could not read this entry" path is
|
|
41
41
|
// exercised on a machine where every file happens to be readable.
|
|
42
42
|
const lstatOf = typeof opts.lstat === 'function' ? opts.lstat : fs.lstatSync
|
|
43
|
+
const readdirOf = typeof opts.readdir === 'function' ? opts.readdir : fs.readdirSync
|
|
43
44
|
|
|
44
45
|
/** Resolve and authorise one path, or explain why not. */
|
|
45
46
|
function allow(raw) {
|
|
@@ -82,7 +83,7 @@ export function makeFsTools(opts) {
|
|
|
82
83
|
const rows = []
|
|
83
84
|
let links = 0
|
|
84
85
|
let unreadable = 0
|
|
85
|
-
for (const name of
|
|
86
|
+
for (const name of readdirOf(ok.real)) {
|
|
86
87
|
let item
|
|
87
88
|
try { item = lstatOf(path.join(ok.real, name)) } catch { unreadable += 1; continue }
|
|
88
89
|
if (item.isSymbolicLink()) { links += 1; continue }
|
|
@@ -157,11 +158,12 @@ export function makeFsTools(opts) {
|
|
|
157
158
|
let capped = false
|
|
158
159
|
let links = 0
|
|
159
160
|
let unreadable = 0
|
|
161
|
+
let unreadableDirs = 0
|
|
160
162
|
const walk = (dir, level) => {
|
|
161
163
|
if (level > depth) return
|
|
162
164
|
if (walked > MAX_WALK) { capped = true; return }
|
|
163
165
|
let names
|
|
164
|
-
try { names =
|
|
166
|
+
try { names = readdirOf(dir) } catch { unreadableDirs += 1; return }
|
|
165
167
|
for (const name of names) {
|
|
166
168
|
walked += 1
|
|
167
169
|
if (walked > MAX_WALK) { capped = true; return }
|
|
@@ -190,6 +192,7 @@ export function makeFsTools(opts) {
|
|
|
190
192
|
: ''
|
|
191
193
|
const skippedNote = [
|
|
192
194
|
links ? '… ' + links + ' symbolic link' + (links === 1 ? '' : 's') + ' not followed' : '',
|
|
195
|
+
unreadableDirs ? '… ' + unreadableDirs + ' director' + (unreadableDirs === 1 ? 'y' : 'ies') + ' could not be read' : '',
|
|
193
196
|
unreadable ? '… ' + unreadable + ' entr' + (unreadable === 1 ? 'y' : 'ies') + ' could not be read' : '',
|
|
194
197
|
].filter(Boolean).join('\n')
|
|
195
198
|
const extra = cappedNote + (skippedNote ? '\n' + skippedNote : '')
|