forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdiskFileSystemProvider.ts
49 lines (39 loc) · 1.9 KB
/
diskFileSystemProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { basename } from 'vs/base/common/path';
import { isWindows } from 'vs/base/common/platform';
import { localize } from 'vs/nls';
import { FileDeleteOptions, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { DiskFileSystemProvider as NodeDiskFileSystemProvider, IDiskFileSystemProviderOptions } from 'vs/platform/files/node/diskFileSystemProvider';
import { ILogService } from 'vs/platform/log/common/log';
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
export class DiskFileSystemProvider extends NodeDiskFileSystemProvider {
constructor(
logService: ILogService,
private readonly nativeHostService: INativeHostService,
options?: IDiskFileSystemProviderOptions
) {
super(logService, options);
}
//#region Enable Trash capability as only extension to the node.js file provider
override get capabilities(): FileSystemProviderCapabilities {
if (!this._capabilities) {
this._capabilities = super.capabilities | FileSystemProviderCapabilities.Trash;
}
return this._capabilities;
}
protected override async doDelete(filePath: string, opts: FileDeleteOptions): Promise<void> {
if (!opts.useTrash) {
return super.doDelete(filePath, opts);
}
try {
await this.nativeHostService.moveItemToTrash(filePath);
} catch (error) {
this.logService.error(error);
throw new Error(isWindows ? localize('binFailed', "Failed to move '{0}' to the recycle bin", basename(filePath)) : localize('trashFailed', "Failed to move '{0}' to the trash", basename(filePath)));
}
}
//#endregion
}