@codingame/monaco-vscode-working-copy-service-override 4.0.0 → 4.1.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/package.json +3 -3
- package/workingCopy.js +2 -2
- package/external/tslib/tslib.es6.js +0 -11
- package/vscode/src/vs/workbench/services/workingCopy/browser/workingCopyBackupService.js +0 -25
- package/vscode/src/vs/workbench/services/workingCopy/browser/workingCopyBackupTracker.js +0 -45
- package/vscode/src/vs/workbench/services/workingCopy/browser/workingCopyHistoryService.js +0 -30
- package/vscode/src/vs/workbench/services/workingCopy/common/workingCopyBackupService.js +0 -454
- package/vscode/src/vs/workbench/services/workingCopy/common/workingCopyBackupTracker.js +0 -255
- package/vscode/src/vs/workbench/services/workingCopy/common/workingCopyHistoryService.js +0 -618
- package/vscode/src/vs/workbench/services/workingCopy/common/workingCopyHistoryTracker.js +0 -164
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-working-copy-service-override",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"module": "index.js",
|
|
19
19
|
"types": "index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"vscode": "npm:@codingame/monaco-vscode-api@4.
|
|
22
|
-
"@codingame/monaco-vscode-files-service-override": "4.
|
|
21
|
+
"vscode": "npm:@codingame/monaco-vscode-api@4.1.0",
|
|
22
|
+
"@codingame/monaco-vscode-files-service-override": "4.1.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/workingCopy.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
|
|
2
|
-
import { BrowserWorkingCopyBackupService } from '
|
|
2
|
+
import { BrowserWorkingCopyBackupService } from 'vscode/vscode/vs/workbench/services/workingCopy/browser/workingCopyBackupService';
|
|
3
3
|
import { IWorkingCopyBackupService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyBackup';
|
|
4
4
|
import { IWorkingCopyService, WorkingCopyService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyService';
|
|
5
5
|
import { IWorkingCopyEditorService, WorkingCopyEditorService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyEditorService';
|
|
6
6
|
import { IWorkingCopyHistoryService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyHistory';
|
|
7
|
-
import { BrowserWorkingCopyHistoryService } from '
|
|
7
|
+
import { BrowserWorkingCopyHistoryService } from 'vscode/vscode/vs/workbench/services/workingCopy/browser/workingCopyHistoryService';
|
|
8
8
|
import getServiceOverride$1 from '@codingame/monaco-vscode-files-service-override';
|
|
9
9
|
|
|
10
10
|
function getServiceOverride() {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
function __decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function __param(paramIndex, decorator) {
|
|
8
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { __decorate, __param };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
|
|
3
|
-
import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
|
|
4
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
5
|
-
import { WorkingCopyBackupService } from '../common/workingCopyBackupService.js';
|
|
6
|
-
import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
7
|
-
import { joinPath } from 'vscode/vscode/vs/base/common/resources';
|
|
8
|
-
import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace';
|
|
9
|
-
import { registerWorkbenchContribution2 } from 'vscode/vscode/vs/workbench/common/contributions';
|
|
10
|
-
import { BrowserWorkingCopyBackupTracker } from './workingCopyBackupTracker.js';
|
|
11
|
-
|
|
12
|
-
let BrowserWorkingCopyBackupService = class BrowserWorkingCopyBackupService extends WorkingCopyBackupService {
|
|
13
|
-
constructor(contextService, environmentService, fileService, logService) {
|
|
14
|
-
super(joinPath(environmentService.userRoamingDataHome, 'Backups', contextService.getWorkspace().id), fileService, logService);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
BrowserWorkingCopyBackupService = ( __decorate([
|
|
18
|
-
( __param(0, IWorkspaceContextService)),
|
|
19
|
-
( __param(1, IWorkbenchEnvironmentService)),
|
|
20
|
-
( __param(2, IFileService)),
|
|
21
|
-
( __param(3, ILogService))
|
|
22
|
-
], BrowserWorkingCopyBackupService));
|
|
23
|
-
registerWorkbenchContribution2(BrowserWorkingCopyBackupTracker.ID, BrowserWorkingCopyBackupTracker, 1 );
|
|
24
|
-
|
|
25
|
-
export { BrowserWorkingCopyBackupService };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { IWorkingCopyBackupService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyBackup';
|
|
3
|
-
import { IFilesConfigurationService } from 'vscode/vscode/vs/workbench/services/filesConfiguration/common/filesConfigurationService';
|
|
4
|
-
import { IWorkingCopyService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyService';
|
|
5
|
-
import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
|
|
6
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
7
|
-
import { WorkingCopyBackupTracker } from '../common/workingCopyBackupTracker.js';
|
|
8
|
-
import { IWorkingCopyEditorService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyEditorService';
|
|
9
|
-
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
|
|
10
|
-
import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService';
|
|
11
|
-
|
|
12
|
-
let BrowserWorkingCopyBackupTracker = class BrowserWorkingCopyBackupTracker extends WorkingCopyBackupTracker {
|
|
13
|
-
static { this.ID = 'workbench.contrib.browserWorkingCopyBackupTracker'; }
|
|
14
|
-
constructor(workingCopyBackupService, filesConfigurationService, workingCopyService, lifecycleService, logService, workingCopyEditorService, editorService, editorGroupService) {
|
|
15
|
-
super(workingCopyBackupService, workingCopyService, logService, lifecycleService, filesConfigurationService, workingCopyEditorService, editorService, editorGroupService);
|
|
16
|
-
}
|
|
17
|
-
onFinalBeforeShutdown(reason) {
|
|
18
|
-
const modifiedWorkingCopies = this.workingCopyService.modifiedWorkingCopies;
|
|
19
|
-
if (!modifiedWorkingCopies.length) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (!this.filesConfigurationService.isHotExitEnabled) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
for (const modifiedWorkingCopy of modifiedWorkingCopies) {
|
|
26
|
-
if (!this.workingCopyBackupService.hasBackupSync(modifiedWorkingCopy, this.getContentVersion(modifiedWorkingCopy))) {
|
|
27
|
-
this.logService.warn('Unload veto: pending backups');
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
BrowserWorkingCopyBackupTracker = ( __decorate([
|
|
35
|
-
( __param(0, IWorkingCopyBackupService)),
|
|
36
|
-
( __param(1, IFilesConfigurationService)),
|
|
37
|
-
( __param(2, IWorkingCopyService)),
|
|
38
|
-
( __param(3, ILifecycleService)),
|
|
39
|
-
( __param(4, ILogService)),
|
|
40
|
-
( __param(5, IWorkingCopyEditorService)),
|
|
41
|
-
( __param(6, IEditorService)),
|
|
42
|
-
( __param(7, IEditorGroupsService))
|
|
43
|
-
], BrowserWorkingCopyBackupTracker));
|
|
44
|
-
|
|
45
|
-
export { BrowserWorkingCopyBackupTracker };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
|
|
3
|
-
import { IRemoteAgentService } from 'vscode/vscode/vs/workbench/services/remote/common/remoteAgentService';
|
|
4
|
-
import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
|
|
5
|
-
import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity';
|
|
6
|
-
import { ILabelService } from 'vscode/vscode/vs/platform/label/common/label';
|
|
7
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
8
|
-
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
9
|
-
import { WorkingCopyHistoryService } from '../common/workingCopyHistoryService.js';
|
|
10
|
-
import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
11
|
-
|
|
12
|
-
let BrowserWorkingCopyHistoryService = class BrowserWorkingCopyHistoryService extends WorkingCopyHistoryService {
|
|
13
|
-
constructor(fileService, remoteAgentService, environmentService, uriIdentityService, labelService, logService, configurationService) {
|
|
14
|
-
super(fileService, remoteAgentService, environmentService, uriIdentityService, labelService, logService, configurationService);
|
|
15
|
-
}
|
|
16
|
-
getModelOptions() {
|
|
17
|
-
return { flushOnChange: true };
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
BrowserWorkingCopyHistoryService = ( __decorate([
|
|
21
|
-
( __param(0, IFileService)),
|
|
22
|
-
( __param(1, IRemoteAgentService)),
|
|
23
|
-
( __param(2, IWorkbenchEnvironmentService)),
|
|
24
|
-
( __param(3, IUriIdentityService)),
|
|
25
|
-
( __param(4, ILabelService)),
|
|
26
|
-
( __param(5, ILogService)),
|
|
27
|
-
( __param(6, IConfigurationService))
|
|
28
|
-
], BrowserWorkingCopyHistoryService));
|
|
29
|
-
|
|
30
|
-
export { BrowserWorkingCopyHistoryService };
|
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { joinPath } from 'vscode/vscode/vs/base/common/resources';
|
|
3
|
-
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
4
|
-
import { coalesce } from 'vscode/vscode/vs/base/common/arrays';
|
|
5
|
-
import { deepClone, equals } from 'vscode/vscode/vs/base/common/objects';
|
|
6
|
-
import { ResourceQueue, Promises } from 'vscode/vscode/vs/base/common/async';
|
|
7
|
-
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
|
|
8
|
-
import { ResourceMap } from 'vscode/vscode/vs/base/common/map';
|
|
9
|
-
import { isReadableStream, peekStream } from 'vscode/vscode/vs/base/common/stream';
|
|
10
|
-
import { VSBuffer, prefixedBufferStream, prefixedBufferReadable, bufferToStream, streamToBuffer, readableToBuffer } from 'vscode/vscode/vs/base/common/buffer';
|
|
11
|
-
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
12
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
13
|
-
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
14
|
-
import { hash } from 'vscode/vscode/vs/base/common/hash';
|
|
15
|
-
import { isEmptyObject } from 'vscode/vscode/vs/base/common/types';
|
|
16
|
-
import { NO_TYPE_ID } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopy';
|
|
17
|
-
|
|
18
|
-
var WorkingCopyBackupServiceImpl_1;
|
|
19
|
-
class WorkingCopyBackupsModel {
|
|
20
|
-
static async create(backupRoot, fileService) {
|
|
21
|
-
const model = ( new WorkingCopyBackupsModel(backupRoot, fileService));
|
|
22
|
-
await model.resolve();
|
|
23
|
-
return model;
|
|
24
|
-
}
|
|
25
|
-
constructor(backupRoot, fileService) {
|
|
26
|
-
this.backupRoot = backupRoot;
|
|
27
|
-
this.fileService = fileService;
|
|
28
|
-
this.cache = ( new ResourceMap());
|
|
29
|
-
}
|
|
30
|
-
async resolve() {
|
|
31
|
-
try {
|
|
32
|
-
const backupRootStat = await this.fileService.resolve(this.backupRoot);
|
|
33
|
-
if (backupRootStat.children) {
|
|
34
|
-
await Promises.settled(( backupRootStat.children
|
|
35
|
-
.filter(child => child.isDirectory)
|
|
36
|
-
.map(async (backupSchemaFolder) => {
|
|
37
|
-
const backupSchemaFolderStat = await this.fileService.resolve(backupSchemaFolder.resource);
|
|
38
|
-
if (backupSchemaFolderStat.children) {
|
|
39
|
-
for (const backupForSchema of backupSchemaFolderStat.children) {
|
|
40
|
-
if (!backupForSchema.isDirectory) {
|
|
41
|
-
this.add(backupForSchema.resource);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
})));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
add(resource, versionId = 0, meta) {
|
|
52
|
-
this.cache.set(resource, {
|
|
53
|
-
versionId,
|
|
54
|
-
meta: deepClone(meta)
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
update(resource, meta) {
|
|
58
|
-
const entry = this.cache.get(resource);
|
|
59
|
-
if (entry) {
|
|
60
|
-
entry.meta = deepClone(meta);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
count() {
|
|
64
|
-
return this.cache.size;
|
|
65
|
-
}
|
|
66
|
-
has(resource, versionId, meta) {
|
|
67
|
-
const entry = this.cache.get(resource);
|
|
68
|
-
if (!entry) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
if (typeof versionId === 'number' && versionId !== entry.versionId) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (meta && !equals(meta, entry.meta)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
get() {
|
|
80
|
-
return Array.from(( this.cache.keys()));
|
|
81
|
-
}
|
|
82
|
-
remove(resource) {
|
|
83
|
-
this.cache.delete(resource);
|
|
84
|
-
}
|
|
85
|
-
clear() {
|
|
86
|
-
this.cache.clear();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
let WorkingCopyBackupService = class WorkingCopyBackupService extends Disposable {
|
|
90
|
-
constructor(backupWorkspaceHome, fileService, logService) {
|
|
91
|
-
super();
|
|
92
|
-
this.fileService = fileService;
|
|
93
|
-
this.logService = logService;
|
|
94
|
-
this.impl = this._register(this.initialize(backupWorkspaceHome));
|
|
95
|
-
}
|
|
96
|
-
initialize(backupWorkspaceHome) {
|
|
97
|
-
if (backupWorkspaceHome) {
|
|
98
|
-
return ( new WorkingCopyBackupServiceImpl(backupWorkspaceHome, this.fileService, this.logService));
|
|
99
|
-
}
|
|
100
|
-
return ( new InMemoryWorkingCopyBackupService());
|
|
101
|
-
}
|
|
102
|
-
reinitialize(backupWorkspaceHome) {
|
|
103
|
-
if (this.impl instanceof WorkingCopyBackupServiceImpl) {
|
|
104
|
-
if (backupWorkspaceHome) {
|
|
105
|
-
this.impl.initialize(backupWorkspaceHome);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
this.impl = ( new InMemoryWorkingCopyBackupService());
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
hasBackups() {
|
|
113
|
-
return this.impl.hasBackups();
|
|
114
|
-
}
|
|
115
|
-
hasBackupSync(identifier, versionId, meta) {
|
|
116
|
-
return this.impl.hasBackupSync(identifier, versionId, meta);
|
|
117
|
-
}
|
|
118
|
-
backup(identifier, content, versionId, meta, token) {
|
|
119
|
-
return this.impl.backup(identifier, content, versionId, meta, token);
|
|
120
|
-
}
|
|
121
|
-
discardBackup(identifier, token) {
|
|
122
|
-
return this.impl.discardBackup(identifier, token);
|
|
123
|
-
}
|
|
124
|
-
discardBackups(filter) {
|
|
125
|
-
return this.impl.discardBackups(filter);
|
|
126
|
-
}
|
|
127
|
-
getBackups() {
|
|
128
|
-
return this.impl.getBackups();
|
|
129
|
-
}
|
|
130
|
-
resolve(identifier) {
|
|
131
|
-
return this.impl.resolve(identifier);
|
|
132
|
-
}
|
|
133
|
-
toBackupResource(identifier) {
|
|
134
|
-
return this.impl.toBackupResource(identifier);
|
|
135
|
-
}
|
|
136
|
-
joinBackups() {
|
|
137
|
-
return this.impl.joinBackups();
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
WorkingCopyBackupService = ( __decorate([
|
|
141
|
-
( __param(1, IFileService)),
|
|
142
|
-
( __param(2, ILogService))
|
|
143
|
-
], WorkingCopyBackupService));
|
|
144
|
-
let WorkingCopyBackupServiceImpl = class WorkingCopyBackupServiceImpl extends Disposable {
|
|
145
|
-
static { WorkingCopyBackupServiceImpl_1 = this; }
|
|
146
|
-
static { this.PREAMBLE_END_MARKER = '\n'; }
|
|
147
|
-
static { this.PREAMBLE_END_MARKER_CHARCODE = '\n'.charCodeAt(0); }
|
|
148
|
-
static { this.PREAMBLE_META_SEPARATOR = ' '; }
|
|
149
|
-
static { this.PREAMBLE_MAX_LENGTH = 10000; }
|
|
150
|
-
constructor(backupWorkspaceHome, fileService, logService) {
|
|
151
|
-
super();
|
|
152
|
-
this.backupWorkspaceHome = backupWorkspaceHome;
|
|
153
|
-
this.fileService = fileService;
|
|
154
|
-
this.logService = logService;
|
|
155
|
-
this.ioOperationQueues = this._register(( new ResourceQueue()));
|
|
156
|
-
this.model = undefined;
|
|
157
|
-
this.initialize(backupWorkspaceHome);
|
|
158
|
-
}
|
|
159
|
-
initialize(backupWorkspaceResource) {
|
|
160
|
-
this.backupWorkspaceHome = backupWorkspaceResource;
|
|
161
|
-
this.ready = this.doInitialize();
|
|
162
|
-
}
|
|
163
|
-
async doInitialize() {
|
|
164
|
-
this.model = await WorkingCopyBackupsModel.create(this.backupWorkspaceHome, this.fileService);
|
|
165
|
-
return this.model;
|
|
166
|
-
}
|
|
167
|
-
async hasBackups() {
|
|
168
|
-
const model = await this.ready;
|
|
169
|
-
await this.joinBackups();
|
|
170
|
-
return model.count() > 0;
|
|
171
|
-
}
|
|
172
|
-
hasBackupSync(identifier, versionId, meta) {
|
|
173
|
-
if (!this.model) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
const backupResource = this.toBackupResource(identifier);
|
|
177
|
-
return ( this.model.has(backupResource, versionId, meta));
|
|
178
|
-
}
|
|
179
|
-
async backup(identifier, content, versionId, meta, token) {
|
|
180
|
-
const model = await this.ready;
|
|
181
|
-
if (token?.isCancellationRequested) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const backupResource = this.toBackupResource(identifier);
|
|
185
|
-
if (( model.has(backupResource, versionId, meta))) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
return this.ioOperationQueues.queueFor(backupResource, async () => {
|
|
189
|
-
if (token?.isCancellationRequested) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (( model.has(backupResource, versionId, meta))) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
let preamble = this.createPreamble(identifier, meta);
|
|
196
|
-
if (preamble.length >= WorkingCopyBackupServiceImpl_1.PREAMBLE_MAX_LENGTH) {
|
|
197
|
-
preamble = this.createPreamble(identifier);
|
|
198
|
-
}
|
|
199
|
-
const preambleBuffer = VSBuffer.fromString(preamble);
|
|
200
|
-
let backupBuffer;
|
|
201
|
-
if (isReadableStream(content)) {
|
|
202
|
-
backupBuffer = prefixedBufferStream(preambleBuffer, content);
|
|
203
|
-
}
|
|
204
|
-
else if (content) {
|
|
205
|
-
backupBuffer = prefixedBufferReadable(preambleBuffer, content);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
backupBuffer = VSBuffer.concat([preambleBuffer, VSBuffer.fromString('')]);
|
|
209
|
-
}
|
|
210
|
-
await this.fileService.writeFile(backupResource, backupBuffer);
|
|
211
|
-
model.add(backupResource, versionId, meta);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
createPreamble(identifier, meta) {
|
|
215
|
-
return `${( identifier.resource.toString())}${WorkingCopyBackupServiceImpl_1.PREAMBLE_META_SEPARATOR}${JSON.stringify({ ...meta, typeId: identifier.typeId })}${WorkingCopyBackupServiceImpl_1.PREAMBLE_END_MARKER}`;
|
|
216
|
-
}
|
|
217
|
-
async discardBackups(filter) {
|
|
218
|
-
const model = await this.ready;
|
|
219
|
-
const except = filter?.except;
|
|
220
|
-
if (Array.isArray(except) && except.length > 0) {
|
|
221
|
-
const exceptMap = ( new ResourceMap());
|
|
222
|
-
for (const exceptWorkingCopy of except) {
|
|
223
|
-
exceptMap.set(this.toBackupResource(exceptWorkingCopy), true);
|
|
224
|
-
}
|
|
225
|
-
await Promises.settled(( model.get().map(async (backupResource) => {
|
|
226
|
-
if (!( exceptMap.has(backupResource))) {
|
|
227
|
-
await this.doDiscardBackup(backupResource);
|
|
228
|
-
}
|
|
229
|
-
})));
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
await this.deleteIgnoreFileNotFound(this.backupWorkspaceHome);
|
|
233
|
-
model.clear();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
discardBackup(identifier, token) {
|
|
237
|
-
const backupResource = this.toBackupResource(identifier);
|
|
238
|
-
return this.doDiscardBackup(backupResource, token);
|
|
239
|
-
}
|
|
240
|
-
async doDiscardBackup(backupResource, token) {
|
|
241
|
-
const model = await this.ready;
|
|
242
|
-
if (token?.isCancellationRequested) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
return this.ioOperationQueues.queueFor(backupResource, async () => {
|
|
246
|
-
if (token?.isCancellationRequested) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
await this.deleteIgnoreFileNotFound(backupResource);
|
|
250
|
-
model.remove(backupResource);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
async deleteIgnoreFileNotFound(backupResource) {
|
|
254
|
-
try {
|
|
255
|
-
await this.fileService.del(backupResource, { recursive: true });
|
|
256
|
-
}
|
|
257
|
-
catch (error) {
|
|
258
|
-
if (error.fileOperationResult !== 1 ) {
|
|
259
|
-
throw error;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
async getBackups() {
|
|
264
|
-
const model = await this.ready;
|
|
265
|
-
await this.joinBackups();
|
|
266
|
-
const backups = await Promise.all(( model.get().map(backupResource => this.resolveIdentifier(backupResource, model))));
|
|
267
|
-
return coalesce(backups);
|
|
268
|
-
}
|
|
269
|
-
async resolveIdentifier(backupResource, model) {
|
|
270
|
-
let res = undefined;
|
|
271
|
-
await this.ioOperationQueues.queueFor(backupResource, async () => {
|
|
272
|
-
if (!( model.has(backupResource))) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const backupPreamble = await this.readToMatchingString(backupResource, WorkingCopyBackupServiceImpl_1.PREAMBLE_END_MARKER, WorkingCopyBackupServiceImpl_1.PREAMBLE_MAX_LENGTH);
|
|
276
|
-
if (!backupPreamble) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
const metaStartIndex = backupPreamble.indexOf(WorkingCopyBackupServiceImpl_1.PREAMBLE_META_SEPARATOR);
|
|
280
|
-
let resourcePreamble;
|
|
281
|
-
let metaPreamble;
|
|
282
|
-
if (metaStartIndex > 0) {
|
|
283
|
-
resourcePreamble = backupPreamble.substring(0, metaStartIndex);
|
|
284
|
-
metaPreamble = backupPreamble.substr(metaStartIndex + 1);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
resourcePreamble = backupPreamble;
|
|
288
|
-
metaPreamble = undefined;
|
|
289
|
-
}
|
|
290
|
-
const { typeId, meta } = this.parsePreambleMeta(metaPreamble);
|
|
291
|
-
model.update(backupResource, meta);
|
|
292
|
-
res = {
|
|
293
|
-
typeId: typeId ?? NO_TYPE_ID,
|
|
294
|
-
resource: ( URI.parse(resourcePreamble))
|
|
295
|
-
};
|
|
296
|
-
});
|
|
297
|
-
return res;
|
|
298
|
-
}
|
|
299
|
-
async readToMatchingString(backupResource, matchingString, maximumBytesToRead) {
|
|
300
|
-
const contents = ( (await this.fileService.readFile(backupResource, { length: maximumBytesToRead })).value.toString());
|
|
301
|
-
const matchingStringIndex = contents.indexOf(matchingString);
|
|
302
|
-
if (matchingStringIndex >= 0) {
|
|
303
|
-
return contents.substr(0, matchingStringIndex);
|
|
304
|
-
}
|
|
305
|
-
return undefined;
|
|
306
|
-
}
|
|
307
|
-
async resolve(identifier) {
|
|
308
|
-
const backupResource = this.toBackupResource(identifier);
|
|
309
|
-
const model = await this.ready;
|
|
310
|
-
let res = undefined;
|
|
311
|
-
await this.ioOperationQueues.queueFor(backupResource, async () => {
|
|
312
|
-
if (!( model.has(backupResource))) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
const backupStream = await this.fileService.readFileStream(backupResource);
|
|
316
|
-
const peekedBackupStream = await peekStream(backupStream.value, 1);
|
|
317
|
-
const firstBackupChunk = VSBuffer.concat(peekedBackupStream.buffer);
|
|
318
|
-
const preambleEndIndex = firstBackupChunk.buffer.indexOf(WorkingCopyBackupServiceImpl_1.PREAMBLE_END_MARKER_CHARCODE);
|
|
319
|
-
if (preambleEndIndex === -1) {
|
|
320
|
-
this.logService.trace(`Backup: Could not find meta end marker in ${backupResource}. The file is probably corrupt (filesize: ${backupStream.size}).`);
|
|
321
|
-
return undefined;
|
|
322
|
-
}
|
|
323
|
-
const preambelRaw = ( firstBackupChunk.slice(0, preambleEndIndex).toString());
|
|
324
|
-
let meta;
|
|
325
|
-
const metaStartIndex = preambelRaw.indexOf(WorkingCopyBackupServiceImpl_1.PREAMBLE_META_SEPARATOR);
|
|
326
|
-
if (metaStartIndex !== -1) {
|
|
327
|
-
meta = this.parsePreambleMeta(preambelRaw.substr(metaStartIndex + 1)).meta;
|
|
328
|
-
}
|
|
329
|
-
model.update(backupResource, meta);
|
|
330
|
-
const firstBackupChunkWithoutPreamble = firstBackupChunk.slice(preambleEndIndex + 1);
|
|
331
|
-
let value;
|
|
332
|
-
if (peekedBackupStream.ended) {
|
|
333
|
-
value = bufferToStream(firstBackupChunkWithoutPreamble);
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
value = prefixedBufferStream(firstBackupChunkWithoutPreamble, peekedBackupStream.stream);
|
|
337
|
-
}
|
|
338
|
-
res = { value, meta };
|
|
339
|
-
});
|
|
340
|
-
return res;
|
|
341
|
-
}
|
|
342
|
-
parsePreambleMeta(preambleMetaRaw) {
|
|
343
|
-
let typeId = undefined;
|
|
344
|
-
let meta = undefined;
|
|
345
|
-
if (preambleMetaRaw) {
|
|
346
|
-
try {
|
|
347
|
-
meta = JSON.parse(preambleMetaRaw);
|
|
348
|
-
typeId = meta?.typeId;
|
|
349
|
-
if (typeof meta?.typeId === 'string') {
|
|
350
|
-
delete meta.typeId;
|
|
351
|
-
if (isEmptyObject(meta)) {
|
|
352
|
-
meta = undefined;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return { typeId, meta };
|
|
360
|
-
}
|
|
361
|
-
toBackupResource(identifier) {
|
|
362
|
-
return joinPath(this.backupWorkspaceHome, identifier.resource.scheme, hashIdentifier(identifier));
|
|
363
|
-
}
|
|
364
|
-
joinBackups() {
|
|
365
|
-
return this.ioOperationQueues.whenDrained();
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
WorkingCopyBackupServiceImpl = WorkingCopyBackupServiceImpl_1 = ( __decorate([
|
|
369
|
-
( __param(1, IFileService)),
|
|
370
|
-
( __param(2, ILogService))
|
|
371
|
-
], WorkingCopyBackupServiceImpl));
|
|
372
|
-
class InMemoryWorkingCopyBackupService extends Disposable {
|
|
373
|
-
constructor() {
|
|
374
|
-
super();
|
|
375
|
-
this.backups = ( new ResourceMap());
|
|
376
|
-
}
|
|
377
|
-
async hasBackups() {
|
|
378
|
-
return this.backups.size > 0;
|
|
379
|
-
}
|
|
380
|
-
hasBackupSync(identifier, versionId) {
|
|
381
|
-
const backupResource = this.toBackupResource(identifier);
|
|
382
|
-
return ( this.backups.has(backupResource));
|
|
383
|
-
}
|
|
384
|
-
async backup(identifier, content, versionId, meta, token) {
|
|
385
|
-
const backupResource = this.toBackupResource(identifier);
|
|
386
|
-
this.backups.set(backupResource, {
|
|
387
|
-
typeId: identifier.typeId,
|
|
388
|
-
content: content instanceof VSBuffer ? content : content ? isReadableStream(content) ? await streamToBuffer(content) : readableToBuffer(content) : VSBuffer.fromString(''),
|
|
389
|
-
meta
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
async resolve(identifier) {
|
|
393
|
-
const backupResource = this.toBackupResource(identifier);
|
|
394
|
-
const backup = this.backups.get(backupResource);
|
|
395
|
-
if (backup) {
|
|
396
|
-
return { value: bufferToStream(backup.content), meta: backup.meta };
|
|
397
|
-
}
|
|
398
|
-
return undefined;
|
|
399
|
-
}
|
|
400
|
-
async getBackups() {
|
|
401
|
-
return ( Array.from(this.backups.entries()).map(([resource, backup]) => ({ typeId: backup.typeId, resource })));
|
|
402
|
-
}
|
|
403
|
-
async discardBackup(identifier) {
|
|
404
|
-
this.backups.delete(this.toBackupResource(identifier));
|
|
405
|
-
}
|
|
406
|
-
async discardBackups(filter) {
|
|
407
|
-
const except = filter?.except;
|
|
408
|
-
if (Array.isArray(except) && except.length > 0) {
|
|
409
|
-
const exceptMap = ( new ResourceMap());
|
|
410
|
-
for (const exceptWorkingCopy of except) {
|
|
411
|
-
exceptMap.set(this.toBackupResource(exceptWorkingCopy), true);
|
|
412
|
-
}
|
|
413
|
-
for (const backup of await this.getBackups()) {
|
|
414
|
-
if (!( exceptMap.has(this.toBackupResource(backup)))) {
|
|
415
|
-
await this.discardBackup(backup);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
this.backups.clear();
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
toBackupResource(identifier) {
|
|
424
|
-
return ( URI.from({ scheme: Schemas.inMemory, path: hashIdentifier(identifier) }));
|
|
425
|
-
}
|
|
426
|
-
async joinBackups() {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
function hashIdentifier(identifier) {
|
|
431
|
-
let resource;
|
|
432
|
-
if (identifier.typeId.length > 0) {
|
|
433
|
-
const typeIdHash = hashString(identifier.typeId);
|
|
434
|
-
if (identifier.resource.path) {
|
|
435
|
-
resource = joinPath(identifier.resource, typeIdHash);
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
resource = identifier.resource.with({ path: typeIdHash });
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
resource = identifier.resource;
|
|
443
|
-
}
|
|
444
|
-
return hashPath(resource);
|
|
445
|
-
}
|
|
446
|
-
function hashPath(resource) {
|
|
447
|
-
const str = resource.scheme === Schemas.file || resource.scheme === Schemas.untitled ? resource.fsPath : ( resource.toString());
|
|
448
|
-
return hashString(str);
|
|
449
|
-
}
|
|
450
|
-
function hashString(str) {
|
|
451
|
-
return ( hash(str).toString(16));
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
export { InMemoryWorkingCopyBackupService, WorkingCopyBackupService, WorkingCopyBackupsModel, hashIdentifier };
|