1
>
/*---------------------------------------------------------------------------------------------
pfs.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as fs from 'fs';
7
>
import { tmpdir } from 'os';
8
>
import { promisify } from 'util';
9
>
import { ResourceQueue, timeout } from '../common/async.js';
10
>
import { isEqualOrParent, isRootOrDriveLetter, randomPath } from '../common/extpath.js';
11
>
import { normalizeNFC } from '../common/normalization.js';
12
>
import { basename, dirname, join, normalize, sep } from '../common/path.js';
13
>
import { isLinux, isMacintosh, isWindows } from '../common/platform.js';
14
>
import { extUriBiasedIgnorePathCase } from '../common/resources.js';
15
>
import { URI } from '../common/uri.js';
16
>
import { CancellationToken } from '../common/cancellation.js';
17
>
import { rtrim } from '../common/strings.js';
18
>
19
>
//#region rimraf
20
>
21
>
export enum RimRafMode {
22
>
23
>
/**
24
>
* Slow version that unlinks each file and folder.
25
>
*/
26
>
UNLINK,
27
>
28
>
/**
29
>
* Fast version that first moves the file/folder
30
>
* into a temp directory and then deletes that
31
>
* without waiting for it.
32
>
*/
33
>
MOVE
34
>
}
35
>
36
>
/**
37
>
* Allows to delete the provided path (either file or folder) recursively
38
>
* with the options:
39
>
* - `UNLINK`: direct removal from disk
40
>
* - `MOVE`: faster variant that first moves the target to temp dir and then
41
>
* deletes it in the background without waiting for that to finish.
42
>
* the optional `moveToPath` allows to override where to rename the
43
>
* path to before deleting it.
44
>
*/
45
>
async function rimraf(path: string, mode: RimRafMode.UNLINK): Promise<void>;
46
>
async function rimraf(path: string, mode: RimRafMode.MOVE, moveToPath?: string): Promise<void>;
47
>
async function rimraf(path: string, mode?: RimRafMode, moveToPath?: string): Promise<void>;
48
async function rimraf(path: string, mode = RimRafMode.UNLINK, moveToPath?: string): Promise<void> {
49
if (isRootOrDriveLetter(path)) {