fauxnix-cli 0.13.0 → 2.0.0
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 +49 -8
- package/dist/cli.js +18 -7
- package/dist/commands/archive.js +135 -103
- package/dist/commands/files.d.ts +2 -1
- package/dist/commands/files.js +139 -50
- package/dist/commands/gzip-node.d.ts +3 -0
- package/dist/commands/gzip-node.js +119 -0
- package/dist/commands/move-native.d.ts +1 -0
- package/dist/commands/move-native.js +82 -0
- package/dist/commands/net.js +26 -34
- package/dist/commands/sysinfo.js +16 -10
- package/dist/commands/text-filters.js +50 -116
- package/dist/commands/text-io.js +103 -88
- package/dist/commands/text-output.d.ts +14 -0
- package/dist/commands/text-output.js +29 -0
- package/dist/doctor.js +9 -12
- package/dist/encoding.d.ts +5 -0
- package/dist/encoding.js +40 -0
- package/dist/errors.js +7 -1
- package/dist/executor.js +1 -15
- package/dist/facade.d.ts +1 -0
- package/dist/facade.js +115 -0
- package/dist/index.js +11 -5
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +162 -141
- package/dist/parser.js +18 -1
- package/dist/ps-host.js +42 -4
- package/dist/registry.d.ts +5 -0
- package/dist/registry.js +10 -5
- package/dist/runtime-support.d.ts +3 -0
- package/dist/runtime-support.js +22 -0
- package/dist/translator.d.ts +2 -1
- package/dist/translator.js +51 -42
- package/package.json +6 -4
package/dist/commands/files.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FauxnixParseError, wordToString } from '../ast.js';
|
|
2
2
|
import { parseWords, psStr, } from '../registry.js';
|
|
3
3
|
import { argListExpr, exprOfWord, operandExpr } from '../translator.js';
|
|
4
|
+
import { PS_WRITE_FN, fxTermLine } from './text-output.js';
|
|
5
|
+
import { PS_MOVE_REPLACE_FN } from './move-native.js';
|
|
4
6
|
/* ------------------------------------------------------------------ */
|
|
5
7
|
/* Shared PS snippets */
|
|
6
8
|
/* ------------------------------------------------------------------ */
|
|
@@ -149,22 +151,22 @@ const cp = (args) => {
|
|
|
149
151
|
PS_GLOB_FN,
|
|
150
152
|
'$fx_all = ' + argListExpr(operandWords),
|
|
151
153
|
"if ($fx_all.Count -lt 2) { $fx_srcs = @(); $fx_dst = '' } else { $fx_dst = [string]$fx_all[$fx_all.Count - 1]; $fx_srcs = @($fx_all[0..($fx_all.Count - 2)]) }",
|
|
154
|
+
'$fx_srcs = @($fx_srcs | ForEach-Object { fx-glob $_ })',
|
|
152
155
|
"if ($fx_srcs.Count -eq 0) { [Console]::Error.WriteLine('cp: missing file operand'); $script:fx_exit = 1 }",
|
|
153
156
|
"elseif ($fx_dst -eq '') { [Console]::Error.WriteLine('cp: missing destination file operand'); $script:fx_exit = 1 }",
|
|
157
|
+
'elseif ($fx_srcs.Count -gt 1 -and -not (Test-Path -LiteralPath $fx_dst -PathType Container)) { [Console]::Error.WriteLine("cp: target \'" + $fx_dst + "\' is not a directory"); $script:fx_exit = 1 }',
|
|
154
158
|
'else {',
|
|
155
|
-
' foreach ($
|
|
156
|
-
'
|
|
157
|
-
'
|
|
158
|
-
'
|
|
159
|
-
'
|
|
160
|
-
'
|
|
161
|
-
'
|
|
162
|
-
'
|
|
163
|
-
'
|
|
164
|
-
'
|
|
165
|
-
'
|
|
166
|
-
' } catch { [Console]::Error.WriteLine("cp: cannot copy \'" + $fx_g + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
167
|
-
' }',
|
|
159
|
+
' foreach ($fx_g in $fx_srcs) {',
|
|
160
|
+
' if (-not (Test-Path -LiteralPath $fx_g)) { [Console]::Error.WriteLine("cp: cannot stat \'" + $fx_g + "\': No such file or directory"); $script:fx_exit = 1; continue }',
|
|
161
|
+
' $fx_isdir = (Test-Path -LiteralPath $fx_g -PathType Container)',
|
|
162
|
+
' if ($fx_isdir -and ' + (recurse ? '$false' : '$true') + ') { [Console]::Error.WriteLine("cp: -r not specified; omitting directory \'" + $fx_g + "\'"); $script:fx_exit = 1; continue }',
|
|
163
|
+
' $fx_target = $fx_dst',
|
|
164
|
+
' if (Test-Path -LiteralPath $fx_dst -PathType Container) { $fx_target = Join-Path $fx_dst (Split-Path $fx_g -Leaf) }',
|
|
165
|
+
' if (' + (noclobber ? '$true' : '$false') + ' -and (Test-Path -LiteralPath $fx_target)) { continue }',
|
|
166
|
+
' try {',
|
|
167
|
+
' Copy-Item -LiteralPath $fx_g -Destination $fx_target -Recurse:' + (recurse ? '$true' : '$false') + ' -Force -ErrorAction Stop',
|
|
168
|
+
' if (' + (verbose ? '$true' : '$false') + ') { [Console]::Error.WriteLine("\'" + $fx_g + "\' -> \'" + $fx_target + "\'") }',
|
|
169
|
+
' } catch { [Console]::Error.WriteLine("cp: cannot copy \'" + $fx_g + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
168
170
|
' }',
|
|
169
171
|
'}',
|
|
170
172
|
].join('\n');
|
|
@@ -175,24 +177,48 @@ const mv = (args) => {
|
|
|
175
177
|
const noclobber = flags.has('n') || longs.has('--no-clobber');
|
|
176
178
|
return [
|
|
177
179
|
PS_GLOB_FN,
|
|
180
|
+
PS_MOVE_REPLACE_FN,
|
|
178
181
|
'$fx_all = ' + argListExpr(operandWords),
|
|
179
182
|
"if ($fx_all.Count -lt 2) { $fx_srcs = @(); $fx_dst = '' } else { $fx_dst = [string]$fx_all[$fx_all.Count - 1]; $fx_srcs = @($fx_all[0..($fx_all.Count - 2)]) }",
|
|
183
|
+
'$fx_srcs = @($fx_srcs | ForEach-Object { fx-glob $_ })',
|
|
180
184
|
"if ($fx_srcs.Count -eq 0) { [Console]::Error.WriteLine('mv: missing file operand'); $script:fx_exit = 1 }",
|
|
181
185
|
"elseif ($fx_dst -eq '') { [Console]::Error.WriteLine('mv: missing destination file operand'); $script:fx_exit = 1 }",
|
|
182
186
|
'elseif ($fx_srcs.Count -gt 1 -and -not (Test-Path -LiteralPath $fx_dst -PathType Container)) { [Console]::Error.WriteLine("mv: target \'" + $fx_dst + "\' is not a directory"); $script:fx_exit = 1 }',
|
|
183
187
|
'else {',
|
|
184
|
-
' foreach ($
|
|
185
|
-
'
|
|
186
|
-
'
|
|
187
|
-
'
|
|
188
|
-
'
|
|
189
|
-
'
|
|
190
|
-
'
|
|
191
|
-
'
|
|
192
|
-
'
|
|
193
|
-
|
|
194
|
-
'
|
|
195
|
-
'
|
|
188
|
+
' foreach ($fx_g in $fx_srcs) {',
|
|
189
|
+
' if (-not (Test-Path -LiteralPath $fx_g)) { [Console]::Error.WriteLine("mv: cannot stat \'" + $fx_g + "\': No such file or directory"); $script:fx_exit = 1; continue }',
|
|
190
|
+
' $fx_target = $fx_dst',
|
|
191
|
+
' if (Test-Path -LiteralPath $fx_dst -PathType Container) { $fx_target = Join-Path $fx_dst (Split-Path $fx_g -Leaf) }',
|
|
192
|
+
' if (' + (noclobber ? '$true' : '$false') + ' -and (Test-Path -LiteralPath $fx_target)) { continue }',
|
|
193
|
+
' try {',
|
|
194
|
+
' if (Test-Path -LiteralPath $fx_target) {',
|
|
195
|
+
' $fx_sourcePath = (Resolve-Path -LiteralPath $fx_g -ErrorAction Stop).ProviderPath',
|
|
196
|
+
' $fx_targetPath = (Resolve-Path -LiteralPath $fx_target -ErrorAction Stop).ProviderPath',
|
|
197
|
+
" if ($fx_sourcePath.TrimEnd([char[]]'\\/') -eq $fx_targetPath.TrimEnd([char[]]'\\/')) {",
|
|
198
|
+
' [Console]::Error.WriteLine("mv: \'" + $fx_g + "\' and \'" + $fx_target + "\' are the same file"); $script:fx_exit = 1; continue',
|
|
199
|
+
' }',
|
|
200
|
+
' $fx_sourceItem = Get-Item -LiteralPath $fx_g -Force -ErrorAction Stop',
|
|
201
|
+
' $fx_targetItem = Get-Item -LiteralPath $fx_target -Force -ErrorAction Stop',
|
|
202
|
+
' if (-not $fx_sourceItem.PSIsContainer -and $fx_targetItem.PSIsContainer) {',
|
|
203
|
+
' [Console]::Error.WriteLine("mv: cannot overwrite directory \'" + $fx_target + "\' with non-directory \'" + $fx_g + "\'"); $script:fx_exit = 1; continue',
|
|
204
|
+
' }',
|
|
205
|
+
' if ($fx_sourceItem.PSIsContainer -and -not $fx_targetItem.PSIsContainer) {',
|
|
206
|
+
' [Console]::Error.WriteLine("mv: cannot overwrite non-directory \'" + $fx_target + "\' with directory \'" + $fx_g + "\'"); $script:fx_exit = 1; continue',
|
|
207
|
+
' }',
|
|
208
|
+
' if ($fx_targetItem.PSIsContainer) {',
|
|
209
|
+
' if (@(Get-ChildItem -LiteralPath $fx_target -Force -ErrorAction Stop).Count -gt 0) {',
|
|
210
|
+
' [Console]::Error.WriteLine("mv: cannot move \'" + $fx_g + "\' to \'" + $fx_target + "\': Directory not empty"); $script:fx_exit = 1; continue',
|
|
211
|
+
' }',
|
|
212
|
+
' [Console]::Error.WriteLine("mv: replacement of an existing empty directory is unsupported; both directories retained"); $script:fx_exit = 1; continue',
|
|
213
|
+
' } else {',
|
|
214
|
+
' fx-move-replace-file $fx_sourcePath $fx_targetPath',
|
|
215
|
+
' }',
|
|
216
|
+
' } else {',
|
|
217
|
+
// No force retry if a destination appears after the preflight.
|
|
218
|
+
' Move-Item -LiteralPath $fx_g -Destination $fx_target -ErrorAction Stop',
|
|
219
|
+
' }',
|
|
220
|
+
' if (' + (verbose ? '$true' : '$false') + ') { [Console]::Error.WriteLine("renamed \'" + $fx_g + "\' -> \'" + $fx_target + "\'") }',
|
|
221
|
+
' } catch { [Console]::Error.WriteLine("mv: cannot move \'" + $fx_g + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
196
222
|
' }',
|
|
197
223
|
'}',
|
|
198
224
|
].join('\n');
|
|
@@ -215,7 +241,7 @@ const rm = (args) => {
|
|
|
215
241
|
' $fx_isdir = (Test-Path -LiteralPath $fx_g -PathType Container)',
|
|
216
242
|
' if ($fx_isdir -and ' + (recurse ? '$false' : '$true') + ') { [Console]::Error.WriteLine("rm: cannot remove \'" + $fx_g + "\': Is a directory"); $script:fx_exit = 1; continue }',
|
|
217
243
|
' try {',
|
|
218
|
-
' Remove-Item -LiteralPath $fx_g -Recurse:' + (recurse ? '$true' : '$false') + ' -Force',
|
|
244
|
+
' Remove-Item -LiteralPath $fx_g -Recurse:' + (recurse ? '$true' : '$false') + ' -Force -ErrorAction Stop',
|
|
219
245
|
' if (' + (verbose ? '$true' : '$false') + ') { [Console]::Error.WriteLine("removed \'" + $fx_g + "\'") }',
|
|
220
246
|
' } catch { [Console]::Error.WriteLine("rm: cannot remove \'" + $fx_g + "\': Permission denied"); $script:fx_exit = 1 }',
|
|
221
247
|
' }',
|
|
@@ -234,11 +260,11 @@ const mkdir = (args) => {
|
|
|
234
260
|
"if ($fx_dirs.Count -eq 0) { [Console]::Error.WriteLine('mkdir: missing operand'); $script:fx_exit = 1 }",
|
|
235
261
|
'foreach ($fx_d in $fx_dirs) {',
|
|
236
262
|
' if (Test-Path -LiteralPath $fx_d) {',
|
|
237
|
-
' if (' + (parents ? '$false' : '$true') + ') { [Console]::Error.WriteLine("mkdir: cannot create directory \'" + $fx_d + "\': File exists"); $script:fx_exit = 1 }',
|
|
263
|
+
' if (' + (parents ? '$false' : '$true') + ' -or -not (Test-Path -LiteralPath $fx_d -PathType Container)) { [Console]::Error.WriteLine("mkdir: cannot create directory \'" + $fx_d + "\': File exists"); $script:fx_exit = 1 }',
|
|
238
264
|
' continue',
|
|
239
265
|
' }',
|
|
240
266
|
' try {',
|
|
241
|
-
' New-Item -ItemType Directory -Path $fx_d -Force:' + (parents ? '$true' : '$false') + ' | Out-Null',
|
|
267
|
+
' New-Item -ItemType Directory -Path $fx_d -Force:' + (parents ? '$true' : '$false') + ' -ErrorAction Stop | Out-Null',
|
|
242
268
|
' if (' + (verbose ? '$true' : '$false') + ') { [Console]::Error.WriteLine("mkdir: created directory \'" + $fx_d + "\'") }',
|
|
243
269
|
' } catch { [Console]::Error.WriteLine("mkdir: cannot create directory \'" + $fx_d + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
244
270
|
'}',
|
|
@@ -252,7 +278,7 @@ const rmdir = (args) => {
|
|
|
252
278
|
'foreach ($fx_d in $fx_dirs) {',
|
|
253
279
|
' if (-not (Test-Path -LiteralPath $fx_d -PathType Container)) { [Console]::Error.WriteLine("rmdir: failed to remove \'" + $fx_d + "\': No such file or directory"); $script:fx_exit = 1; continue }',
|
|
254
280
|
' if ((Get-ChildItem -LiteralPath $fx_d -Force).Count -gt 0) { [Console]::Error.WriteLine("rmdir: failed to remove \'" + $fx_d + "\': Directory not empty"); $script:fx_exit = 1; continue }',
|
|
255
|
-
' try { Remove-Item -LiteralPath $fx_d -Force } catch { [Console]::Error.WriteLine("rmdir: failed to remove \'" + $fx_d + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
281
|
+
' try { Remove-Item -LiteralPath $fx_d -Force -ErrorAction Stop } catch { [Console]::Error.WriteLine("rmdir: failed to remove \'" + $fx_d + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
256
282
|
'}',
|
|
257
283
|
].join('\n');
|
|
258
284
|
};
|
|
@@ -267,7 +293,7 @@ const touch = (args) => {
|
|
|
267
293
|
' try { (Get-Item -LiteralPath $fx_f).LastWriteTime = Get-Date } catch { [Console]::Error.WriteLine("touch: cannot touch \'" + $fx_f + "\': Permission denied"); $script:fx_exit = 1 }',
|
|
268
294
|
' } else {',
|
|
269
295
|
' if (' + (noCreate ? '$true' : '$false') + ') { continue }',
|
|
270
|
-
' try { New-Item -ItemType File -Path $fx_f | Out-Null }',
|
|
296
|
+
' try { New-Item -ItemType File -Path $fx_f -ErrorAction Stop | Out-Null }',
|
|
271
297
|
' catch { [Console]::Error.WriteLine("touch: cannot touch \'" + $fx_f + "\': No such file or directory"); $script:fx_exit = 1 }',
|
|
272
298
|
' }',
|
|
273
299
|
'}',
|
|
@@ -280,7 +306,7 @@ const mktemp = (args) => {
|
|
|
280
306
|
'try {',
|
|
281
307
|
' if (' + (dir ? '$true' : '$false') + ') {',
|
|
282
308
|
" $fx_p = Join-Path $env:TEMP ('fauxnix-' + ([IO.Path]::GetRandomFileName() -replace '\\.', ''))",
|
|
283
|
-
' New-Item -ItemType Directory -Path $fx_p | Out-Null',
|
|
309
|
+
' New-Item -ItemType Directory -Path $fx_p -ErrorAction Stop | Out-Null',
|
|
284
310
|
' } else {',
|
|
285
311
|
' $fx_p = [IO.Path]::GetTempFileName()',
|
|
286
312
|
' }',
|
|
@@ -302,7 +328,7 @@ const ln = (args) => {
|
|
|
302
328
|
"if ($fx_src -eq '' -or $fx_dst -eq '') { [Console]::Error.WriteLine('ln: missing file operand'); $script:fx_exit = 1 }",
|
|
303
329
|
'else {',
|
|
304
330
|
' if (Test-Path -LiteralPath $fx_dst -PathType Container) { $fx_dst = Join-Path $fx_dst (Split-Path $fx_src -Leaf) }',
|
|
305
|
-
' try { New-Item -ItemType ' + kind + ' -Path $fx_dst -Target $fx_src | Out-Null }',
|
|
331
|
+
' try { New-Item -ItemType ' + kind + ' -Path $fx_dst -Target $fx_src -ErrorAction Stop | Out-Null }',
|
|
306
332
|
' catch { [Console]::Error.WriteLine("ln: failed to create ' + label + ' \'" + $fx_dst + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
307
333
|
'}',
|
|
308
334
|
].join('\n');
|
|
@@ -341,8 +367,9 @@ const realpath = (args) => {
|
|
|
341
367
|
/* basename / dirname */
|
|
342
368
|
/* ------------------------------------------------------------------ */
|
|
343
369
|
const basename = (args) => {
|
|
370
|
+
const { operandWords } = parseWords(args);
|
|
344
371
|
return [
|
|
345
|
-
'$fx_ps = ' + argListExpr(
|
|
372
|
+
'$fx_ps = ' + argListExpr(operandWords, exprOfWord),
|
|
346
373
|
"if ($fx_ps.Count -eq 0) { [Console]::Error.WriteLine('basename: missing operand'); $script:fx_exit = 1 }",
|
|
347
374
|
'elseif ($fx_ps.Count -eq 2) {',
|
|
348
375
|
' $fx_p = [string]$fx_ps[0]',
|
|
@@ -361,8 +388,9 @@ const basename = (args) => {
|
|
|
361
388
|
].join('\n');
|
|
362
389
|
};
|
|
363
390
|
const dirname = (args) => {
|
|
391
|
+
const { operandWords } = parseWords(args);
|
|
364
392
|
return [
|
|
365
|
-
'$fx_ps = ' + argListExpr(
|
|
393
|
+
'$fx_ps = ' + argListExpr(operandWords, exprOfWord),
|
|
366
394
|
"if ($fx_ps.Count -eq 0) { [Console]::Error.WriteLine('dirname: missing operand'); $script:fx_exit = 1 }",
|
|
367
395
|
'foreach ($fx_p in $fx_ps) {',
|
|
368
396
|
" $fx_n = ($fx_p.TrimEnd('/')).TrimEnd('\\')",
|
|
@@ -376,12 +404,71 @@ const dirname = (args) => {
|
|
|
376
404
|
/* ------------------------------------------------------------------ */
|
|
377
405
|
/* stat / file */
|
|
378
406
|
/* ------------------------------------------------------------------ */
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
407
|
+
const STAT_DIRECTIVES = {
|
|
408
|
+
'%%': psStr('%'),
|
|
409
|
+
'%s': '[string]$fx_size',
|
|
410
|
+
'%n': '$fx_g',
|
|
411
|
+
'%F': '$fx_ft',
|
|
412
|
+
'%a': "$fx_mode.TrimStart('0')",
|
|
413
|
+
'%Y': '[string]$fx_epoch',
|
|
414
|
+
'%y': "$fx_it.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')",
|
|
415
|
+
};
|
|
416
|
+
/** Expand the existing stat directives once; inserted metadata is literal. */
|
|
417
|
+
function statFormatExpr(format) {
|
|
418
|
+
// Only odd slots are recognized directives. Other text, including unknown
|
|
419
|
+
// directives, stays quoted rather than being mistaken for a lookup key.
|
|
420
|
+
return format.split(/(%[%snFaYy])/)
|
|
421
|
+
.map((part, index) => index % 2 ? STAT_DIRECTIVES[part] : psStr(part))
|
|
422
|
+
.join(' + ');
|
|
423
|
+
}
|
|
424
|
+
/** GNU --printf escapes are scanned beside directives, never before them. */
|
|
425
|
+
function statPrintfFormat(format) {
|
|
426
|
+
const warnings = [];
|
|
427
|
+
let error;
|
|
428
|
+
const controls = { a: 7, b: 8, e: 27, f: 12, n: 10, r: 13, t: 9, v: 11 };
|
|
429
|
+
const expr = format.split(/(%[%snFaYy]|\\(?:[0-7]{1,3}|x[0-9a-fA-F]{1,2}|[\s\S]|$))/)
|
|
430
|
+
.map((part, index) => {
|
|
431
|
+
if (index % 2 === 0)
|
|
432
|
+
return psStr(part);
|
|
433
|
+
if (part.startsWith('%'))
|
|
434
|
+
return STAT_DIRECTIVES[part];
|
|
435
|
+
const escape = part.slice(1);
|
|
436
|
+
let byte;
|
|
437
|
+
if (/^[0-7]{1,3}$/.test(escape))
|
|
438
|
+
byte = parseInt(escape, 8) & 255;
|
|
439
|
+
else if (/^x[0-9a-fA-F]{1,2}$/.test(escape))
|
|
440
|
+
byte = parseInt(escape.slice(1), 16);
|
|
441
|
+
if (byte !== undefined) {
|
|
442
|
+
if (byte >= 128) {
|
|
443
|
+
error = 'stat: fauxnix: non-ASCII numeric byte escapes are not supported by the text output contract';
|
|
444
|
+
}
|
|
445
|
+
return '[string][char]' + byte;
|
|
446
|
+
}
|
|
447
|
+
if (Object.hasOwn(controls, escape))
|
|
448
|
+
return '[string][char]' + controls[escape];
|
|
449
|
+
if (escape === '\\')
|
|
450
|
+
return psStr('\\');
|
|
451
|
+
if (escape === '') {
|
|
452
|
+
warnings.push('stat: warning: backslash at end of format');
|
|
453
|
+
return psStr('\\');
|
|
454
|
+
}
|
|
455
|
+
warnings.push("stat: warning: unrecognized escape '\\" + escape + "'");
|
|
456
|
+
return psStr(escape);
|
|
457
|
+
}).join(' + ');
|
|
458
|
+
return { expr, warnings, error };
|
|
459
|
+
}
|
|
460
|
+
const stat = (args, ctx) => {
|
|
461
|
+
const { valueEntries, operandWords } = parseWords(args, ['c'], ['--format', '--printf']);
|
|
462
|
+
const formatOption = valueEntries.at(-1);
|
|
463
|
+
const fmt = formatOption?.value ?? null;
|
|
464
|
+
const printfMode = formatOption?.name === '--printf';
|
|
465
|
+
const format = printfMode ? statPrintfFormat(fmt ?? '') : { expr: statFormatExpr(fmt ?? ''), warnings: [] };
|
|
466
|
+
if (format.error)
|
|
467
|
+
return '[Console]::Error.WriteLine(' + psStr(format.error) + '); $script:fx_exit = 1';
|
|
382
468
|
return [
|
|
383
469
|
PS_FTIME_FN,
|
|
384
470
|
PS_GLOB_FN,
|
|
471
|
+
...(printfMode ? [PS_WRITE_FN, fxTermLine(ctx.position), '$fx_stat_out = New-Object System.Text.StringBuilder'] : []),
|
|
385
472
|
'$fx_files = ' + psArray(operandWords),
|
|
386
473
|
"if ($fx_files.Count -eq 0) { [Console]::Error.WriteLine('stat: missing operand'); $script:fx_exit = 1 }",
|
|
387
474
|
'foreach ($fx_f in $fx_files) {',
|
|
@@ -394,11 +481,11 @@ const stat = (args) => {
|
|
|
394
481
|
" { $fx_ft = 'symbolic link' }",
|
|
395
482
|
" $fx_ro = $fx_it.Attributes.ToString().Contains('ReadOnly')",
|
|
396
483
|
" $fx_mode = '0664'; if ($fx_it.PSIsContainer) { $fx_mode = '0775' } elseif ($fx_ro) { $fx_mode = '0444' }",
|
|
397
|
-
" $fx_epoch = [
|
|
398
|
-
' if (' + (fmt ? '$true' : '$false') + ') {',
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
' $fx_o',
|
|
484
|
+
" $fx_epoch = [long][math]::Floor(($fx_it.LastWriteTime.ToUniversalTime() - [datetime]'1970-01-01').TotalSeconds)",
|
|
485
|
+
' if (' + (fmt !== null ? '$true' : '$false') + ') {',
|
|
486
|
+
...format.warnings.map((warning) => ' [Console]::Error.WriteLine(' + psStr(warning) + ')'),
|
|
487
|
+
' $fx_o = ' + format.expr,
|
|
488
|
+
printfMode ? ' [void]$fx_stat_out.Append($fx_o)' : ' $fx_o',
|
|
402
489
|
' } else {',
|
|
403
490
|
' " File: " + $fx_g',
|
|
404
491
|
' (" Size: {0}`tBlocks: {1}`tIO Block: 4096 {2}" -f $fx_size, [math]::Ceiling($fx_size / 512), $fx_ft)',
|
|
@@ -408,6 +495,7 @@ const stat = (args) => {
|
|
|
408
495
|
' }',
|
|
409
496
|
' }',
|
|
410
497
|
'}',
|
|
498
|
+
...(printfMode ? ['fx-write ($fx_stat_out.ToString()) $fx_term'] : []),
|
|
411
499
|
].join('\n');
|
|
412
500
|
};
|
|
413
501
|
const file = (args) => {
|
|
@@ -838,8 +926,8 @@ const chmod = (args) => {
|
|
|
838
926
|
' if (-not (Test-Path -LiteralPath $fx_f)) { [Console]::Error.WriteLine("chmod: cannot access \'" + $fx_f + "\': No such file or directory"); $script:fx_exit = 1; continue }',
|
|
839
927
|
' try {',
|
|
840
928
|
' $fx_it = Get-Item -LiteralPath $fx_f -Force',
|
|
841
|
-
' if (' + (readOnly ===
|
|
842
|
-
' elseif (' + (readOnly ===
|
|
929
|
+
' if (' + (readOnly === true ? '$true' : '$false') + ') { $fx_it.Attributes = $fx_it.Attributes -bor [IO.FileAttributes]::ReadOnly }',
|
|
930
|
+
' elseif (' + (readOnly === false ? '$true' : '$false') + ') { $fx_it.Attributes = $fx_it.Attributes -band (-bnot [IO.FileAttributes]::ReadOnly) }',
|
|
843
931
|
' # symbolic modes (+x, u+w ...): Windows has no exec bit — accepted as a no-op',
|
|
844
932
|
' } catch { [Console]::Error.WriteLine("chmod: changing permissions of \'" + $fx_f + "\': " + $_.Exception.Message); $script:fx_exit = 1 }',
|
|
845
933
|
'}',
|
|
@@ -872,7 +960,7 @@ const diff = (args) => {
|
|
|
872
960
|
' $fx_lb = @((fx-read $fx_b) -split "`r?`n")',
|
|
873
961
|
" if ($fx_lb.Count -eq 1 -and $fx_lb[0] -eq '') { $fx_lb = @() }",
|
|
874
962
|
' $fx_same = ($fx_la.Count -eq $fx_lb.Count)',
|
|
875
|
-
' if ($fx_same) { for ($fx_i = 0; $fx_i -lt $fx_la.Count; $fx_i++) { if ($fx_la[$fx_i] -
|
|
963
|
+
' if ($fx_same) { for ($fx_i = 0; $fx_i -lt $fx_la.Count; $fx_i++) { if ($fx_la[$fx_i] -cne $fx_lb[$fx_i]) { $fx_same = $false; break } } }',
|
|
876
964
|
' if ($fx_same) { }',
|
|
877
965
|
' elseif (' + (brief ? '$true' : '$false') + ') { "Files " + $fx_a + " and " + $fx_b + " differ"; $script:fx_exit = 1 }',
|
|
878
966
|
' elseif ($fx_la.Count -gt 4000 -or $fx_lb.Count -gt 4000) { "Files " + $fx_a + " and " + $fx_b + " differ (too large for a fauxnix line diff)"; $script:fx_exit = 1 }',
|
|
@@ -882,14 +970,14 @@ const diff = (args) => {
|
|
|
882
970
|
" $fx_dp = New-Object 'int[]' (($fx_n + 1) * $fx_w)",
|
|
883
971
|
' for ($fx_i = $fx_n - 1; $fx_i -ge 0; $fx_i--) {',
|
|
884
972
|
' for ($fx_j = $fx_m - 1; $fx_j -ge 0; $fx_j--) {',
|
|
885
|
-
' if ($fx_la[$fx_i] -
|
|
973
|
+
' if ($fx_la[$fx_i] -ceq $fx_lb[$fx_j]) { $fx_dp[($fx_i * $fx_w) + $fx_j] = $fx_dp[(($fx_i + 1) * $fx_w) + ($fx_j + 1)] + 1 }',
|
|
886
974
|
' else { $fx_r = $fx_dp[(($fx_i + 1) * $fx_w) + $fx_j]; $fx_d2 = $fx_dp[($fx_i * $fx_w) + ($fx_j + 1)]; if ($fx_r -ge $fx_d2) { $fx_dp[($fx_i * $fx_w) + $fx_j] = $fx_r } else { $fx_dp[($fx_i * $fx_w) + $fx_j] = $fx_d2 } }',
|
|
887
975
|
' }',
|
|
888
976
|
' }',
|
|
889
977
|
" $fx_ops = @() # tuples: @('<op>', text, aIndex, bIndex)",
|
|
890
978
|
' $fx_i = 0; $fx_j = 0',
|
|
891
979
|
' while ($fx_i -lt $fx_n -and $fx_j -lt $fx_m) {',
|
|
892
|
-
" if ($fx_la[$fx_i] -
|
|
980
|
+
" if ($fx_la[$fx_i] -ceq $fx_lb[$fx_j]) { $fx_ops += ,@('=', $fx_la[$fx_i], $fx_i, $fx_j); $fx_i++; $fx_j++ }",
|
|
893
981
|
" elseif ($fx_dp[(($fx_i + 1) * $fx_w) + $fx_j] -ge $fx_dp[($fx_i * $fx_w) + ($fx_j + 1)]) { $fx_ops += ,@('-', $fx_la[$fx_i], $fx_i, $fx_j); $fx_i++ }",
|
|
894
982
|
" else { $fx_ops += ,@('+', $fx_lb[$fx_j], $fx_i, $fx_j); $fx_j++ }",
|
|
895
983
|
' }',
|
|
@@ -907,8 +995,8 @@ const diff = (args) => {
|
|
|
907
995
|
' if ($fx_del.Count -gt 0) { $fx_a1 = $fx_del[0][1] + 1; $fx_a2 = $fx_del[$fx_del.Count - 1][1] + 1 }',
|
|
908
996
|
' if ($fx_add.Count -gt 0) { $fx_b1 = $fx_add[0][1] + 1; $fx_b2 = $fx_add[$fx_add.Count - 1][1] + 1 }',
|
|
909
997
|
' $fx_range = \'\'',
|
|
910
|
-
" if ($fx_del.Count -eq 0) { $fx_range = ([string]$
|
|
911
|
-
" elseif ($fx_add.Count -eq 0) { $fx_range = (fx-dr $fx_a1 $fx_a2) + 'd' + ([string]$
|
|
998
|
+
" if ($fx_del.Count -eq 0) { $fx_range = ([string]$fx_ops[$fx_start][2]) + 'a' + (fx-dr $fx_b1 $fx_b2) }",
|
|
999
|
+
" elseif ($fx_add.Count -eq 0) { $fx_range = (fx-dr $fx_a1 $fx_a2) + 'd' + ([string]$fx_ops[$fx_start][3]) }",
|
|
912
1000
|
" else { $fx_range = (fx-dr $fx_a1 $fx_a2) + 'c' + (fx-dr $fx_b1 $fx_b2) }",
|
|
913
1001
|
' $fx_range',
|
|
914
1002
|
" foreach ($fx_d in $fx_del) { '< ' + $fx_d[0] }",
|
|
@@ -939,7 +1027,8 @@ function fileSpec(names, effects, options, handler) {
|
|
|
939
1027
|
}
|
|
940
1028
|
const INTERACTIVE = { reason: 'interactive prompt' };
|
|
941
1029
|
/** Destructive file commands migrated first (#130). Unspec'd handlers stay unchecked.
|
|
942
|
-
* cp
|
|
1030
|
+
* cp `-f` is always-on overwrite. mv `-f` retains safe same-volume regular-file
|
|
1031
|
+
* replacement and never overrides preservation limits or permissions. */
|
|
943
1032
|
export const specs = [
|
|
944
1033
|
fileSpec(['cp'], ['read', 'write'], [
|
|
945
1034
|
opt('r', undefined),
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { psStr } from '../registry.js';
|
|
2
|
+
import { nodeEngineRange } from '../runtime-support.js';
|
|
3
|
+
/** Trusted program, no user text interpolation. It only reads input and emits bytes. */
|
|
4
|
+
export const GZIP_DECODER_SOURCE = String.raw `
|
|
5
|
+
const { createReadStream } = require('node:fs');
|
|
6
|
+
const { createGunzip } = require('node:zlib');
|
|
7
|
+
const { Writable } = require('node:stream');
|
|
8
|
+
const { pipeline } = require('node:stream/promises');
|
|
9
|
+
(async () => {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
let finished = false;
|
|
12
|
+
let stopping = false;
|
|
13
|
+
const stopDecoder = () => {
|
|
14
|
+
if (finished || stopping) return;
|
|
15
|
+
stopping = true;
|
|
16
|
+
controller.abort();
|
|
17
|
+
// A stalled output pipe can retain native writes after stream destruction.
|
|
18
|
+
// The owner has gone, so bound only this read-only decoder's shutdown.
|
|
19
|
+
setTimeout(() => process.exit(1), 1000).unref();
|
|
20
|
+
};
|
|
21
|
+
const leased = process.argv[4] === 'lease';
|
|
22
|
+
if (leased) {
|
|
23
|
+
// PowerShell keeps this private input pipe open without writing to it.
|
|
24
|
+
// EOF is an ownership signal, not compressed input or a host RPC message.
|
|
25
|
+
process.stdin.on('end', stopDecoder);
|
|
26
|
+
process.stdin.on('error', stopDecoder);
|
|
27
|
+
process.stdin.resume();
|
|
28
|
+
}
|
|
29
|
+
const parent = Number(process.argv[3]);
|
|
30
|
+
const watcher = Number.isSafeInteger(parent) && parent > 0 ? setInterval(() => {
|
|
31
|
+
try { process.kill(parent, 0); }
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error.code === 'ESRCH') {
|
|
34
|
+
clearInterval(watcher);
|
|
35
|
+
stopDecoder();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, 250) : undefined;
|
|
39
|
+
watcher?.unref();
|
|
40
|
+
process.stderr.on('error', () => {});
|
|
41
|
+
try {
|
|
42
|
+
const minimum = ${JSON.stringify(nodeEngineRange.slice(2).split('.').map(Number))};
|
|
43
|
+
const actual = process.versions.node.split('.').map(Number);
|
|
44
|
+
let supported = actual.every(Number.isSafeInteger);
|
|
45
|
+
for (let i = 0; supported && i < 3; i++) {
|
|
46
|
+
if (actual[i] !== minimum[i]) { supported = actual[i] > minimum[i]; break; }
|
|
47
|
+
}
|
|
48
|
+
if (!supported) throw new Error('Node.js ${nodeEngineRange} is required for strict gzip decoding');
|
|
49
|
+
const path = Buffer.from(process.argv[1], 'base64').toString('utf8');
|
|
50
|
+
const mode = process.argv[2];
|
|
51
|
+
if (mode !== 'test' && mode !== 'stream') throw new Error('invalid decoder mode');
|
|
52
|
+
const sink = mode === 'test' ? new Writable({ write(chunk, encoding, next) { next(); } }) : process.stdout;
|
|
53
|
+
await pipeline(createReadStream(path), createGunzip(), sink, { signal: controller.signal });
|
|
54
|
+
} catch (error) {
|
|
55
|
+
process.stderr.write('gzip decoder: ' + String(error.message).slice(0, 2048) + '\n');
|
|
56
|
+
process.exitCode = error.code === 'Z_DATA_ERROR' || error.code === 'Z_BUF_ERROR' ? 2 : 1;
|
|
57
|
+
} finally {
|
|
58
|
+
finished = true;
|
|
59
|
+
if (watcher) clearInterval(watcher);
|
|
60
|
+
if (leased) process.stdin.destroy();
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
`;
|
|
64
|
+
export function gzipNodeFunctions(pure) {
|
|
65
|
+
const program = Buffer.from(GZIP_DECODER_SOURCE, 'utf8').toString('base64');
|
|
66
|
+
const prefix = `-e "eval(Buffer.from('${program}','base64').toString())" -- `;
|
|
67
|
+
const node = pure
|
|
68
|
+
? "(Get-Command node.exe -CommandType Application -ErrorAction Stop).Source"
|
|
69
|
+
: psStr(process.execPath);
|
|
70
|
+
return [
|
|
71
|
+
'function fx-gz-decode($src, $isBytes, $sink, $testOnly) {',
|
|
72
|
+
' $fx_raw = $null; $fx_process = $null',
|
|
73
|
+
' try {',
|
|
74
|
+
' if ($isBytes) {',
|
|
75
|
+
" $fx_inputPath = [IO.Path]::Combine([IO.Path]::GetTempPath(), 'fauxnix-gzip-input-' + [Guid]::NewGuid().ToString('N') + '.tmp')",
|
|
76
|
+
' $fx_raw = New-Object IO.FileStream($fx_inputPath, [IO.FileMode]::CreateNew, [IO.FileAccess]::ReadWrite, ([IO.FileShare]::Read -bor [IO.FileShare]::Delete), 65536, [IO.FileOptions]::DeleteOnClose)',
|
|
77
|
+
' $fx_raw.Write($src, 0, $src.Length); $fx_raw.Flush()',
|
|
78
|
+
' } else {',
|
|
79
|
+
' $fx_inputPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($src)',
|
|
80
|
+
' $fx_raw = [IO.File]::Open($fx_inputPath, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::Read)',
|
|
81
|
+
' }',
|
|
82
|
+
' $fx_psi = New-Object Diagnostics.ProcessStartInfo',
|
|
83
|
+
' $fx_psi.FileName = ' + node,
|
|
84
|
+
' $fx_psi.UseShellExecute = $false; $fx_psi.CreateNoWindow = $true',
|
|
85
|
+
' $fx_psi.RedirectStandardOutput = $true; $fx_psi.RedirectStandardError = $true',
|
|
86
|
+
' $fx_psi.RedirectStandardInput = $true',
|
|
87
|
+
' $fx_psi.StandardErrorEncoding = New-Object Text.UTF8Encoding($false)',
|
|
88
|
+
" $fx_mode = 'stream'; if ($testOnly) { $fx_mode = 'test' }",
|
|
89
|
+
' $fx_psi.Arguments = ' + psStr(prefix) + " + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($fx_inputPath)) + ' ' + $fx_mode + ' ' + $PID + ' lease'",
|
|
90
|
+
' $fx_process = New-Object Diagnostics.Process',
|
|
91
|
+
' $fx_process.StartInfo = $fx_psi',
|
|
92
|
+
" if (-not $fx_process.Start()) { throw 'unable to start the Node gzip decoder' }",
|
|
93
|
+
' $fx_errors = $fx_process.StandardError.ReadToEndAsync()',
|
|
94
|
+
// Binary stdout never passes through PowerShell's text pipeline.
|
|
95
|
+
' try { $fx_process.StandardOutput.BaseStream.CopyTo($sink, 65536) }',
|
|
96
|
+
" catch { throw ('gzip output transfer failed: ' + $_.Exception.Message) }",
|
|
97
|
+
' $fx_process.WaitForExit()',
|
|
98
|
+
' $fx_errorText = $fx_errors.Result',
|
|
99
|
+
" if ($fx_process.ExitCode -eq 2) { throw ('not in gzip format: strict gzip decode failed: ' + $fx_errorText.Trim()) }",
|
|
100
|
+
" if ($fx_process.ExitCode -ne 0) { throw ('gzip decoder failed: ' + $fx_errorText.Trim()) }",
|
|
101
|
+
' } finally {',
|
|
102
|
+
' if ($null -ne $fx_process) {',
|
|
103
|
+
' try { if (-not $fx_process.HasExited) { $fx_process.Kill(); [void]$fx_process.WaitForExit(5000) } } catch {}',
|
|
104
|
+
' $fx_process.Dispose()',
|
|
105
|
+
' }',
|
|
106
|
+
' if ($null -ne $fx_raw) { $fx_raw.Dispose() }',
|
|
107
|
+
' }',
|
|
108
|
+
'}',
|
|
109
|
+
'function fx-gz-open($src, $isBytes) {',
|
|
110
|
+
" $fx_path = [IO.Path]::Combine([IO.Path]::GetTempPath(), 'fauxnix-gzip-stdout-' + [Guid]::NewGuid().ToString('N') + '.tmp')",
|
|
111
|
+
' $fx_decoded = New-Object IO.FileStream($fx_path, [IO.FileMode]::CreateNew, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None, 65536, [IO.FileOptions]::DeleteOnClose)',
|
|
112
|
+
' try {',
|
|
113
|
+
' fx-gz-decode $src $isBytes $fx_decoded $false',
|
|
114
|
+
' $fx_decoded.Position = 0',
|
|
115
|
+
' return $fx_decoded',
|
|
116
|
+
' } catch { $fx_decoded.Dispose(); throw }',
|
|
117
|
+
'}',
|
|
118
|
+
].join('\n');
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PS_MOVE_REPLACE_FN: string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { psStr } from '../registry.js';
|
|
2
|
+
// No user data is interpolated into C#. Paths are ordinary method arguments.
|
|
3
|
+
// Windows 8+ FILE_ID_INFO retains ReFS's full 128-bit identity; unsupported
|
|
4
|
+
// filesystems fail closed rather than falling back to a partial identifier.
|
|
5
|
+
const nativeSource = String.raw `
|
|
6
|
+
using System;
|
|
7
|
+
using System.ComponentModel;
|
|
8
|
+
using System.IO;
|
|
9
|
+
using System.Runtime.InteropServices;
|
|
10
|
+
using Microsoft.Win32.SafeHandles;
|
|
11
|
+
namespace Fauxnix {
|
|
12
|
+
public static class FileMoveV1 {
|
|
13
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
14
|
+
private struct FileIdInfo {
|
|
15
|
+
public ulong Volume;
|
|
16
|
+
public ulong Low;
|
|
17
|
+
public ulong High;
|
|
18
|
+
}
|
|
19
|
+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
|
|
20
|
+
private static extern SafeFileHandle CreateFileW(string path, uint access,
|
|
21
|
+
uint share, IntPtr security, uint creation, uint flags, IntPtr template);
|
|
22
|
+
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
|
|
23
|
+
[return: MarshalAs(UnmanagedType.Bool)]
|
|
24
|
+
private static extern bool GetFileInformationByHandleEx(SafeFileHandle handle,
|
|
25
|
+
int infoClass, out FileIdInfo information, uint size);
|
|
26
|
+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
|
|
27
|
+
[return: MarshalAs(UnmanagedType.Bool)]
|
|
28
|
+
private static extern bool MoveFileExW(string source, string destination, uint flags);
|
|
29
|
+
|
|
30
|
+
private static SafeFileHandle OpenIdentity(string path) {
|
|
31
|
+
// Metadata-only access, read/write/delete sharing, OPEN_EXISTING,
|
|
32
|
+
// FILE_FLAG_OPEN_REPARSE_POINT: never create or modify the inspected file.
|
|
33
|
+
SafeFileHandle handle = CreateFileW(path, 0, 7, IntPtr.Zero, 3, 0x00200000, IntPtr.Zero);
|
|
34
|
+
if (handle.IsInvalid) {
|
|
35
|
+
int error = Marshal.GetLastWin32Error();
|
|
36
|
+
handle.Dispose();
|
|
37
|
+
throw new Win32Exception(error);
|
|
38
|
+
}
|
|
39
|
+
return handle;
|
|
40
|
+
}
|
|
41
|
+
private static FileIdInfo Identity(SafeFileHandle handle) {
|
|
42
|
+
FileIdInfo info;
|
|
43
|
+
if (!GetFileInformationByHandleEx(handle, 18, out info, (uint)Marshal.SizeOf(typeof(FileIdInfo))))
|
|
44
|
+
throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
45
|
+
return info;
|
|
46
|
+
}
|
|
47
|
+
public static void ReplaceRegular(string source, string destination) {
|
|
48
|
+
FileAttributes disallowed = FileAttributes.Directory | FileAttributes.ReparsePoint;
|
|
49
|
+
if ((File.GetAttributes(source) & disallowed) != 0 ||
|
|
50
|
+
(File.GetAttributes(destination) & disallowed) != 0)
|
|
51
|
+
throw new IOException("replacement of directories or reparse points is unsupported");
|
|
52
|
+
using (SafeFileHandle sourceHandle = OpenIdentity(source))
|
|
53
|
+
using (SafeFileHandle destinationHandle = OpenIdentity(destination)) {
|
|
54
|
+
FileIdInfo a = Identity(sourceHandle);
|
|
55
|
+
FileIdInfo b = Identity(destinationHandle);
|
|
56
|
+
if (a.Volume != b.Volume)
|
|
57
|
+
throw new IOException("cross-volume replacement is unsupported; both files retained");
|
|
58
|
+
if (a.Low == b.Low && a.High == b.High)
|
|
59
|
+
throw new IOException("source and destination are the same file");
|
|
60
|
+
}
|
|
61
|
+
// Close identity handles before replacement: an open destination can
|
|
62
|
+
// prevent Windows replacement even when opened with delete sharing.
|
|
63
|
+
// This preflight is deliberately not represented as a namespace lock.
|
|
64
|
+
// MOVEFILE_REPLACE_EXISTING only. No COPY_ALLOWED/predelete fallback.
|
|
65
|
+
if (!MoveFileExW(source, destination, 1)) {
|
|
66
|
+
int error = Marshal.GetLastWin32Error();
|
|
67
|
+
if (error == 17)
|
|
68
|
+
throw new IOException("cross-volume replacement is unsupported; both files retained");
|
|
69
|
+
throw new Win32Exception(error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
export const PS_MOVE_REPLACE_FN = [
|
|
76
|
+
'function fx-move-replace-file($source, $destination) {',
|
|
77
|
+
" if (-not ('Fauxnix.FileMoveV1' -as [type])) {",
|
|
78
|
+
' Add-Type -TypeDefinition ' + psStr(nativeSource) + ' -ErrorAction Stop',
|
|
79
|
+
' }',
|
|
80
|
+
' [Fauxnix.FileMoveV1]::ReplaceRegular($source, $destination)',
|
|
81
|
+
'}',
|
|
82
|
+
].join('\n');
|