Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1425d048
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 搜索 >>
提交
1425d048
编写于
10月 18, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
storage - add test for migration
上级
b5aa0f02
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
125 addition
and
68 deletion
+125
-68
src/vs/platform/storage/node/storageService.ts
src/vs/platform/storage/node/storageService.ts
+7
-11
src/vs/platform/storage/test/common/storageService.test.ts
src/vs/platform/storage/test/common/storageService.test.ts
+0
-54
src/vs/platform/storage/test/node/storageService.test.ts
src/vs/platform/storage/test/node/storageService.test.ts
+107
-0
src/vs/workbench/services/workspace/node/workspaceEditingService.ts
...kbench/services/workspace/node/workspaceEditingService.ts
+11
-3
未找到文件。
src/vs/platform/storage/node/storageService.ts
浏览文件 @
1425d048
...
...
@@ -15,9 +15,8 @@ import { Action } from 'vs/base/common/actions';
import
{
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
mark
,
getDuration
}
from
'
vs/base/common/performance
'
;
import
{
IWorkspaceIdentifier
}
from
'
vs/platform/workspaces/common/workspaces
'
;
import
{
join
,
basename
}
from
'
path
'
;
import
{
mkdirp
,
copy
}
from
'
vs/base/node/pfs
'
;
import
{
copy
}
from
'
vs/base/node/pfs
'
;
export
class
StorageService
extends
Disposable
implements
IStorageService
{
_serviceBrand
:
any
;
...
...
@@ -59,7 +58,7 @@ export class StorageService extends Disposable implements IStorageService {
constructor
(
workspaceStoragePath
:
string
,
@
ILogService
logService
:
ILogService
,
@
IEnvironmentService
private
environmentService
:
IEnvironmentService
@
IEnvironmentService
environmentService
:
IEnvironmentService
)
{
super
();
...
...
@@ -197,26 +196,23 @@ export class StorageService extends Disposable implements IStorageService {
});
}
migrate
(
toWorkspace
:
IWorkspaceIdentifier
):
Promise
<
void
>
{
migrate
(
toWorkspace
StorageFolder
:
string
):
Promise
<
void
>
{
if
(
this
.
workspaceStoragePath
===
StorageService
.
IN_MEMORY_PATH
)
{
return
Promise
.
resolve
();
// no migration needed if running in memory
}
// Compute new workspace storage path based on workspace identifier
const
newWorkspaceStorageHome
=
join
(
this
.
environmentService
.
workspaceStorageHome
,
toWorkspace
.
id
);
const
newWorkspaceStoragePath
=
join
(
newWorkspaceStorageHome
,
basename
(
this
.
workspaceStoragePath
));
const
newWorkspaceStoragePath
=
join
(
toWorkspaceStorageFolder
,
basename
(
this
.
workspaceStoragePath
));
if
(
this
.
workspaceStoragePath
===
newWorkspaceStoragePath
)
{
return
Promise
.
resolve
();
// guard against migrating to same path
}
// Close workspace DB to be able to copy
return
this
.
workspaceStorage
.
close
().
then
(()
=>
{
return
mkdirp
(
newWorkspaceStorageHome
).
then
(()
=>
{
return
copy
(
this
.
workspaceStoragePath
,
newWorkspaceStoragePath
).
then
(()
=>
{
this
.
createWorkspaceStorage
(
newWorkspaceStoragePath
);
return
copy
(
this
.
workspaceStoragePath
,
newWorkspaceStoragePath
).
then
(()
=>
{
this
.
createWorkspaceStorage
(
newWorkspaceStoragePath
);
return
this
.
workspaceStorage
.
init
();
});
return
this
.
workspaceStorage
.
init
();
});
});
}
...
...
src/vs/platform/storage/test/common/storageService.test.ts
已删除
100644 → 0
浏览文件 @
b5aa0f02
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
// tslint:disable-next-line:import-patterns
import
{
TestStorageService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
suite
(
'
StorageService
'
,
()
=>
{
test
(
'
Remove Data
'
,
()
=>
{
let
storage
=
new
TestStorageService
();
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
'
foobar
'
,
StorageScope
.
GLOBAL
);
assert
.
strictEqual
(
'
foobar
'
,
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
StorageScope
.
GLOBAL
));
storage
.
remove
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
StorageScope
.
GLOBAL
);
assert
.
ok
(
!
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
StorageScope
.
GLOBAL
));
});
test
(
'
Get Data, Integer, Boolean
'
,
()
=>
{
let
storage
=
new
TestStorageService
();
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
StorageScope
.
GLOBAL
,
'
foobar
'
),
'
foobar
'
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
StorageScope
.
GLOBAL
,
''
),
''
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
StorageScope
.
GLOBAL
,
5
),
5
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
StorageScope
.
GLOBAL
,
0
),
0
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
StorageScope
.
GLOBAL
,
true
),
true
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
StorageScope
.
GLOBAL
,
false
),
false
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
'
foobar
'
,
StorageScope
.
GLOBAL
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
StorageScope
.
GLOBAL
),
'
foobar
'
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
''
,
StorageScope
.
GLOBAL
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
StorageScope
.
GLOBAL
),
''
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
5
,
StorageScope
.
GLOBAL
);
assert
.
strictEqual
(
storage
.
getInteger
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
StorageScope
.
GLOBAL
),
5
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
0
,
StorageScope
.
GLOBAL
);
assert
.
strictEqual
(
storage
.
getInteger
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
StorageScope
.
GLOBAL
),
0
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
true
,
StorageScope
.
GLOBAL
);
assert
.
strictEqual
(
storage
.
getBoolean
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
StorageScope
.
GLOBAL
),
true
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
false
,
StorageScope
.
GLOBAL
);
assert
.
strictEqual
(
storage
.
getBoolean
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
StorageScope
.
GLOBAL
),
false
);
assert
.
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getDefault
'
,
StorageScope
.
GLOBAL
,
'
getDefault
'
),
'
getDefault
'
);
assert
.
strictEqual
(
storage
.
getInteger
(
'
Monaco.IDE.Core.Storage.Test.getIntegerDefault
'
,
StorageScope
.
GLOBAL
,
5
),
5
);
assert
.
strictEqual
(
storage
.
getBoolean
(
'
Monaco.IDE.Core.Storage.Test.getBooleanDefault
'
,
StorageScope
.
GLOBAL
,
true
),
true
);
});
});
\ No newline at end of file
src/vs/platform/storage/test/node/storageService.test.ts
0 → 100644
浏览文件 @
1425d048
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
strictEqual
,
ok
,
equal
}
from
'
assert
'
;
import
{
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
import
{
TestStorageService
,
TestEnvironmentService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
StorageService
}
from
'
vs/platform/storage/node/storageService
'
;
import
{
generateUuid
}
from
'
vs/base/common/uuid
'
;
import
{
join
}
from
'
path
'
;
import
{
tmpdir
}
from
'
os
'
;
import
{
mkdirp
,
del
}
from
'
vs/base/node/pfs
'
;
import
{
NullLogService
}
from
'
vs/platform/log/common/log
'
;
suite
(
'
StorageService
'
,
()
=>
{
test
(
'
Remove Data (global, in-memory)
'
,
()
=>
{
removeData
(
StorageScope
.
GLOBAL
);
});
test
(
'
Remove Data (workspace, in-memory)
'
,
()
=>
{
removeData
(
StorageScope
.
WORKSPACE
);
});
function
removeData
(
scope
:
StorageScope
):
void
{
const
storage
=
new
TestStorageService
();
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
'
foobar
'
,
scope
);
strictEqual
(
'
foobar
'
,
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
scope
));
storage
.
remove
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
scope
);
ok
(
!
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.remove
'
,
scope
));
}
test
(
'
Get Data, Integer, Boolean (global, in-memory)
'
,
()
=>
{
storeData
(
StorageScope
.
GLOBAL
);
});
test
(
'
Get Data, Integer, Boolean (workspace, in-memory)
'
,
()
=>
{
storeData
(
StorageScope
.
WORKSPACE
);
});
function
storeData
(
scope
:
StorageScope
):
void
{
const
storage
=
new
TestStorageService
();
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
scope
,
'
foobar
'
),
'
foobar
'
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
scope
,
''
),
''
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
scope
,
5
),
5
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
scope
,
0
),
0
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
scope
,
true
),
true
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
scope
,
false
),
false
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
'
foobar
'
,
scope
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
scope
),
'
foobar
'
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
''
,
scope
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.get
'
,
scope
),
''
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
5
,
scope
);
strictEqual
(
storage
.
getInteger
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
scope
),
5
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
0
,
scope
);
strictEqual
(
storage
.
getInteger
(
'
Monaco.IDE.Core.Storage.Test.getInteger
'
,
scope
),
0
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
true
,
scope
);
strictEqual
(
storage
.
getBoolean
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
scope
),
true
);
storage
.
store
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
false
,
scope
);
strictEqual
(
storage
.
getBoolean
(
'
Monaco.IDE.Core.Storage.Test.getBoolean
'
,
scope
),
false
);
strictEqual
(
storage
.
get
(
'
Monaco.IDE.Core.Storage.Test.getDefault
'
,
scope
,
'
getDefault
'
),
'
getDefault
'
);
strictEqual
(
storage
.
getInteger
(
'
Monaco.IDE.Core.Storage.Test.getIntegerDefault
'
,
scope
,
5
),
5
);
strictEqual
(
storage
.
getBoolean
(
'
Monaco.IDE.Core.Storage.Test.getBooleanDefault
'
,
scope
,
true
),
true
);
}
function
uniqueStorageDir
():
string
{
const
id
=
generateUuid
();
return
join
(
tmpdir
(),
'
vsctests
'
,
id
,
'
storage2
'
,
id
);
}
test
(
'
Migrate Data
'
,
async
()
=>
{
const
storageDir
=
uniqueStorageDir
();
await
mkdirp
(
storageDir
);
const
storage
=
new
StorageService
(
join
(
storageDir
,
'
storage.db
'
),
new
NullLogService
(),
TestEnvironmentService
);
await
storage
.
init
();
storage
.
store
(
'
bar
'
,
'
foo
'
,
StorageScope
.
WORKSPACE
);
storage
.
store
(
'
barNumber
'
,
55
,
StorageScope
.
WORKSPACE
);
storage
.
store
(
'
barBoolean
'
,
true
,
StorageScope
.
GLOBAL
);
const
newStorageDir
=
uniqueStorageDir
();
await
mkdirp
(
newStorageDir
);
await
storage
.
migrate
(
newStorageDir
);
equal
(
storage
.
get
(
'
bar
'
,
StorageScope
.
WORKSPACE
),
'
foo
'
);
equal
(
storage
.
getInteger
(
'
barNumber
'
,
StorageScope
.
WORKSPACE
),
55
);
equal
(
storage
.
getBoolean
(
'
barBoolean
'
,
StorageScope
.
GLOBAL
),
true
);
await
storage
.
close
();
await
del
(
newStorageDir
,
tmpdir
());
await
del
(
storageDir
,
tmpdir
());
});
});
\ No newline at end of file
src/vs/workbench/services/workspace/node/workspaceEditingService.ts
浏览文件 @
1425d048
...
...
@@ -25,6 +25,9 @@ import { distinct } from 'vs/base/common/arrays';
import
{
isLinux
}
from
'
vs/base/common/platform
'
;
import
{
isEqual
}
from
'
vs/base/common/resources
'
;
import
{
INotificationService
,
Severity
}
from
'
vs/platform/notification/common/notification
'
;
import
{
join
}
from
'
path
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
mkdirp
}
from
'
vs/base/node/pfs
'
;
export
class
WorkspaceEditingService
implements
IWorkspaceEditingService
{
...
...
@@ -39,7 +42,8 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
@
IExtensionService
private
extensionService
:
IExtensionService
,
@
IBackupFileService
private
backupFileService
:
IBackupFileService
,
@
INotificationService
private
notificationService
:
INotificationService
,
@
ICommandService
private
commandService
:
ICommandService
@
ICommandService
private
commandService
:
ICommandService
,
@
IEnvironmentService
private
environmentService
:
IEnvironmentService
)
{
}
...
...
@@ -237,9 +241,13 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
}
private
migrateStorage
(
toWorkspace
:
IWorkspaceIdentifier
):
TPromise
<
void
>
{
const
storageImpl
=
this
.
storageService
as
DelegatingStorageService
;
const
newWorkspaceStorageHome
=
join
(
this
.
environmentService
.
workspaceStorageHome
,
toWorkspace
.
id
)
;
return
storageImpl
.
storage
.
migrate
(
toWorkspace
);
return
mkdirp
(
newWorkspaceStorageHome
).
then
(()
=>
{
const
storageImpl
=
this
.
storageService
as
DelegatingStorageService
;
return
storageImpl
.
storage
.
migrate
(
newWorkspaceStorageHome
);
});
}
private
migrateWorkspaceSettings
(
toWorkspace
:
IWorkspaceIdentifier
):
TPromise
<
void
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录