dsh-vigil 0.0.1
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/LICENSE +201 -0
- package/README.md +188 -0
- package/client.js +4652 -0
- package/cordis.patch.yml +7 -0
- package/docs/DETAIL.md +66 -0
- package/icon.png +0 -0
- package/illustrations/notice.png +0 -0
- package/illustrations/warning.png +0 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +75 -0
- package/rules/audit.yaml +130 -0
- package/rules/manifest.json +7 -0
- package/rules/sentinel.yaml +289 -0
- package/src/alert-route.js +194 -0
- package/src/approval.js +398 -0
- package/src/artwork-route.js +87 -0
- package/src/audit/ast.js +213 -0
- package/src/audit/install-scan.js +127 -0
- package/src/audit/lexer.js +307 -0
- package/src/audit/narrative.js +320 -0
- package/src/audit/rules.js +1440 -0
- package/src/audit/scan.js +880 -0
- package/src/audit-clear-route.js +89 -0
- package/src/audit-feed.js +265 -0
- package/src/audit-log.js +887 -0
- package/src/config-schema.js +194 -0
- package/src/config.js +580 -0
- package/src/delete/command-kinds.js +46 -0
- package/src/delete/lex.js +46 -0
- package/src/delete/parser-posix.js +1427 -0
- package/src/delete/parser-pwsh.js +1729 -0
- package/src/delete/parser.js +2082 -0
- package/src/delete/policy.js +680 -0
- package/src/delete/quarantine.js +417 -0
- package/src/index.js +1134 -0
- package/src/install-scan-route.js +58 -0
- package/src/install-watch.js +389 -0
- package/src/integrity.js +509 -0
- package/src/live-config.js +88 -0
- package/src/quarantine-route.js +74 -0
- package/src/quarantine-view.js +44 -0
- package/src/rules/pack.js +423 -0
- package/src/rules/update.js +341 -0
- package/src/rules/yaml.js +186 -0
- package/src/sage-action-route.js +63 -0
- package/src/sage-provision.js +716 -0
- package/src/sentinel/guard.js +392 -0
- package/src/sentinel/hook.js +546 -0
- package/src/sentinel/rules.js +488 -0
- package/src/sentinel/sage-load.js +79 -0
- package/src/sentinel/sage.js +550 -0
- package/src/tools.js +727 -0
- package/src/update-check.js +339 -0
- package/src/util.js +400 -0
- package/threats/README.md +25 -0
|
@@ -0,0 +1,1427 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POSIX shell (sh / bash / zsh / dash) deletion-intent parser.
|
|
3
|
+
*
|
|
4
|
+
* Internal module used by `parser.js`. It is a pure function library: no
|
|
5
|
+
* filesystem access, no process spawning, no network and no dependencies.
|
|
6
|
+
* It never throws; on internal failure it degrades to an `unparsed` statement.
|
|
7
|
+
*
|
|
8
|
+
* The parser returns *partial statements*. Their `rawTargets` still carry the
|
|
9
|
+
* masked text needed for variable expansion / path resolution, which is done by
|
|
10
|
+
* parser.js (that way the OS-specific path logic lives in exactly one place).
|
|
11
|
+
*
|
|
12
|
+
* Masking convention: every character that must never be treated as a variable
|
|
13
|
+
* or glob is prefixed with the ESC sentinel (`\u0001`). parser.js strips the
|
|
14
|
+
* sentinel while expanding and restores the literal character.
|
|
15
|
+
*
|
|
16
|
+
* @module delete/parser-posix
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { ESC, MAX_TOKENS, unmask, baseName } from './lex.js'
|
|
20
|
+
import { POSIX_DELETE_COMMANDS as DELETE_COMMANDS } from './command-kinds.js'
|
|
21
|
+
|
|
22
|
+
/** Shell keywords that may prefix a simple command inside a compound command. */
|
|
23
|
+
const SKIP_WORDS = new Set(['do', 'then', 'else', 'elif', 'fi', 'done', 'esac', '!']);
|
|
24
|
+
|
|
25
|
+
/** Compound-statement keywords: such a chunk has no standalone delete command. */
|
|
26
|
+
const COMPOUND_WORDS = new Set(['for', 'while', 'until', 'if', 'case', 'select', 'function']);
|
|
27
|
+
|
|
28
|
+
/** Commands understood by the pipeline backtracking heuristic. */
|
|
29
|
+
const PRODUCER_COMMANDS = new Set(['find', 'ls', 'echo', 'printf']);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Merge glob kinds into a single `globKind` value.
|
|
33
|
+
* @param {Set<string>} kinds
|
|
34
|
+
* @returns {'none'|'asterisk'|'question'|'bracket'|'brace'|'mixed'}
|
|
35
|
+
*/
|
|
36
|
+
function combineGlobKinds(kinds) {
|
|
37
|
+
if (!kinds || kinds.size === 0) return 'none';
|
|
38
|
+
if (kinds.size > 1) return 'mixed';
|
|
39
|
+
return kinds.values().next().value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Normalise a partial statement object (defaults for every field).
|
|
44
|
+
* @param {object} fields
|
|
45
|
+
* @returns {object}
|
|
46
|
+
*/
|
|
47
|
+
function makePartial(fields) {
|
|
48
|
+
return Object.assign(
|
|
49
|
+
{
|
|
50
|
+
shell: 'posix',
|
|
51
|
+
text: '',
|
|
52
|
+
command: '',
|
|
53
|
+
isDelete: false,
|
|
54
|
+
dryRun: false,
|
|
55
|
+
recursive: false,
|
|
56
|
+
force: false,
|
|
57
|
+
wildcard: false,
|
|
58
|
+
deleteKind: 'none',
|
|
59
|
+
unparsed: false,
|
|
60
|
+
notes: [],
|
|
61
|
+
risks: [],
|
|
62
|
+
rawTargets: [],
|
|
63
|
+
},
|
|
64
|
+
fields,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Build a raw target from a token.
|
|
70
|
+
* @param {{value:string, hasGlob?:boolean, globKind?:string}} token
|
|
71
|
+
* @param {object} [extra]
|
|
72
|
+
* @returns {object}
|
|
73
|
+
*/
|
|
74
|
+
function targetFromToken(token, extra) {
|
|
75
|
+
return Object.assign(
|
|
76
|
+
{
|
|
77
|
+
raw: unmask(token.value),
|
|
78
|
+
text: token.value,
|
|
79
|
+
hasGlob: Boolean(token.hasGlob),
|
|
80
|
+
globKind: token.globKind || 'none',
|
|
81
|
+
},
|
|
82
|
+
extra || {},
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A synthetic `./` root token used when a command has no explicit path. */
|
|
87
|
+
function dotToken() {
|
|
88
|
+
return { value: '.', raw: '.', hasGlob: false, globKind: 'none' };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Find the closing `)` matching the `(` at `open`.
|
|
93
|
+
* Quotes are respected; returns `src.length` when unbalanced.
|
|
94
|
+
* @param {string} src
|
|
95
|
+
* @param {number} open index of `(`
|
|
96
|
+
* @returns {number}
|
|
97
|
+
*/
|
|
98
|
+
function findParenClose(src, open) {
|
|
99
|
+
let depth = 0;
|
|
100
|
+
let quote = null;
|
|
101
|
+
for (let i = open; i < src.length; i += 1) {
|
|
102
|
+
const c = src[i];
|
|
103
|
+
if (quote === "'") {
|
|
104
|
+
if (c === "'") quote = null;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (quote === '"') {
|
|
108
|
+
if (c === '\\') {
|
|
109
|
+
i += 1;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (c === '"') quote = null;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (c === "'" || c === '"') {
|
|
116
|
+
quote = c;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (c === '\\') {
|
|
120
|
+
i += 1;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (c === '(') depth += 1;
|
|
124
|
+
else if (c === ')') {
|
|
125
|
+
depth -= 1;
|
|
126
|
+
if (depth === 0) return i;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return src.length;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Find the closing backtick for the substitution starting at `start`.
|
|
134
|
+
* @param {string} src
|
|
135
|
+
* @param {number} start
|
|
136
|
+
* @returns {number} index of closing backtick, or `src.length`
|
|
137
|
+
*/
|
|
138
|
+
function findBacktickEnd(src, start) {
|
|
139
|
+
for (let i = start + 1; i < src.length; i += 1) {
|
|
140
|
+
if (src[i] === '\\') {
|
|
141
|
+
i += 1;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (src[i] === '`') return i;
|
|
145
|
+
}
|
|
146
|
+
return src.length;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Detect a bash brace expansion such as `{a,b}` or `{1..9}` at `start`.
|
|
151
|
+
* @param {string} src
|
|
152
|
+
* @param {number} start
|
|
153
|
+
* @returns {number} index of the closing `}`, or -1
|
|
154
|
+
*/
|
|
155
|
+
function matchBraceExpansion(src, start) {
|
|
156
|
+
if (src[start] !== '{') return -1;
|
|
157
|
+
let depth = 0;
|
|
158
|
+
for (let i = start; i < src.length; i += 1) {
|
|
159
|
+
const c = src[i];
|
|
160
|
+
if (c === '\\') {
|
|
161
|
+
i += 1;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (c === '{') {
|
|
165
|
+
depth += 1;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (c === '}') {
|
|
169
|
+
depth -= 1;
|
|
170
|
+
if (depth === 0) {
|
|
171
|
+
const inner = src.slice(start + 1, i);
|
|
172
|
+
if (!inner || /[\s;|&<>()]/.test(inner)) return -1;
|
|
173
|
+
return /,|\.\./.test(inner) ? i : -1;
|
|
174
|
+
}
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (/[\s;|&<>()]/.test(c)) return -1;
|
|
178
|
+
}
|
|
179
|
+
return -1;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Whether a `[` at `start` has a matching `]` inside the same word.
|
|
184
|
+
* @param {string} src
|
|
185
|
+
* @param {number} start
|
|
186
|
+
* @returns {boolean}
|
|
187
|
+
*/
|
|
188
|
+
function hasClosingBracket(src, start) {
|
|
189
|
+
for (let i = start + 1; i < src.length; i += 1) {
|
|
190
|
+
const c = src[i];
|
|
191
|
+
if (c === ']') return true;
|
|
192
|
+
if (/[\s;|&<>[\]]/.test(c)) return false;
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Tokenize a POSIX simple command / pipeline stage.
|
|
199
|
+
*
|
|
200
|
+
* Recognised tokens: words (with quote / escape handling), redirection
|
|
201
|
+
* operators and command substitutions (`$(...)`, backticks) which are kept
|
|
202
|
+
* verbatim inside their word. Separators are *not* tokenized here; callers
|
|
203
|
+
* split statements / pipelines first.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} src
|
|
206
|
+
* @returns {Array<object>} tokens
|
|
207
|
+
*/
|
|
208
|
+
function tokenizePosix(src) {
|
|
209
|
+
const tokens = [];
|
|
210
|
+
const n = src.length;
|
|
211
|
+
let i = 0;
|
|
212
|
+
|
|
213
|
+
while (i < n && tokens.length < MAX_TOKENS) {
|
|
214
|
+
const c = src[i];
|
|
215
|
+
if (c === ' ' || c === '\t' || c === '\r' || c === '\n') {
|
|
216
|
+
i += 1;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
// Comment: `#` only starts a comment at a word boundary.
|
|
220
|
+
if (c === '#') break;
|
|
221
|
+
// Control characters / separators that survived the statement splitter.
|
|
222
|
+
if (c === ';' || c === '&' || c === '|' || c === '(' || c === ')' || c === '!' || c === '}') {
|
|
223
|
+
i += 1;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (c === '{' && matchBraceExpansion(src, i) < 0) {
|
|
227
|
+
i += 1;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
// Redirection operator.
|
|
231
|
+
const opMatch = /^(?:[0-9]+)?(?:&>>|&>|>>|>|<<<|<<|<|>&|<&)/.exec(src.slice(i));
|
|
232
|
+
if (opMatch) {
|
|
233
|
+
let op = opMatch[0];
|
|
234
|
+
i += op.length;
|
|
235
|
+
if (/[<>]$/.test(op)) {
|
|
236
|
+
const fd = /^&?\d+/.exec(src.slice(i));
|
|
237
|
+
if (fd) {
|
|
238
|
+
op += fd[0];
|
|
239
|
+
i += fd[0].length;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
tokens.push({ op: true, value: op, raw: op });
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const before = i;
|
|
247
|
+
let value = '';
|
|
248
|
+
let raw = '';
|
|
249
|
+
let quote = null;
|
|
250
|
+
let quotedAny = false;
|
|
251
|
+
let hasSub = false;
|
|
252
|
+
const globKinds = new Set();
|
|
253
|
+
|
|
254
|
+
while (i < n) {
|
|
255
|
+
const ch = src[i];
|
|
256
|
+
if (quote === "'") {
|
|
257
|
+
if (ch === "'") {
|
|
258
|
+
quote = null;
|
|
259
|
+
i += 1;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (ch === '$') value += ESC + '$';
|
|
263
|
+
else if (ch === '~' && value.length === 0) value += ESC + '~';
|
|
264
|
+
else value += ch;
|
|
265
|
+
raw += ch;
|
|
266
|
+
i += 1;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (quote === '"') {
|
|
270
|
+
if (ch === '"') {
|
|
271
|
+
quote = null;
|
|
272
|
+
i += 1;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (ch === '\\') {
|
|
276
|
+
const next = src[i + 1];
|
|
277
|
+
if (next === '$' || next === '`' || next === '"' || next === '\\') {
|
|
278
|
+
value += ESC + next;
|
|
279
|
+
raw += next;
|
|
280
|
+
i += 2;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (next === '\n') {
|
|
284
|
+
i += 2;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
value += ch;
|
|
288
|
+
raw += ch;
|
|
289
|
+
i += 1;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (ch === '`') {
|
|
293
|
+
const end = findBacktickEnd(src, i);
|
|
294
|
+
const segment = src.slice(i, Math.min(end + 1, n));
|
|
295
|
+
value += segment;
|
|
296
|
+
raw += segment;
|
|
297
|
+
hasSub = true;
|
|
298
|
+
i = Math.min(end + 1, n);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (ch === '$' && src[i + 1] === '(') {
|
|
302
|
+
const end = findParenClose(src, i + 1);
|
|
303
|
+
const segment = src.slice(i, Math.min(end + 1, n));
|
|
304
|
+
value += segment;
|
|
305
|
+
raw += segment;
|
|
306
|
+
hasSub = true;
|
|
307
|
+
i = Math.min(end + 1, n);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
value += ch;
|
|
311
|
+
raw += ch;
|
|
312
|
+
i += 1;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Unquoted context.
|
|
317
|
+
if (ch === "'" || ch === '"') {
|
|
318
|
+
quote = ch;
|
|
319
|
+
quotedAny = true;
|
|
320
|
+
i += 1;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (ch === '\\') {
|
|
324
|
+
const next = src[i + 1];
|
|
325
|
+
if (next === undefined) {
|
|
326
|
+
// A trailing backslash is literal in our best-effort model
|
|
327
|
+
// (e.g. the Windows root target `C:\` inside an `rm` command).
|
|
328
|
+
value += '\\';
|
|
329
|
+
raw += '\\';
|
|
330
|
+
i += 1;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (next === '\n') {
|
|
334
|
+
i += 2;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if ('$%~*?[]{}'.includes(next)) value += ESC + next;
|
|
338
|
+
else value += next;
|
|
339
|
+
raw += next;
|
|
340
|
+
i += 2;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (ch === '`') {
|
|
344
|
+
const end = findBacktickEnd(src, i);
|
|
345
|
+
const segment = src.slice(i, Math.min(end + 1, n));
|
|
346
|
+
value += segment;
|
|
347
|
+
raw += segment;
|
|
348
|
+
hasSub = true;
|
|
349
|
+
i = Math.min(end + 1, n);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (ch === '$' && src[i + 1] === '(') {
|
|
353
|
+
const end = findParenClose(src, i + 1);
|
|
354
|
+
const segment = src.slice(i, Math.min(end + 1, n));
|
|
355
|
+
value += segment;
|
|
356
|
+
raw += segment;
|
|
357
|
+
hasSub = true;
|
|
358
|
+
i = Math.min(end + 1, n);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (ch === ' ' || ch === '\t' || ch === '\r' || ch === '\n') break;
|
|
362
|
+
if (ch === ';' || ch === '&' || ch === '|' || ch === '(' || ch === ')' || ch === '<' || ch === '>') break;
|
|
363
|
+
if (ch === '*') {
|
|
364
|
+
globKinds.add('asterisk');
|
|
365
|
+
value += ch;
|
|
366
|
+
raw += ch;
|
|
367
|
+
i += 1;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (ch === '?') {
|
|
371
|
+
globKinds.add('question');
|
|
372
|
+
value += ch;
|
|
373
|
+
raw += ch;
|
|
374
|
+
i += 1;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (ch === '[') {
|
|
378
|
+
if (hasClosingBracket(src, i)) globKinds.add('bracket');
|
|
379
|
+
value += ch;
|
|
380
|
+
raw += ch;
|
|
381
|
+
i += 1;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (ch === '{') {
|
|
385
|
+
const end = matchBraceExpansion(src, i);
|
|
386
|
+
if (end >= 0) {
|
|
387
|
+
globKinds.add('brace');
|
|
388
|
+
value += src.slice(i, end + 1);
|
|
389
|
+
raw += src.slice(i, end + 1);
|
|
390
|
+
i = end + 1;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
value += ch;
|
|
394
|
+
raw += ch;
|
|
395
|
+
i += 1;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
value += ch;
|
|
399
|
+
raw += ch;
|
|
400
|
+
i += 1;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (value.length > 0 || raw.length > 0) {
|
|
404
|
+
tokens.push({
|
|
405
|
+
value,
|
|
406
|
+
raw,
|
|
407
|
+
quoted: quotedAny,
|
|
408
|
+
hasSub,
|
|
409
|
+
hasGlob: globKinds.size > 0,
|
|
410
|
+
globKind: combineGlobKinds(globKinds),
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
if (i === before) i += 1; // paranoia: always make progress
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return tokens;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Drop redirection operators and their target words from a token list.
|
|
421
|
+
* @param {Array<object>} tokens
|
|
422
|
+
* @returns {Array<object>}
|
|
423
|
+
*/
|
|
424
|
+
function stripRedirections(tokens) {
|
|
425
|
+
const out = [];
|
|
426
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
427
|
+
const token = tokens[i];
|
|
428
|
+
if (token.op) {
|
|
429
|
+
if (i + 1 < tokens.length && !tokens[i + 1].op) i += 1;
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
out.push(token);
|
|
433
|
+
}
|
|
434
|
+
return out;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Split a chunk into pipeline stages on unquoted single `|`.
|
|
439
|
+
* Quotes, `$(...)`, backtick substitutions are respected.
|
|
440
|
+
* @param {string} src
|
|
441
|
+
* @returns {string[]}
|
|
442
|
+
*/
|
|
443
|
+
function splitPosixPipeline(src) {
|
|
444
|
+
const stages = [];
|
|
445
|
+
const n = src.length;
|
|
446
|
+
let start = 0;
|
|
447
|
+
let i = 0;
|
|
448
|
+
let quote = null;
|
|
449
|
+
while (i < n) {
|
|
450
|
+
const c = src[i];
|
|
451
|
+
if (quote === "'") {
|
|
452
|
+
if (c === "'") quote = null;
|
|
453
|
+
i += 1;
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
if (quote === '"') {
|
|
457
|
+
if (c === '\\') {
|
|
458
|
+
i += 2;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (c === '"') quote = null;
|
|
462
|
+
i += 1;
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (c === "'" || c === '"') {
|
|
466
|
+
quote = c;
|
|
467
|
+
i += 1;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if (c === '\\') {
|
|
471
|
+
i += 2;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (c === '`') {
|
|
475
|
+
const end = findBacktickEnd(src, i);
|
|
476
|
+
i = Math.min(end + 1, n);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (c === '$' && src[i + 1] === '(') {
|
|
480
|
+
const end = findParenClose(src, i + 1);
|
|
481
|
+
i = Math.min(end + 1, n);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (c === '|') {
|
|
485
|
+
if (src[i + 1] === '|') {
|
|
486
|
+
// `||` should not survive statement splitting; keep it as a boundary.
|
|
487
|
+
stages.push(src.slice(start, i));
|
|
488
|
+
i += 2;
|
|
489
|
+
start = i;
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
stages.push(src.slice(start, i));
|
|
493
|
+
i += 1;
|
|
494
|
+
start = i;
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
i += 1;
|
|
498
|
+
}
|
|
499
|
+
stages.push(src.slice(start));
|
|
500
|
+
return stages.map((stage) => stage.trim()).filter((stage) => stage.length > 0);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Parse flags and targets of an `rm` command.
|
|
505
|
+
* @param {Array<object>} args tokens after the command word
|
|
506
|
+
* @param {string} text full stage text
|
|
507
|
+
* @returns {object} partial statement
|
|
508
|
+
*/
|
|
509
|
+
function analyzeRm(args, text) {
|
|
510
|
+
let recursive = false;
|
|
511
|
+
let force = false;
|
|
512
|
+
let dryRun = false;
|
|
513
|
+
let endOfOptions = false;
|
|
514
|
+
const notes = [];
|
|
515
|
+
const risks = [];
|
|
516
|
+
const rawTargets = [];
|
|
517
|
+
|
|
518
|
+
for (const token of args) {
|
|
519
|
+
const value = token.value;
|
|
520
|
+
if (!endOfOptions && value === '--') {
|
|
521
|
+
endOfOptions = true;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (!endOfOptions && value.startsWith('--')) {
|
|
525
|
+
risks.push('rm-long-options');
|
|
526
|
+
const name = value.slice(2).split('=')[0].toLowerCase();
|
|
527
|
+
if (name === 'recursive') recursive = true;
|
|
528
|
+
else if (name === 'force') force = true;
|
|
529
|
+
else if (name === 'dry-run') {
|
|
530
|
+
dryRun = true;
|
|
531
|
+
risks.push('dry-run');
|
|
532
|
+
} else if (name === 'no-preserve-root') {
|
|
533
|
+
notes.push('使用 --no-preserve-root,允许把根目录作为删除目标');
|
|
534
|
+
} else if (name === 'verbose') {
|
|
535
|
+
// no-op
|
|
536
|
+
} else if (name === 'interactive') {
|
|
537
|
+
notes.push('--interactive 会改变确认行为,无法静态判定');
|
|
538
|
+
} else if (name === 'one-file-system') {
|
|
539
|
+
notes.push('--one-file-system 限制删除跨文件系统');
|
|
540
|
+
} else {
|
|
541
|
+
notes.push('未识别的 rm 长选项 --' + name);
|
|
542
|
+
}
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
if (!endOfOptions && value.length > 1 && value[0] === '-') {
|
|
546
|
+
for (const flag of value.slice(1)) {
|
|
547
|
+
if (flag === 'r' || flag === 'R') recursive = true;
|
|
548
|
+
else if (flag === 'f') force = true;
|
|
549
|
+
else if (flag === 'd') notes.push('-d 仅删除空目录');
|
|
550
|
+
else if (flag === 'i') notes.push('-i 为交互确认');
|
|
551
|
+
else if (flag === 'v') {
|
|
552
|
+
// verbose, nothing to record
|
|
553
|
+
} else notes.push('未识别的 rm 选项 -' + flag);
|
|
554
|
+
}
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
rawTargets.push(targetFromToken(token));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (!rawTargets.length) {
|
|
561
|
+
return makePartial({
|
|
562
|
+
text,
|
|
563
|
+
command: 'rm',
|
|
564
|
+
isDelete: true,
|
|
565
|
+
dryRun,
|
|
566
|
+
recursive,
|
|
567
|
+
force,
|
|
568
|
+
deleteKind: 'rm',
|
|
569
|
+
unparsed: true,
|
|
570
|
+
notes: notes.concat('rm 缺少可解析的删除目标'),
|
|
571
|
+
risks: risks.concat('unknown-construct'),
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return makePartial({
|
|
576
|
+
text,
|
|
577
|
+
command: 'rm',
|
|
578
|
+
isDelete: true,
|
|
579
|
+
dryRun,
|
|
580
|
+
recursive,
|
|
581
|
+
force,
|
|
582
|
+
deleteKind: 'rm',
|
|
583
|
+
notes,
|
|
584
|
+
risks,
|
|
585
|
+
rawTargets,
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Parse a `mv`/`ren` command. A move is not a deletion for the delete policy,
|
|
591
|
+
* but its targets must still be resolved: dsh-vigil's self-protection guard
|
|
592
|
+
* treats moving the installed plugin/state away as destructive too.
|
|
593
|
+
* @param {Array<object>} args
|
|
594
|
+
* @param {string} text
|
|
595
|
+
* @returns {object}
|
|
596
|
+
*/
|
|
597
|
+
function analyzeMove(args, text) {
|
|
598
|
+
/** @type {object[]} */
|
|
599
|
+
const rawTargets = [];
|
|
600
|
+
const notes = [];
|
|
601
|
+
let dryRun = false;
|
|
602
|
+
let force = false;
|
|
603
|
+
let endOfOptions = false;
|
|
604
|
+
for (const token of args) {
|
|
605
|
+
const value = unmask(token.value);
|
|
606
|
+
if (!endOfOptions && value === '--') {
|
|
607
|
+
endOfOptions = true;
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
if (!endOfOptions && (value === '-n' || value === '--dry-run' || value === '-v' || value === '--verbose')) {
|
|
611
|
+
if (value === '-n' || value === '--dry-run') dryRun = true;
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
if (!endOfOptions && (value === '-f' || value === '--force')) {
|
|
615
|
+
force = true;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
if (!endOfOptions && (value === '-i' || value === '--interactive')) {
|
|
619
|
+
notes.push('mv -i 为交互确认');
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
if (!endOfOptions && value.length > 1 && value[0] === '-' && !value.includes('/') && !value.includes('\\')) {
|
|
623
|
+
notes.push('未识别的 mv 选项 ' + value);
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
rawTargets.push(targetFromToken(token));
|
|
627
|
+
}
|
|
628
|
+
if (rawTargets.length < 2) {
|
|
629
|
+
return makePartial({
|
|
630
|
+
text,
|
|
631
|
+
command: 'mv',
|
|
632
|
+
isDelete: false,
|
|
633
|
+
dryRun,
|
|
634
|
+
force,
|
|
635
|
+
deleteKind: 'move',
|
|
636
|
+
resolveTargets: true,
|
|
637
|
+
unparsed: true,
|
|
638
|
+
notes: notes.concat('mv 缺少源/目标,无法确认移动范围'),
|
|
639
|
+
risks: ['move', 'unknown-construct'],
|
|
640
|
+
rawTargets,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
return makePartial({
|
|
644
|
+
text,
|
|
645
|
+
command: 'mv',
|
|
646
|
+
isDelete: false,
|
|
647
|
+
dryRun,
|
|
648
|
+
force,
|
|
649
|
+
deleteKind: 'move',
|
|
650
|
+
resolveTargets: true,
|
|
651
|
+
notes: notes.concat('mv 会移动目标'),
|
|
652
|
+
risks: ['move'],
|
|
653
|
+
rawTargets,
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Parse a `rmdir` command.
|
|
659
|
+
* @param {Array<object>} args
|
|
660
|
+
* @param {string} text
|
|
661
|
+
* @returns {object}
|
|
662
|
+
*/
|
|
663
|
+
function analyzeRmdir(args, text) {
|
|
664
|
+
let recursive = false;
|
|
665
|
+
let force = false;
|
|
666
|
+
let dryRun = false;
|
|
667
|
+
const notes = [];
|
|
668
|
+
const rawTargets = [];
|
|
669
|
+
for (const token of args) {
|
|
670
|
+
const value = token.value;
|
|
671
|
+
if (value === '--') continue;
|
|
672
|
+
if (value.startsWith('--')) {
|
|
673
|
+
const name = value.slice(2).split('=')[0].toLowerCase();
|
|
674
|
+
if (name === 'parents') recursive = true;
|
|
675
|
+
else if (name === 'ignore-fail-on-non-empty') notes.push('--ignore-fail-on-non-empty 忽略非空目录');
|
|
676
|
+
else if (name === 'verbose') {
|
|
677
|
+
// no-op
|
|
678
|
+
} else notes.push('未识别的 rmdir 长选项 --' + name);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (value.length > 1 && value[0] === '-') {
|
|
682
|
+
if (value.includes('p')) recursive = true;
|
|
683
|
+
if (value.includes('f')) force = true;
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
rawTargets.push(targetFromToken(token));
|
|
687
|
+
}
|
|
688
|
+
if (!rawTargets.length) {
|
|
689
|
+
return makePartial({
|
|
690
|
+
text,
|
|
691
|
+
command: 'rmdir',
|
|
692
|
+
isDelete: true,
|
|
693
|
+
dryRun,
|
|
694
|
+
recursive,
|
|
695
|
+
force,
|
|
696
|
+
deleteKind: 'rmdir',
|
|
697
|
+
unparsed: true,
|
|
698
|
+
notes: notes.concat('rmdir 缺少可解析的删除目标'),
|
|
699
|
+
risks: ['unknown-construct'],
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
return makePartial({
|
|
703
|
+
text,
|
|
704
|
+
command: 'rmdir',
|
|
705
|
+
isDelete: true,
|
|
706
|
+
dryRun,
|
|
707
|
+
recursive,
|
|
708
|
+
force,
|
|
709
|
+
deleteKind: 'rmdir',
|
|
710
|
+
notes,
|
|
711
|
+
rawTargets,
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Parse an `unlink` command.
|
|
717
|
+
* @param {Array<object>} args
|
|
718
|
+
* @param {string} text
|
|
719
|
+
* @returns {object}
|
|
720
|
+
*/
|
|
721
|
+
function analyzeUnlink(args, text) {
|
|
722
|
+
const rawTargets = [];
|
|
723
|
+
const notes = [];
|
|
724
|
+
for (const token of args) {
|
|
725
|
+
if (token.value.startsWith('-')) continue;
|
|
726
|
+
rawTargets.push(targetFromToken(token));
|
|
727
|
+
}
|
|
728
|
+
if (!rawTargets.length) {
|
|
729
|
+
return makePartial({
|
|
730
|
+
text,
|
|
731
|
+
command: 'unlink',
|
|
732
|
+
isDelete: true,
|
|
733
|
+
deleteKind: 'unlink',
|
|
734
|
+
unparsed: true,
|
|
735
|
+
notes: ['unlink 缺少可解析的目标'],
|
|
736
|
+
risks: ['unknown-construct'],
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
if (rawTargets.length > 1) notes.push('unlink 只接受一个目标,多余参数会被忽略');
|
|
740
|
+
return makePartial({
|
|
741
|
+
text,
|
|
742
|
+
command: 'unlink',
|
|
743
|
+
isDelete: true,
|
|
744
|
+
deleteKind: 'unlink',
|
|
745
|
+
notes,
|
|
746
|
+
risks: ['unlink'],
|
|
747
|
+
rawTargets,
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Parse a `shred` command. `shred -u` overwrites then unlinks the file.
|
|
753
|
+
* @param {Array<object>} args
|
|
754
|
+
* @param {string} text
|
|
755
|
+
* @returns {object}
|
|
756
|
+
*/
|
|
757
|
+
function analyzeShred(args, text) {
|
|
758
|
+
let force = false;
|
|
759
|
+
let unlink = false;
|
|
760
|
+
const notes = [];
|
|
761
|
+
const rawTargets = [];
|
|
762
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
763
|
+
const token = args[i];
|
|
764
|
+
const value = token.value;
|
|
765
|
+
if (value === '--') continue;
|
|
766
|
+
if (value.startsWith('--')) {
|
|
767
|
+
const name = value.slice(2).split('=')[0].toLowerCase();
|
|
768
|
+
if (name === 'remove') unlink = true;
|
|
769
|
+
else if (name === 'force') force = true;
|
|
770
|
+
else if (name === 'verbose' || name === 'zero' || name === 'exact') {
|
|
771
|
+
// no-op
|
|
772
|
+
} else notes.push('未识别的 shred 长选项 --' + name);
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
if (value.length > 1 && value[0] === '-') {
|
|
776
|
+
if (value.includes('u')) unlink = true;
|
|
777
|
+
if (value.includes('f')) force = true;
|
|
778
|
+
// Options -n / -s take a value.
|
|
779
|
+
if (value.includes('n') || value.includes('s')) i += 1;
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
rawTargets.push(targetFromToken(token));
|
|
783
|
+
}
|
|
784
|
+
if (!rawTargets.length) {
|
|
785
|
+
return makePartial({
|
|
786
|
+
text,
|
|
787
|
+
command: 'shred',
|
|
788
|
+
isDelete: true,
|
|
789
|
+
force,
|
|
790
|
+
deleteKind: 'other',
|
|
791
|
+
unparsed: true,
|
|
792
|
+
notes: ['shred 缺少可解析的目标'],
|
|
793
|
+
risks: ['unknown-construct'],
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
notes.push(unlink ? 'shred -u 覆写后删除文件' : 'shred 覆写文件内容(内容不可恢复)');
|
|
797
|
+
return makePartial({
|
|
798
|
+
text,
|
|
799
|
+
command: 'shred',
|
|
800
|
+
isDelete: true,
|
|
801
|
+
force,
|
|
802
|
+
deleteKind: 'other',
|
|
803
|
+
notes,
|
|
804
|
+
rawTargets,
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/** Find predicates that take one value argument (for skipping). */
|
|
809
|
+
const FIND_VALUE_PREDICATES = new Set([
|
|
810
|
+
'-name',
|
|
811
|
+
'-iname',
|
|
812
|
+
'-path',
|
|
813
|
+
'-ipath',
|
|
814
|
+
'-wholename',
|
|
815
|
+
'-iwholename',
|
|
816
|
+
'-regex',
|
|
817
|
+
'-iregex',
|
|
818
|
+
'-type',
|
|
819
|
+
'-xtype',
|
|
820
|
+
'-maxdepth',
|
|
821
|
+
'-mindepth',
|
|
822
|
+
'-user',
|
|
823
|
+
'-group',
|
|
824
|
+
'-perm',
|
|
825
|
+
'-size',
|
|
826
|
+
'-mtime',
|
|
827
|
+
'-mmin',
|
|
828
|
+
'-atime',
|
|
829
|
+
'-amin',
|
|
830
|
+
'-ctime',
|
|
831
|
+
'-cmin',
|
|
832
|
+
'-newer',
|
|
833
|
+
'-anewer',
|
|
834
|
+
'-cnewer',
|
|
835
|
+
'-links',
|
|
836
|
+
'-inum',
|
|
837
|
+
'-samefile',
|
|
838
|
+
'-fstype',
|
|
839
|
+
'-uid',
|
|
840
|
+
'-gid',
|
|
841
|
+
]);
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Parse a `find` command; returns a delete partial only when `-delete` or a
|
|
845
|
+
* deleting `-exec` action is present.
|
|
846
|
+
*
|
|
847
|
+
* @param {Array<object>} args
|
|
848
|
+
* @param {string} text
|
|
849
|
+
* @param {number} depth recursion depth guard for `-exec`
|
|
850
|
+
* @returns {object|null}
|
|
851
|
+
*/
|
|
852
|
+
function analyzeFind(args, text, depth) {
|
|
853
|
+
let i = 0;
|
|
854
|
+
const roots = [];
|
|
855
|
+
const notes = [];
|
|
856
|
+
const risks = [];
|
|
857
|
+
let hasDelete = false;
|
|
858
|
+
let execShell = false;
|
|
859
|
+
let force = false;
|
|
860
|
+
let wildcard = false;
|
|
861
|
+
let unparsed = false;
|
|
862
|
+
|
|
863
|
+
// Skip find's own leading options (-L, -H, -P, -O..., -D).
|
|
864
|
+
while (i < args.length) {
|
|
865
|
+
const value = args[i].value;
|
|
866
|
+
if (value === '-L' || value === '-H' || value === '-P') {
|
|
867
|
+
i += 1;
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
if (value === '-D' || value === '-O') {
|
|
871
|
+
i += 2;
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
if (/^-O\d/.test(value)) {
|
|
875
|
+
i += 1;
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
while (i < args.length) {
|
|
881
|
+
const value = args[i].value;
|
|
882
|
+
if (value.startsWith('-') || value === '(' || value === '!' || value === ')') break;
|
|
883
|
+
roots.push(args[i]);
|
|
884
|
+
i += 1;
|
|
885
|
+
}
|
|
886
|
+
if (!roots.length) roots.push(dotToken());
|
|
887
|
+
|
|
888
|
+
for (; i < args.length; i += 1) {
|
|
889
|
+
const value = args[i].value;
|
|
890
|
+
if (value === '-delete') {
|
|
891
|
+
hasDelete = true;
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
if (value === '-exec' || value === '-execdir' || value === '-ok' || value === '-okdir') {
|
|
895
|
+
const inner = [];
|
|
896
|
+
i += 1;
|
|
897
|
+
while (i < args.length && args[i].value !== ';' && args[i].value !== '+' && args[i].value !== '\\;') {
|
|
898
|
+
inner.push(args[i]);
|
|
899
|
+
i += 1;
|
|
900
|
+
}
|
|
901
|
+
if (inner.length === 0) continue;
|
|
902
|
+
const innerCommand = baseName(inner[0].value);
|
|
903
|
+
const innerPartial = dispatchDeleteCommand(innerCommand, inner.slice(1), text, (depth || 0) + 1);
|
|
904
|
+
if (innerPartial && innerPartial.isDelete) {
|
|
905
|
+
hasDelete = true;
|
|
906
|
+
force = force || Boolean(innerPartial.force);
|
|
907
|
+
// Do not inherit the inner command's target-related `unparsed` state:
|
|
908
|
+
// `{}` is the find placeholder, the real targets are the find roots.
|
|
909
|
+
notes.push('find -exec 调用 ' + innerCommand + ' 删除匹配项');
|
|
910
|
+
} else if (['sh', 'bash', 'zsh', 'dash', 'ksh', 'pwsh', 'powershell', 'cmd'].includes(innerCommand)) {
|
|
911
|
+
hasDelete = true;
|
|
912
|
+
execShell = true;
|
|
913
|
+
unparsed = true;
|
|
914
|
+
risks.push('unknown-construct');
|
|
915
|
+
notes.push('find -exec 通过 ' + innerCommand + ' 执行脚本,无法静态解析删除范围');
|
|
916
|
+
}
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
if (value === '-name' || value === '-iname' || value === '-path' || value === '-ipath' || value === '-wholename' || value === '-iwholename' || value === '-regex' || value === '-iregex') {
|
|
920
|
+
const pattern = args[i + 1];
|
|
921
|
+
if (pattern && /[*?[\]{]/.test(pattern.value)) wildcard = true;
|
|
922
|
+
i += 1;
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
if (FIND_VALUE_PREDICATES.has(value)) {
|
|
926
|
+
i += 1;
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
if (!hasDelete) return null;
|
|
932
|
+
if (execShell) unparsed = true;
|
|
933
|
+
notes.push('-delete 会递归删除所有匹配项');
|
|
934
|
+
return makePartial({
|
|
935
|
+
text,
|
|
936
|
+
command: 'find',
|
|
937
|
+
isDelete: true,
|
|
938
|
+
recursive: true,
|
|
939
|
+
force,
|
|
940
|
+
wildcard,
|
|
941
|
+
deleteKind: 'find-delete',
|
|
942
|
+
unparsed,
|
|
943
|
+
notes,
|
|
944
|
+
risks: risks.concat('find-delete'),
|
|
945
|
+
rawTargets: roots.map((token) => targetFromToken(token)),
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Parse `git clean [-fdxn]`.
|
|
951
|
+
* @param {Array<object>} args tokens after `git`
|
|
952
|
+
* @param {string} text
|
|
953
|
+
* @returns {object|null}
|
|
954
|
+
*/
|
|
955
|
+
function analyzeGitClean(args, text) {
|
|
956
|
+
let cleanIndex = -1;
|
|
957
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
958
|
+
const value = args[i].value;
|
|
959
|
+
if (value === 'clean') {
|
|
960
|
+
cleanIndex = i;
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
if (value === 'status' || value === 'commit' || value === 'log' || value === 'diff' || value === 'push' || value === 'checkout' || value === 'reset') {
|
|
964
|
+
return null;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
if (cleanIndex < 0) return null;
|
|
968
|
+
|
|
969
|
+
let force = false;
|
|
970
|
+
let dryRun = false;
|
|
971
|
+
let dirs = false;
|
|
972
|
+
let ignored = false;
|
|
973
|
+
let interactive = false;
|
|
974
|
+
const notes = [];
|
|
975
|
+
const risks = [];
|
|
976
|
+
const rawTargets = [];
|
|
977
|
+
|
|
978
|
+
for (let i = cleanIndex + 1; i < args.length; i += 1) {
|
|
979
|
+
const token = args[i];
|
|
980
|
+
const value = token.value;
|
|
981
|
+
if (value === '--') continue;
|
|
982
|
+
if (value.startsWith('--')) {
|
|
983
|
+
const name = value.slice(2).split('=')[0].toLowerCase();
|
|
984
|
+
if (name === 'force') force = true;
|
|
985
|
+
else if (name === 'dry-run') dryRun = true;
|
|
986
|
+
else if (name === 'interactive') interactive = true;
|
|
987
|
+
else if (name === 'quiet') {
|
|
988
|
+
// no-op
|
|
989
|
+
} else notes.push('未识别的 git clean 长选项 --' + name);
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
if (value.length > 1 && value[0] === '-') {
|
|
993
|
+
for (const flag of value.slice(1)) {
|
|
994
|
+
if (flag === 'f') force = true;
|
|
995
|
+
else if (flag === 'n') dryRun = true;
|
|
996
|
+
else if (flag === 'd') dirs = true;
|
|
997
|
+
else if (flag === 'x' || flag === 'X') ignored = true;
|
|
998
|
+
else if (flag === 'i') interactive = true;
|
|
999
|
+
else if (flag === 'q') {
|
|
1000
|
+
// quiet
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
rawTargets.push(targetFromToken(token));
|
|
1006
|
+
}
|
|
1007
|
+
if (!rawTargets.length) rawTargets.push(targetFromToken(dotToken(), { note: 'git clean 默认作用于当前工作区' }));
|
|
1008
|
+
if (dirs) notes.push('git clean -d 会递归删除未跟踪目录');
|
|
1009
|
+
if (ignored) notes.push('git clean -x 会连同 .gitignore 中忽略的文件一起删除');
|
|
1010
|
+
if (!force && !dryRun && !interactive) {
|
|
1011
|
+
return makePartial({
|
|
1012
|
+
text,
|
|
1013
|
+
command: 'git',
|
|
1014
|
+
isDelete: false,
|
|
1015
|
+
deleteKind: 'none',
|
|
1016
|
+
notes: notes.concat('git clean 未带 -f/-n/-i,git 会拒绝执行'),
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
if (interactive) {
|
|
1020
|
+
risks.push('unknown-construct');
|
|
1021
|
+
notes.push('git clean -i 为交互式删除,实际范围取决于交互输入');
|
|
1022
|
+
}
|
|
1023
|
+
return makePartial({
|
|
1024
|
+
text,
|
|
1025
|
+
command: 'git',
|
|
1026
|
+
isDelete: true,
|
|
1027
|
+
dryRun,
|
|
1028
|
+
recursive: dirs,
|
|
1029
|
+
force,
|
|
1030
|
+
deleteKind: 'git-clean',
|
|
1031
|
+
unparsed: interactive,
|
|
1032
|
+
notes,
|
|
1033
|
+
risks,
|
|
1034
|
+
rawTargets,
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Parse `rsync ... --delete ...`.
|
|
1040
|
+
* @param {Array<object>} args
|
|
1041
|
+
* @param {string} text
|
|
1042
|
+
* @returns {object|null}
|
|
1043
|
+
*/
|
|
1044
|
+
function analyzeRsync(args, text) {
|
|
1045
|
+
let hasDelete = false;
|
|
1046
|
+
let dryRun = false;
|
|
1047
|
+
let recursive = false;
|
|
1048
|
+
const notes = [];
|
|
1049
|
+
const risks = [];
|
|
1050
|
+
const positional = [];
|
|
1051
|
+
for (const token of args) {
|
|
1052
|
+
const value = token.value;
|
|
1053
|
+
if (value === '--delete' || value.startsWith('--delete-') || value === '--del') {
|
|
1054
|
+
hasDelete = true;
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
if (value === '--dry-run') {
|
|
1058
|
+
dryRun = true;
|
|
1059
|
+
continue;
|
|
1060
|
+
}
|
|
1061
|
+
if (value === '--recursive') {
|
|
1062
|
+
recursive = true;
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
if (value.length > 1 && value[0] === '-' && value[1] === '-') continue;
|
|
1066
|
+
if (value.length > 1 && value[0] === '-') {
|
|
1067
|
+
if (value.slice(1).includes('r') || value.slice(1).includes('a')) recursive = true;
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
positional.push(token);
|
|
1071
|
+
}
|
|
1072
|
+
if (!hasDelete) return null;
|
|
1073
|
+
const dest = positional.length ? positional[positional.length - 1] : null;
|
|
1074
|
+
notes.push('rsync --delete 会删除目标目录中源端不存在的文件');
|
|
1075
|
+
risks.push('mirror-delete');
|
|
1076
|
+
if (!dest) {
|
|
1077
|
+
return makePartial({
|
|
1078
|
+
text,
|
|
1079
|
+
command: 'rsync',
|
|
1080
|
+
isDelete: true,
|
|
1081
|
+
dryRun,
|
|
1082
|
+
recursive,
|
|
1083
|
+
deleteKind: 'other',
|
|
1084
|
+
unparsed: true,
|
|
1085
|
+
notes: notes.concat('未找到 rsync 目标目录'),
|
|
1086
|
+
risks: risks.concat('unknown-construct'),
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
return makePartial({
|
|
1090
|
+
text,
|
|
1091
|
+
command: 'rsync',
|
|
1092
|
+
isDelete: true,
|
|
1093
|
+
dryRun,
|
|
1094
|
+
recursive,
|
|
1095
|
+
deleteKind: 'other',
|
|
1096
|
+
notes,
|
|
1097
|
+
risks,
|
|
1098
|
+
rawTargets: [targetFromToken(dest, { note: 'rsync 目标目录' })],
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Parse an `xargs [opts] <delete-command> [args]` invocation.
|
|
1104
|
+
* @param {Array<object>} args
|
|
1105
|
+
* @param {string} text
|
|
1106
|
+
* @param {number} depth
|
|
1107
|
+
* @returns {object|null}
|
|
1108
|
+
*/
|
|
1109
|
+
function analyzeXargs(args, text, depth) {
|
|
1110
|
+
if ((depth || 0) > 3) return null;
|
|
1111
|
+
let i = 0;
|
|
1112
|
+
let placeholder = null;
|
|
1113
|
+
while (i < args.length) {
|
|
1114
|
+
const value = args[i].value;
|
|
1115
|
+
if (value === '--') {
|
|
1116
|
+
i += 1;
|
|
1117
|
+
break;
|
|
1118
|
+
}
|
|
1119
|
+
if (value === '-I') {
|
|
1120
|
+
placeholder = args[i + 1] ? unmask(args[i + 1].value) : null;
|
|
1121
|
+
i += 2;
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1124
|
+
if (value.startsWith('-I') && value.length > 2) {
|
|
1125
|
+
placeholder = unmask(value.slice(2));
|
|
1126
|
+
i += 1;
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
if (value === '-n' || value === '-P' || value === '-L' || value === '-d' || value === '-s' || value === '-a' || value === '-E' || value === '-e') {
|
|
1130
|
+
i += 2;
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
if (value.startsWith('-')) {
|
|
1134
|
+
i += 1;
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
break;
|
|
1138
|
+
}
|
|
1139
|
+
if (i >= args.length) return null;
|
|
1140
|
+
const innerCommand = baseName(args[i].value);
|
|
1141
|
+
const innerArgs = args.slice(i + 1);
|
|
1142
|
+
if (['sh', 'bash', 'zsh', 'dash', 'ksh', 'pwsh', 'powershell', 'cmd'].includes(innerCommand)) {
|
|
1143
|
+
return makePartial({
|
|
1144
|
+
text,
|
|
1145
|
+
command: 'xargs',
|
|
1146
|
+
isDelete: true,
|
|
1147
|
+
deleteKind: 'other',
|
|
1148
|
+
unparsed: true,
|
|
1149
|
+
notes: ['xargs 通过 ' + innerCommand + ' 执行内联脚本,无法静态解析删除范围'],
|
|
1150
|
+
risks: ['unknown-construct'],
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
const inner = dispatchDeleteCommand(innerCommand, innerArgs, text, (depth || 0) + 1);
|
|
1154
|
+
if (!inner || !inner.isDelete) return null;
|
|
1155
|
+
|
|
1156
|
+
const innerHadTargets = Array.isArray(inner.rawTargets) && inner.rawTargets.length > 0;
|
|
1157
|
+
const notes = (inner.notes || [])
|
|
1158
|
+
.filter((note) => !(innerHadTargets || !String(note).includes('缺少可解析的删除目标')))
|
|
1159
|
+
.concat('经 xargs 调用 ' + innerCommand + ' 批量删除');
|
|
1160
|
+
const rawTargets = [];
|
|
1161
|
+
for (const target of inner.rawTargets || []) {
|
|
1162
|
+
const isPlaceholder =
|
|
1163
|
+
target.raw === '' ||
|
|
1164
|
+
target.raw === '{}' ||
|
|
1165
|
+
(placeholder !== null && target.raw === placeholder);
|
|
1166
|
+
if (isPlaceholder) continue;
|
|
1167
|
+
rawTargets.push(Object.assign({}, target, { viaPipeline: true }));
|
|
1168
|
+
}
|
|
1169
|
+
const inheritedRisks = (inner.risks || []).filter((risk) => innerHadTargets || risk !== 'unknown-construct');
|
|
1170
|
+
const partial = makePartial({
|
|
1171
|
+
text,
|
|
1172
|
+
command: 'xargs',
|
|
1173
|
+
isDelete: true,
|
|
1174
|
+
dryRun: Boolean(inner.dryRun),
|
|
1175
|
+
recursive: Boolean(inner.recursive),
|
|
1176
|
+
force: Boolean(inner.force),
|
|
1177
|
+
wildcard: Boolean(inner.wildcard),
|
|
1178
|
+
deleteKind: inner.deleteKind,
|
|
1179
|
+
// When xargs itself has no explicit target the deletion targets come from
|
|
1180
|
+
// the pipeline, which is resolved by parsePosixStatements().
|
|
1181
|
+
unparsed: innerHadTargets ? Boolean(inner.unparsed) : false,
|
|
1182
|
+
notes,
|
|
1183
|
+
risks: inheritedRisks.concat('pipeline-generic'),
|
|
1184
|
+
rawTargets,
|
|
1185
|
+
});
|
|
1186
|
+
partial.needsPipelineInput = true;
|
|
1187
|
+
return partial;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Dispatch a delete command name to its analyser.
|
|
1192
|
+
* @param {string} command lowercase basename
|
|
1193
|
+
* @param {Array<object>} args
|
|
1194
|
+
* @param {string} text
|
|
1195
|
+
* @param {number} depth
|
|
1196
|
+
* @returns {object|null}
|
|
1197
|
+
*/
|
|
1198
|
+
function dispatchDeleteCommand(command, args, text, depth) {
|
|
1199
|
+
if (!DELETE_COMMANDS.has(command)) return null;
|
|
1200
|
+
switch (command) {
|
|
1201
|
+
case 'rm':
|
|
1202
|
+
return analyzeRm(args, text);
|
|
1203
|
+
case 'rmdir':
|
|
1204
|
+
return analyzeRmdir(args, text);
|
|
1205
|
+
case 'unlink':
|
|
1206
|
+
return analyzeUnlink(args, text);
|
|
1207
|
+
case 'shred':
|
|
1208
|
+
return analyzeShred(args, text);
|
|
1209
|
+
case 'find':
|
|
1210
|
+
return analyzeFind(args, text, depth || 0);
|
|
1211
|
+
case 'xargs':
|
|
1212
|
+
return analyzeXargs(args, text, depth || 0);
|
|
1213
|
+
case 'git':
|
|
1214
|
+
return analyzeGitClean(args, text);
|
|
1215
|
+
case 'rsync':
|
|
1216
|
+
return analyzeRsync(args, text);
|
|
1217
|
+
case 'mv':
|
|
1218
|
+
return analyzeMove(args, text);
|
|
1219
|
+
default:
|
|
1220
|
+
return null;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Extract the upstream roots a producer command emits into a pipeline.
|
|
1226
|
+
* @param {string} command
|
|
1227
|
+
* @param {Array<object>} args
|
|
1228
|
+
* @returns {{roots: Array<object>, recursive: boolean, wildcard: boolean}|null}
|
|
1229
|
+
*/
|
|
1230
|
+
function producerInfo(command, args) {
|
|
1231
|
+
if (!PRODUCER_COMMANDS.has(command)) return null;
|
|
1232
|
+
const roots = [];
|
|
1233
|
+
let wildcard = false;
|
|
1234
|
+
if (command === 'find') {
|
|
1235
|
+
let i = 0;
|
|
1236
|
+
while (i < args.length) {
|
|
1237
|
+
const value = args[i].value;
|
|
1238
|
+
if (value === '-L' || value === '-H' || value === '-P') {
|
|
1239
|
+
i += 1;
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
if (value.startsWith('-') || value === '(' || value === '!' || value === ')') break;
|
|
1243
|
+
roots.push(args[i]);
|
|
1244
|
+
i += 1;
|
|
1245
|
+
}
|
|
1246
|
+
for (; i < args.length; i += 1) {
|
|
1247
|
+
const value = args[i].value;
|
|
1248
|
+
if ((value === '-name' || value === '-iname' || value === '-path') && args[i + 1] && /[*?[\]{]/.test(args[i + 1].value)) {
|
|
1249
|
+
wildcard = true;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
} else if (command === 'printf') {
|
|
1253
|
+
const positional = args.filter((token) => !token.value.startsWith('-'));
|
|
1254
|
+
positional.slice(1).forEach((token) => roots.push(token));
|
|
1255
|
+
} else {
|
|
1256
|
+
for (const token of args) {
|
|
1257
|
+
if (token.value.startsWith('-') && token.value !== '-') continue;
|
|
1258
|
+
roots.push(token);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
if (!roots.length) roots.push(dotToken());
|
|
1262
|
+
return {
|
|
1263
|
+
roots: roots.map((token) => targetFromToken(token)),
|
|
1264
|
+
recursive: command === 'find',
|
|
1265
|
+
wildcard,
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* Redirect targets a `>` would truncate. `>>` appends; `/dev/null` and
|
|
1271
|
+
* `/dev/stdout` are not real files.
|
|
1272
|
+
* @param {Array<object>} tokens
|
|
1273
|
+
* @returns {Array<object>}
|
|
1274
|
+
*/
|
|
1275
|
+
function collectTruncateRedirects(tokens) {
|
|
1276
|
+
const targets = [];
|
|
1277
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
1278
|
+
const token = tokens[i];
|
|
1279
|
+
if (!token.op || !/^[0-9]?>$/.test(token.value)) continue;
|
|
1280
|
+
const next = tokens[i + 1];
|
|
1281
|
+
if (!next || next.op) continue;
|
|
1282
|
+
const value = String(next.value ?? '').trim();
|
|
1283
|
+
// `$null` / `NUL` are void sinks, same as `/dev/null`; never treat them as files.
|
|
1284
|
+
if (value === '' || /^\$?(?:null|nul)$/i.test(value) || /^\/dev\/(?:null|stdout|stderr)$/.test(value)) continue;
|
|
1285
|
+
targets.push(next);
|
|
1286
|
+
}
|
|
1287
|
+
return targets;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/** Commands whose own delete handling must win over redirect truncation. */
|
|
1291
|
+
const POSIX_DELETE_WORDS = new Set(['rm', 'unlink', 'rmdir', 'rd', 'find', 'shred', 'srm', 'trash', 'trash-put'])
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Parse one pipeline stage into a partial statement plus producer info.
|
|
1295
|
+
* @param {string} stageText
|
|
1296
|
+
* @param {number} depth
|
|
1297
|
+
* @returns {{partial: object, producer: object|null}}
|
|
1298
|
+
*/
|
|
1299
|
+
function parseStage(stageText, depth) {
|
|
1300
|
+
const rawTokens = tokenizePosix(stageText);
|
|
1301
|
+
const redirTargets = collectTruncateRedirects(rawTokens);
|
|
1302
|
+
const tokens = stripRedirections(rawTokens);
|
|
1303
|
+
let index = 0;
|
|
1304
|
+
while (index < tokens.length) {
|
|
1305
|
+
const value = tokens[index].value;
|
|
1306
|
+
if (!value) {
|
|
1307
|
+
index += 1;
|
|
1308
|
+
continue;
|
|
1309
|
+
}
|
|
1310
|
+
if (SKIP_WORDS.has(value)) {
|
|
1311
|
+
index += 1;
|
|
1312
|
+
continue;
|
|
1313
|
+
}
|
|
1314
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(value)) {
|
|
1315
|
+
index += 1;
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
break;
|
|
1319
|
+
}
|
|
1320
|
+
if (index >= tokens.length) return { partial: null, producer: null };
|
|
1321
|
+
|
|
1322
|
+
let command = baseName(tokens[index].value);
|
|
1323
|
+
let argStart = index + 1;
|
|
1324
|
+
if (command === 'busybox' && tokens[index + 1]) {
|
|
1325
|
+
command = baseName(tokens[index + 1].value);
|
|
1326
|
+
argStart = index + 2;
|
|
1327
|
+
}
|
|
1328
|
+
const args = tokens.slice(argStart);
|
|
1329
|
+
const producer = producerInfo(command, args);
|
|
1330
|
+
|
|
1331
|
+
// `command > file` truncates `file`; `>>` only appends, `/dev/null` is not a file.
|
|
1332
|
+
if (redirTargets.length > 0 && !POSIX_DELETE_WORDS.has(command)) {
|
|
1333
|
+
return {
|
|
1334
|
+
partial: makePartial({
|
|
1335
|
+
text: stageText.trim(),
|
|
1336
|
+
command: 'redirect',
|
|
1337
|
+
isDelete: true,
|
|
1338
|
+
deleteKind: 'truncate',
|
|
1339
|
+
notes: ['重定向符号 > 会截断目标文件(>> 只追加)'],
|
|
1340
|
+
rawTargets: redirTargets.map(token => targetFromToken(token)),
|
|
1341
|
+
}),
|
|
1342
|
+
producer: null,
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
if (COMPOUND_WORDS.has(command)) {
|
|
1347
|
+
return {
|
|
1348
|
+
partial: makePartial({
|
|
1349
|
+
text: stageText.trim(),
|
|
1350
|
+
command,
|
|
1351
|
+
notes: ['复合语句片段,未在其中直接发现删除命令'],
|
|
1352
|
+
}),
|
|
1353
|
+
producer: null,
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
const partial = dispatchDeleteCommand(command, args, stageText.trim(), depth || 0);
|
|
1358
|
+
if (partial) return { partial, producer: partial.isDelete ? null : producer };
|
|
1359
|
+
return {
|
|
1360
|
+
partial: makePartial({ text: stageText.trim(), command }),
|
|
1361
|
+
producer,
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* Parse a POSIX command chunk (which may be a pipeline).
|
|
1367
|
+
*
|
|
1368
|
+
* @param {string} chunkText one shell statement, separators already removed
|
|
1369
|
+
* @param {number} [depth] internal recursion guard (xargs / find -exec)
|
|
1370
|
+
* @returns {object[]} partial statements
|
|
1371
|
+
*/
|
|
1372
|
+
export function parsePosixStatements(chunkText, depth) {
|
|
1373
|
+
const stages = splitPosixPipeline(String(chunkText || ''));
|
|
1374
|
+
const out = [];
|
|
1375
|
+
let upstream = null;
|
|
1376
|
+
|
|
1377
|
+
for (const stageText of stages) {
|
|
1378
|
+
let parsed;
|
|
1379
|
+
try {
|
|
1380
|
+
parsed = parseStage(stageText, depth || 0);
|
|
1381
|
+
} catch {
|
|
1382
|
+
out.push(
|
|
1383
|
+
makePartial({
|
|
1384
|
+
text: stageText.trim(),
|
|
1385
|
+
command: '',
|
|
1386
|
+
unparsed: true,
|
|
1387
|
+
risks: ['unknown-construct'],
|
|
1388
|
+
notes: ['POSIX 解析异常,已降级为不可解析语句'],
|
|
1389
|
+
}),
|
|
1390
|
+
);
|
|
1391
|
+
continue;
|
|
1392
|
+
}
|
|
1393
|
+
if (!parsed.partial) continue;
|
|
1394
|
+
const partial = parsed.partial;
|
|
1395
|
+
|
|
1396
|
+
if (partial.isDelete && partial.needsPipelineInput) {
|
|
1397
|
+
const derived = upstream && upstream.roots && upstream.roots.length ? upstream.roots : [];
|
|
1398
|
+
if (derived.length) {
|
|
1399
|
+
partial.rawTargets = partial.rawTargets.concat(
|
|
1400
|
+
derived.map((target) => Object.assign({}, target, { viaPipeline: true, note: '目标来自管道上游' })),
|
|
1401
|
+
);
|
|
1402
|
+
if (upstream.wildcard) partial.wildcard = true;
|
|
1403
|
+
} else {
|
|
1404
|
+
partial.rawTargets = partial.rawTargets.concat([
|
|
1405
|
+
{
|
|
1406
|
+
raw: '<pipeline>',
|
|
1407
|
+
text: '',
|
|
1408
|
+
hasGlob: false,
|
|
1409
|
+
globKind: 'none',
|
|
1410
|
+
viaPipeline: true,
|
|
1411
|
+
synthetic: true,
|
|
1412
|
+
scopeOverride: 'unknown',
|
|
1413
|
+
},
|
|
1414
|
+
]);
|
|
1415
|
+
partial.unparsed = true;
|
|
1416
|
+
partial.risks.push('unknown-construct');
|
|
1417
|
+
}
|
|
1418
|
+
if (!partial.risks.includes('pipeline-generic')) partial.risks.push('pipeline-generic');
|
|
1419
|
+
partial.notes.push('删除目标由管道上游提供,无法静态确定具体文件');
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
out.push(partial);
|
|
1423
|
+
if (parsed.producer) upstream = parsed.producer;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
return out;
|
|
1427
|
+
}
|