Skip to content

Commit 84620b1

Browse files
author
Benjamin Pasero
committed
hot exit - back to ' ' as separator
1 parent e3fae47 commit 84620b1

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/vs/workbench/services/backup/node/backupFileService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class BackupFileService implements IBackupFileService {
166166
class BackupFileServiceImpl implements IBackupFileService {
167167

168168
private static readonly PREAMBLE_END_MARKER = '\n';
169-
private static readonly PREAMBLE_META_START_MARKER = '#'; // using a character that is know to be escaped in a URI as separator
169+
private static readonly PREAMBLE_META_SEPARATOR = ' '; // using a character that is know to be escaped in a URI as separator
170170
private static readonly PREAMBLE_MAX_LENGTH = 10000;
171171

172172
_serviceBrand: any;
@@ -234,7 +234,7 @@ class BackupFileServiceImpl implements IBackupFileService {
234234

235235
// With Metadata: URI + META-START + Meta + END
236236
if (meta) {
237-
const preambleWithMeta = `${resource.toString()}${BackupFileServiceImpl.PREAMBLE_META_START_MARKER}${JSON.stringify(meta)}${BackupFileServiceImpl.PREAMBLE_END_MARKER}`;
237+
const preambleWithMeta = `${resource.toString()}${BackupFileServiceImpl.PREAMBLE_META_SEPARATOR}${JSON.stringify(meta)}${BackupFileServiceImpl.PREAMBLE_END_MARKER}`;
238238
if (preambleWithMeta.length < BackupFileServiceImpl.PREAMBLE_MAX_LENGTH) {
239239
preamble = preambleWithMeta;
240240
}
@@ -284,7 +284,7 @@ class BackupFileServiceImpl implements IBackupFileService {
284284
}
285285

286286
// Preamble with metadata: URI + META-START + Meta + END
287-
const metaStartIndex = backupPreamble.indexOf(BackupFileServiceImpl.PREAMBLE_META_START_MARKER);
287+
const metaStartIndex = backupPreamble.indexOf(BackupFileServiceImpl.PREAMBLE_META_SEPARATOR);
288288
if (metaStartIndex > 0) {
289289
return URI.parse(backupPreamble.substring(0, metaStartIndex));
290290
}
@@ -333,7 +333,7 @@ class BackupFileServiceImpl implements IBackupFileService {
333333
factory.getFirstLineText(1);
334334

335335
let meta: T | undefined;
336-
const metaStartIndex = metaRaw.indexOf(BackupFileServiceImpl.PREAMBLE_META_START_MARKER);
336+
const metaStartIndex = metaRaw.indexOf(BackupFileServiceImpl.PREAMBLE_META_SEPARATOR);
337337
if (metaStartIndex !== -1) {
338338
try {
339339
meta = JSON.parse(metaRaw.substr(metaStartIndex + 1));

src/vs/workbench/services/backup/test/node/backupFileService.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const workspaceResource = URI.file(platform.isWindows ? 'c:\\workspace' : '/work
3333
const workspaceBackupPath = path.join(backupHome, hashPath(workspaceResource));
3434
const fooFile = URI.file(platform.isWindows ? 'c:\\Foo' : '/Foo');
3535
const customFile = URI.parse('customScheme://some/path');
36+
const customFileWithFragment = URI.parse('customScheme2://some/path#fragment');
3637
const barFile = URI.file(platform.isWindows ? 'c:\\Bar' : '/Bar');
3738
const fooBarFile = URI.file(platform.isWindows ? 'c:\\Foo Bar' : '/Foo Bar');
3839
const untitledFile = URI.from({ scheme: Schemas.untitled, path: 'Untitled-1' });
@@ -162,7 +163,7 @@ suite('BackupFileService', () => {
162163
await service.backupResource(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).createSnapshot(false), undefined, { etag: '678', orphaned: true });
163164
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
164165
assert.equal(fs.existsSync(fooBackupPath), true);
165-
assert.equal(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()}#{"etag":"678","orphaned":true}\ntest`);
166+
assert.equal(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()} {"etag":"678","orphaned":true}\ntest`);
166167
});
167168

168169
test('untitled file', async () => {
@@ -390,6 +391,8 @@ suite('BackupFileService', () => {
390391

391392
await service.backupResource(fooFile, createTextBufferFactory(contents).create(DefaultEndOfLine.LF).createSnapshot(false), 1, meta);
392393

394+
assert.ok(await service.loadBackupResource(fooFile));
395+
393396
const fileContents = fs.readFileSync(fooBackupPath).toString();
394397
assert.equal(fileContents.indexOf(fooFile.toString()), 0);
395398

@@ -402,6 +405,24 @@ suite('BackupFileService', () => {
402405
assert.ok(!backup.meta);
403406
});
404407

408+
test('should restore the original contents (text file with metadata and fragment URI)', async () => {
409+
const contents = [
410+
'Lorem ipsum ',
411+
'dolor öäü sit amet ',
412+
'adipiscing ßß elit',
413+
'consectetur '
414+
].join('');
415+
416+
const meta = {
417+
etag: 'theEtag',
418+
size: 888,
419+
mtime: Date.now(),
420+
orphaned: false
421+
};
422+
423+
await testResolveBackup(customFileWithFragment, contents, meta);
424+
});
425+
405426
test('should restore the original contents (text file with space in name with metadata)', async () => {
406427
const contents = [
407428
'Lorem ipsum ',
@@ -445,7 +466,7 @@ suite('BackupFileService', () => {
445466

446467
await service.backupResource(resource, createTextBufferFactory(contents).create(DefaultEndOfLine.LF).createSnapshot(false), 1, meta);
447468

448-
assert.ok(service.loadBackupResource(resource));
469+
assert.ok(await service.loadBackupResource(resource));
449470

450471
const backup = await service.resolveBackupContent<IBackupTestMetaData>(service.toBackupResource(resource));
451472
assert.equal(contents, snapshotToString(backup.value.create(platform.isWindows ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF).createSnapshot(true)));

0 commit comments

Comments
 (0)