提交 0d2fa132 编写于 作者: B Benjamin Pasero

storage - fix smoketest

上级 b638c6bd
...@@ -174,7 +174,13 @@ export class StorageMainService extends Disposable implements IStorageMainServic ...@@ -174,7 +174,13 @@ export class StorageMainService extends Disposable implements IStorageMainServic
private migrateGlobalStorage(): Thenable<void> { private migrateGlobalStorage(): Thenable<void> {
this.logService.info('[storage] migrating global storage from localStorage into SQLite'); this.logService.info('[storage] migrating global storage from localStorage into SQLite');
return new Promise((resolve, reject) => { const localStorageDBBackup = join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage.vscmig');
return exists(localStorageDBBackup).then(exists => {
if (!exists) {
return Promise.resolve(); // return if there is no DB to migrate from
}
return readdir(this.environmentService.extensionsPath).then(extensions => { return readdir(this.environmentService.extensionsPath).then(extensions => {
const supportedKeys = new Map<string, string>(); const supportedKeys = new Map<string, string>();
[ [
...@@ -246,79 +252,93 @@ export class StorageMainService extends Disposable implements IStorageMainServic ...@@ -246,79 +252,93 @@ export class StorageMainService extends Disposable implements IStorageMainServic
} }
}); });
const handleSuffixKey = (row, key: string, suffix: string) => { return import('vscode-sqlite3').then(sqlite3 => {
if (endsWith(key, suffix.toLowerCase())) {
const value: string = row.value.toString('utf16le');
const normalizedKey = key.substring(0, key.length - suffix.length) + suffix;
this.store(normalizedKey, value); return new Promise((resolve, reject) => {
const handleSuffixKey = (row, key: string, suffix: string) => {
if (endsWith(key, suffix.toLowerCase())) {
const value: string = row.value.toString('utf16le');
const normalizedKey = key.substring(0, key.length - suffix.length) + suffix;
return true; this.store(normalizedKey, value);
}
return false; return true;
}; }
return import('vscode-sqlite3').then(sqlite3 => { return false;
const localStorageDBBackup = join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage.vscmig'); };
const db: Database = new (sqlite3.Database)(localStorageDBBackup, error => {
if (error) {
return db ? db.close(() => reject(error)) : reject(error);
}
db.all('SELECT key, value FROM ItemTable', (error, rows) => { const db: Database = new (sqlite3.Database)(localStorageDBBackup, error => {
if (error) { if (error) {
return db.close(() => reject(error)); if (db) {
db.close();
}
return reject(error);
} }
rows.forEach(row => { db.all('SELECT key, value FROM ItemTable', (error, rows) => {
let key: string = row.key; if (error) {
if (key.indexOf('storage://global/') !== 0) { db.close();
return; // not a global key
return reject(error);
} }
// convert storage://global/colorthemedata => colorthemedata try {
key = key.substr('storage://global/'.length); rows.forEach(row => {
let key: string = row.key;
if (key.indexOf('storage://global/') !== 0) {
return; // not a global key
}
const supportedKey = supportedKeys.get(key); // convert storage://global/colorthemedata => colorthemedata
if (supportedKey) { key = key.substr('storage://global/'.length);
const value: string = row.value.toString('utf16le');
this.store(supportedKey, value); const supportedKey = supportedKeys.get(key);
} if (supportedKey) {
const value: string = row.value.toString('utf16le');
// dynamic values this.store(supportedKey, value);
else if ( }
endsWith(key, '.hidden') ||
startsWith(key, 'experiments.')
) {
const value: string = row.value.toString('utf16le');
this.store(key, value); // dynamic values
} else if (
endsWith(key, '.hidden') ||
startsWith(key, 'experiments.')
) {
const value: string = row.value.toString('utf16le');
// fix lowercased ".sessionCount" this.store(key, value);
else if (handleSuffixKey(row, key, '.sessionCount')) { } }
// fix lowercased ".lastSessionDate" // fix lowercased ".sessionCount"
else if (handleSuffixKey(row, key, '.lastSessionDate')) { } else if (handleSuffixKey(row, key, '.sessionCount')) { }
// fix lowercased ".skipVersion" // fix lowercased ".lastSessionDate"
else if (handleSuffixKey(row, key, '.skipVersion')) { } else if (handleSuffixKey(row, key, '.lastSessionDate')) { }
// fix lowercased ".isCandidate" // fix lowercased ".skipVersion"
else if (handleSuffixKey(row, key, '.isCandidate')) { } else if (handleSuffixKey(row, key, '.skipVersion')) { }
// fix lowercased ".editedCount" // fix lowercased ".isCandidate"
else if (handleSuffixKey(row, key, '.editedCount')) { } else if (handleSuffixKey(row, key, '.isCandidate')) { }
// fix lowercased ".editedDate" // fix lowercased ".editedCount"
else if (handleSuffixKey(row, key, '.editedDate')) { } else if (handleSuffixKey(row, key, '.editedCount')) { }
});
db.close(); // fix lowercased ".editedDate"
else if (handleSuffixKey(row, key, '.editedDate')) { }
});
resolve(); db.close();
} catch (error) {
db.close();
return reject(error);
}
resolve();
});
}); });
}); });
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册