Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3fb99698
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3fb99698
编写于
10月 29, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
storage - only create DB if path does not exist
上级
fd5d3ca5
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
37 addition
and
27 deletion
+37
-27
src/vs/base/node/storage.ts
src/vs/base/node/storage.ts
+12
-6
src/vs/base/test/node/storage/storage.test.ts
src/vs/base/test/node/storage/storage.test.ts
+14
-11
src/vs/platform/storage/node/storageService.ts
src/vs/platform/storage/node/storageService.ts
+6
-5
src/vs/platform/storage/test/node/storageService.test.ts
src/vs/platform/storage/test/node/storageService.test.ts
+1
-1
src/vs/platform/telemetry/test/electron-browser/commonProperties.test.ts
.../telemetry/test/electron-browser/commonProperties.test.ts
+1
-1
src/vs/workbench/electron-browser/main.ts
src/vs/workbench/electron-browser/main.ts
+2
-2
src/vs/workbench/test/workbenchTestServices.ts
src/vs/workbench/test/workbenchTestServices.ts
+1
-1
未找到文件。
src/vs/base/node/storage.ts
浏览文件 @
3fb99698
...
...
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Database
,
Statement
}
from
'
vscode-sqlite3
'
;
import
{
Database
,
Statement
,
OPEN_READWRITE
,
OPEN_CREATE
}
from
'
vscode-sqlite3
'
;
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
RunOnceScheduler
,
Queue
}
from
'
vs/base/common/async
'
;
...
...
@@ -14,6 +14,7 @@ import { mark } from 'vs/base/common/performance';
export
interface
IStorageOptions
{
path
:
string
;
createPath
:
boolean
;
logging
?:
IStorageLoggingOptions
;
}
...
...
@@ -363,18 +364,18 @@ export class SQLiteStorageImpl {
this
.
logger
.
info
(
`[storage
${
this
.
name
}
] open()`
);
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
doOpen
(
this
.
options
.
path
).
then
(
resolve
,
error
=>
{
this
.
doOpen
(
this
.
options
.
path
,
this
.
options
.
createPath
).
then
(
resolve
,
error
=>
{
this
.
logger
.
error
(
`[storage
${
this
.
name
}
] open(): Error (open DB):
${
error
}
`
);
this
.
logger
.
error
(
`[storage
${
this
.
name
}
] open(): Falling back to in-memory DB`
);
// In case of any error to open the DB, use an in-memory
// DB so that we always have a valid DB to talk to.
this
.
doOpen
(
'
:memory:
'
).
then
(
resolve
,
reject
);
this
.
doOpen
(
'
:memory:
'
,
true
).
then
(
resolve
,
reject
);
});
});
}
private
doOpen
(
path
:
string
):
Promise
<
Database
>
{
private
doOpen
(
path
:
string
,
createPath
:
boolean
):
Promise
<
Database
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
measureRequireDuration
=
false
;
if
(
!
SQLiteStorageImpl
.
measuredRequireDuration
)
{
...
...
@@ -388,12 +389,17 @@ export class SQLiteStorageImpl {
mark
(
'
didRequireSQLite
'
);
}
const
db
=
new
(
this
.
logger
.
verbose
?
sqlite3
.
verbose
().
Database
:
sqlite3
.
Database
)(
path
,
error
=>
{
const
db
=
new
(
this
.
logger
.
verbose
?
sqlite3
.
verbose
().
Database
:
sqlite3
.
Database
)(
path
,
createPath
?
OPEN_READWRITE
|
OPEN_CREATE
:
OPEN_READWRITE
,
error
=>
{
if
(
error
)
{
return
reject
(
error
);
}
// Setup schema
// Return early if we did not create the DB
if
(
!
createPath
)
{
return
resolve
(
db
);
}
// Otherwise: Setup schema
mark
(
'
willSetupSQLiteSchema
'
);
this
.
exec
(
db
,
[
'
PRAGMA user_version = 1;
'
,
...
...
src/vs/base/test/node/storage/storage.test.ts
浏览文件 @
3fb99698
...
...
@@ -23,7 +23,7 @@ suite('Storage Library', () => {
const
storageDir
=
uniqueStorageDir
();
await
mkdirp
(
storageDir
);
const
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
});
const
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
,
createPath
:
true
});
await
storage
.
init
();
...
...
@@ -97,7 +97,7 @@ suite('Storage Library', () => {
const
storageDir
=
uniqueStorageDir
();
await
mkdirp
(
storageDir
);
let
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
});
let
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
,
createPath
:
true
});
await
storage
.
init
();
const
set1Promise
=
storage
.
set
(
'
foo
'
,
'
bar
'
);
...
...
@@ -113,7 +113,7 @@ suite('Storage Library', () => {
equal
(
setPromiseResolved
,
true
);
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
});
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
,
createPath
:
false
});
await
storage
.
init
();
equal
(
storage
.
get
(
'
foo
'
),
'
bar
'
);
...
...
@@ -121,7 +121,7 @@ suite('Storage Library', () => {
await
storage
.
close
();
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
});
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
,
createPath
:
false
});
await
storage
.
init
();
const
delete1Promise
=
storage
.
delete
(
'
foo
'
);
...
...
@@ -137,7 +137,7 @@ suite('Storage Library', () => {
equal
(
deletePromiseResolved
,
true
);
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
});
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
,
createPath
:
false
});
await
storage
.
init
();
ok
(
!
storage
.
get
(
'
foo
'
));
...
...
@@ -151,7 +151,7 @@ suite('Storage Library', () => {
const
storageDir
=
uniqueStorageDir
();
await
mkdirp
(
storageDir
);
let
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
});
let
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
,
createPath
:
true
});
await
storage
.
init
();
let
changes
=
new
Set
<
string
>
();
...
...
@@ -206,7 +206,7 @@ suite('SQLite Storage Library', () => {
}
async
function
testDBBasics
(
path
,
errorLogger
?:
(
error
)
=>
void
)
{
const
options
:
IStorageOptions
=
{
path
};
const
options
:
IStorageOptions
=
{
path
,
createPath
:
true
};
if
(
errorLogger
)
{
options
.
logging
=
{
errorLogger
...
...
@@ -305,7 +305,8 @@ suite('SQLite Storage Library', () => {
await
mkdirp
(
storageDir
);
let
storage
=
new
SQLiteStorageImpl
({
path
:
join
(
storageDir
,
'
storage.db
'
)
path
:
join
(
storageDir
,
'
storage.db
'
),
createPath
:
true
});
const
items1
=
new
Map
<
string
,
string
>
();
...
...
@@ -381,7 +382,8 @@ suite('SQLite Storage Library', () => {
await
storage
.
close
();
storage
=
new
SQLiteStorageImpl
({
path
:
join
(
storageDir
,
'
storage.db
'
)
path
:
join
(
storageDir
,
'
storage.db
'
),
createPath
:
true
});
storedItems
=
await
storage
.
getItems
();
...
...
@@ -398,7 +400,8 @@ suite('SQLite Storage Library', () => {
await
mkdirp
(
storageDir
);
let
storage
=
new
SQLiteStorageImpl
({
path
:
join
(
storageDir
,
'
storage.db
'
)
path
:
join
(
storageDir
,
'
storage.db
'
),
createPath
:
true
});
const
items
=
new
Map
<
string
,
string
>
();
...
...
@@ -451,7 +454,7 @@ suite('SQLite Storage Library', () => {
const
storageDir
=
uniqueStorageDir
();
await
mkdirp
(
storageDir
);
const
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
});
const
storage
=
new
Storage
({
path
:
join
(
storageDir
,
'
storage.db
'
)
,
createPath
:
true
});
await
storage
.
init
();
...
...
src/vs/platform/storage/node/storageService.ts
浏览文件 @
3fb99698
...
...
@@ -61,6 +61,7 @@ export class StorageService extends Disposable implements IStorageService {
constructor
(
workspaceStoragePath
:
string
,
workspaceStoragePathExists
:
boolean
,
disableGlobalStorage
:
boolean
,
@
ILogService
logService
:
ILogService
,
@
IEnvironmentService
environmentService
:
IEnvironmentService
...
...
@@ -84,13 +85,13 @@ export class StorageService extends Disposable implements IStorageService {
};
this
.
globalStorageWorkspacePath
=
workspaceStoragePath
===
StorageService
.
IN_MEMORY_PATH
?
StorageService
.
IN_MEMORY_PATH
:
StorageService
.
IN_MEMORY_PATH
;
this
.
globalStorage
=
disableGlobalStorage
?
new
NullStorage
()
:
new
Storage
({
path
:
this
.
globalStorageWorkspacePath
,
logging
:
this
.
loggingOptions
});
this
.
globalStorage
=
disableGlobalStorage
?
new
NullStorage
()
:
new
Storage
({
path
:
this
.
globalStorageWorkspacePath
,
createPath
:
true
,
logging
:
this
.
loggingOptions
});
this
.
_register
(
this
.
globalStorage
.
onDidChangeStorage
(
key
=>
this
.
handleDidChangeStorage
(
key
,
StorageScope
.
GLOBAL
)));
this
.
createWorkspaceStorage
(
workspaceStoragePath
);
this
.
createWorkspaceStorage
(
workspaceStoragePath
,
workspaceStoragePathExists
);
}
private
createWorkspaceStorage
(
workspaceStoragePath
:
string
):
void
{
private
createWorkspaceStorage
(
workspaceStoragePath
:
string
,
workspaceStoragePathExists
:
boolean
):
void
{
// Dispose old (if any)
this
.
workspaceStorage
=
dispose
(
this
.
workspaceStorage
);
...
...
@@ -98,7 +99,7 @@ export class StorageService extends Disposable implements IStorageService {
// Create new
this
.
workspaceStoragePath
=
workspaceStoragePath
;
this
.
workspaceStorage
=
new
Storage
({
path
:
workspaceStoragePath
,
logging
:
this
.
loggingOptions
});
this
.
workspaceStorage
=
new
Storage
({
path
:
workspaceStoragePath
,
createPath
:
!
workspaceStoragePathExists
,
logging
:
this
.
loggingOptions
});
this
.
workspaceStorageListener
=
this
.
workspaceStorage
.
onDidChangeStorage
(
key
=>
this
.
handleDidChangeStorage
(
key
,
StorageScope
.
WORKSPACE
));
}
...
...
@@ -233,7 +234,7 @@ export class StorageService extends Disposable implements IStorageService {
// Close workspace DB to be able to copy
return
this
.
workspaceStorage
.
close
().
then
(()
=>
{
return
copy
(
this
.
workspaceStoragePath
,
newWorkspaceStoragePath
).
then
(()
=>
{
this
.
createWorkspaceStorage
(
newWorkspaceStoragePath
);
this
.
createWorkspaceStorage
(
newWorkspaceStoragePath
,
false
);
return
this
.
workspaceStorage
.
init
();
});
...
...
src/vs/platform/storage/test/node/storageService.test.ts
浏览文件 @
3fb99698
...
...
@@ -84,7 +84,7 @@ suite('StorageService', () => {
const
storageDir
=
uniqueStorageDir
();
await
mkdirp
(
storageDir
);
const
storage
=
new
StorageService
(
join
(
storageDir
,
'
storage.db
'
),
false
,
new
NullLogService
(),
TestEnvironmentService
);
const
storage
=
new
StorageService
(
join
(
storageDir
,
'
storage.db
'
),
false
,
false
,
new
NullLogService
(),
TestEnvironmentService
);
await
storage
.
init
();
storage
.
store
(
'
bar
'
,
'
foo
'
,
StorageScope
.
WORKSPACE
);
...
...
src/vs/platform/telemetry/test/electron-browser/commonProperties.test.ts
浏览文件 @
3fb99698
...
...
@@ -24,7 +24,7 @@ suite('Telemetry - common properties', function () {
let
nestStorage2Service
:
IStorageService
;
setup
(()
=>
{
nestStorage2Service
=
new
StorageService
(
'
:memory:
'
,
false
,
new
NullLogService
(),
TestEnvironmentService
);
nestStorage2Service
=
new
StorageService
(
'
:memory:
'
,
false
,
false
,
new
NullLogService
(),
TestEnvironmentService
);
});
teardown
(
done
=>
{
...
...
src/vs/workbench/electron-browser/main.ts
浏览文件 @
3fb99698
...
...
@@ -284,7 +284,7 @@ function createStorageService(workspaceStorageFolder: string, payload: IWorkspac
// Return early if we are using in-memory storage
const
useInMemoryStorage
=
!!
environmentService
.
extensionTestsPath
;
/* never keep any state when running extension tests */
if
(
useInMemoryStorage
)
{
const
storageService
=
new
StorageService
(
StorageService
.
IN_MEMORY_PATH
,
true
,
logService
,
environmentService
);
const
storageService
=
new
StorageService
(
StorageService
.
IN_MEMORY_PATH
,
false
,
true
,
logService
,
environmentService
);
return
storageService
.
init
().
then
(()
=>
storageService
);
}
...
...
@@ -296,7 +296,7 @@ function createStorageService(workspaceStorageFolder: string, payload: IWorkspac
return
exists
(
workspaceStorageDBPath
).
then
(
exists
=>
{
perf
.
mark
(
'
didCheckWorkspaceStorageExists
'
);
const
storageService
=
new
StorageService
(
workspaceStorageDBPath
,
true
,
logService
,
environmentService
);
const
storageService
=
new
StorageService
(
workspaceStorageDBPath
,
exists
,
true
,
logService
,
environmentService
);
return
storageService
.
init
().
then
(()
=>
{
if
(
exists
)
{
...
...
src/vs/workbench/test/workbenchTestServices.ts
浏览文件 @
3fb99698
...
...
@@ -531,7 +531,7 @@ export class TestPartService implements IPartService {
export
class
TestStorageService
extends
StorageService
{
constructor
()
{
super
(
'
:memory:
'
,
false
,
new
NullLogService
(),
TestEnvironmentService
);
super
(
'
:memory:
'
,
false
,
false
,
new
NullLogService
(),
TestEnvironmentService
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录