Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f7adbed3
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,发现更多精彩内容 >>
提交
f7adbed3
编写于
10月 17, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
storage - switch to a workspace storage
上级
f41a6943
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
83 addition
and
71 deletion
+83
-71
src/vs/platform/storage/electron-browser/storageService.ts
src/vs/platform/storage/electron-browser/storageService.ts
+13
-26
src/vs/workbench/electron-browser/main.ts
src/vs/workbench/electron-browser/main.ts
+70
-45
未找到文件。
src/vs/platform/storage/electron-browser/storageService.ts
浏览文件 @
f7adbed3
...
...
@@ -15,7 +15,7 @@ import { startsWith } from 'vs/base/common/strings';
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
mark
}
from
'
vs/base/common/performance
'
;
import
{
mark
,
getDuration
}
from
'
vs/base/common/performance
'
;
export
class
StorageService
extends
Disposable
implements
IStorageService
{
_serviceBrand
:
any
;
...
...
@@ -169,13 +169,13 @@ export class StorageService extends Disposable implements IStorageService {
workspaceItemsParsed
[
key
]
=
safeParse
(
value
);
});
console
.
group
(
`Storage: Global (check:
${
result
[
2
]}
)`
);
console
.
group
(
`Storage: Global (check:
${
result
[
2
]}
, load:
${
getDuration
(
'
willInitGlobalStorage
'
,
'
didInitGlobalStorage
'
)}
)`
);
console
.
table
(
globalItems
);
console
.
groupEnd
();
console
.
log
(
globalItemsParsed
);
console
.
group
(
`Storage: Workspace (check:
${
result
[
3
]}
)`
);
console
.
group
(
`Storage: Workspace (check:
${
result
[
3
]}
, load:
${
getDuration
(
'
willInitWorkspaceStorage
'
,
'
didInitWorkspaceStorage
'
)}
)`
);
console
.
table
(
workspaceItems
);
console
.
groupEnd
();
...
...
@@ -245,40 +245,27 @@ export class DelegatingStorageService extends Disposable implements IStorageServ
}
get
(
key
:
string
,
scope
:
StorageScope
,
fallbackValue
?:
any
):
string
{
const
localStorageValue
=
this
.
storageLegacyService
.
get
(
key
,
this
.
convertScope
(
scope
),
fallbackValue
);
const
dbValue
=
this
.
storageService
.
get
(
key
,
scope
,
localStorageValue
);
if
(
scope
===
StorageScope
.
WORKSPACE
)
{
return
this
.
storageService
.
get
(
key
,
scope
,
fallbackValue
);
}
return
this
.
assertAndGet
(
key
,
scope
,
dbValue
,
localStorage
Value
);
return
this
.
storageLegacyService
.
get
(
key
,
this
.
convertScope
(
scope
),
fallback
Value
);
}
getBoolean
(
key
:
string
,
scope
:
StorageScope
,
fallbackValue
?:
boolean
):
boolean
{
const
localStorageValue
=
this
.
storageLegacyService
.
getBoolean
(
key
,
this
.
convertScope
(
scope
),
fallbackValue
);
const
dbValue
=
this
.
storageService
.
getBoolean
(
key
,
scope
,
localStorageValue
);
return
this
.
assertAndGet
(
key
,
scope
,
dbValue
,
localStorageValue
);
if
(
scope
===
StorageScope
.
WORKSPACE
)
{
return
this
.
storageService
.
getBoolean
(
key
,
scope
,
fallbackValue
);
}
getInteger
(
key
:
string
,
scope
:
StorageScope
,
fallbackValue
?:
number
):
number
{
const
localStorageValue
=
this
.
storageLegacyService
.
getInteger
(
key
,
this
.
convertScope
(
scope
),
fallbackValue
);
const
dbValue
=
this
.
storageService
.
getInteger
(
key
,
scope
,
localStorageValue
);
return
this
.
assertAndGet
(
key
,
scope
,
dbValue
,
localStorageValue
);
return
this
.
storageLegacyService
.
getBoolean
(
key
,
this
.
convertScope
(
scope
),
fallbackValue
);
}
private
assertAndGet
(
key
:
string
,
scope
:
StorageScope
,
dbValue
:
any
,
localStorageValue
:
any
):
any
{
getInteger
(
key
:
string
,
scope
:
StorageScope
,
fallbackValue
?:
number
):
number
{
if
(
scope
===
StorageScope
.
WORKSPACE
)
{
this
.
assertStorageValue
(
key
,
scope
,
dbValue
,
localStorageValue
);
return
dbValue
;
return
this
.
storageService
.
getInteger
(
key
,
scope
,
fallbackValue
);
}
return
localStorageValue
;
}
private
assertStorageValue
(
key
:
string
,
scope
:
StorageScope
,
dbValue
:
any
,
localStorageValue
:
any
):
void
{
if
(
dbValue
!==
localStorageValue
)
{
this
.
logService
.
error
(
`Unexpected storage value (key:
${
key
}
, scope:
${
scope
===
StorageScope
.
GLOBAL
?
'
global
'
:
'
workspace
'
}
), actual:
${
dbValue
}
, expected:
${
localStorageValue
}
`
);
}
return
this
.
storageLegacyService
.
getInteger
(
key
,
this
.
convertScope
(
scope
),
fallbackValue
);
}
store
(
key
:
string
,
value
:
any
,
scope
:
StorageScope
):
void
{
...
...
src/vs/workbench/electron-browser/main.ts
浏览文件 @
f7adbed3
...
...
@@ -16,7 +16,7 @@ import { IWorkspaceContextService, Workspace, WorkbenchState } from 'vs/platform
import
{
WorkspaceService
,
ISingleFolderWorkspaceInitializationPayload
,
IMultiFolderWorkspaceInitializationPayload
,
IEmptyWorkspaceInitializationPayload
,
IWorkspaceInitializationPayload
}
from
'
vs/workbench/services/configuration/node/configurationService
'
;
import
{
SyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
import
{
stat
}
from
'
vs/base/node/pfs
'
;
import
{
stat
,
exists
}
from
'
vs/base/node/pfs
'
;
import
{
EnvironmentService
}
from
'
vs/platform/environment/node/environmentService
'
;
import
*
as
gracefulFs
from
'
graceful-fs
'
;
import
{
KeyboardMapperFactory
}
from
'
vs/workbench/services/keybinding/electron-browser/keybindingService
'
;
...
...
@@ -43,8 +43,8 @@ import { RelayURLService } from 'vs/platform/url/common/urlService';
import
{
MenubarChannelClient
}
from
'
vs/platform/menubar/node/menubarIpc
'
;
import
{
IMenubarService
}
from
'
vs/platform/menubar/common/menubar
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
sanitizeFilePath
}
from
'
vs/base/node/extfs
'
;
import
{
basename
}
from
'
path
'
;
import
{
sanitizeFilePath
,
mkdirp
}
from
'
vs/base/node/extfs
'
;
import
{
basename
,
join
}
from
'
path
'
;
import
{
createHash
}
from
'
crypto
'
;
gracefulFs
.
gracefulify
(
fs
);
// enable gracefulFs
...
...
@@ -101,13 +101,16 @@ function openWorkbench(configuration: IWindowConfiguration): Promise<void> {
// Resolve a workspace payload that we can get the workspace ID from
return
createWorkspaceInitializationPayload
(
configuration
,
environmentService
).
then
(
payload
=>
{
// Prepare the workspace storage folder
return
prepareWorkspaceStorageFolder
(
payload
,
environmentService
).
then
(
storagePath
=>
{
return
Promise
.
all
([
// Create and load workspace/configuration service
createWorkspaceService
(
payload
,
environmentService
),
// Create and load storage service
createStorageService
(
environmentService
,
logService
)
createStorageService
(
storagePath
,
environmentService
,
logService
)
]).
then
(
services
=>
{
const
workspaceService
=
services
[
0
];
const
storageLegacyService
=
createStorageLegacyService
(
workspaceService
,
environmentService
);
...
...
@@ -145,6 +148,7 @@ function openWorkbench(configuration: IWindowConfiguration): Promise<void> {
});
});
});
});
}
function
createWorkspaceInitializationPayload
(
configuration
:
IWindowConfiguration
,
environmentService
:
EnvironmentService
):
Promise
<
IWorkspaceInitializationPayload
>
{
...
...
@@ -162,9 +166,14 @@ function createWorkspaceInitializationPayload(configuration: IWindowConfiguratio
return
workspaceInitializationPayload
.
then
(
payload
=>
{
// Fallback to empty workspace if we have no payload yet
// Fallback to empty workspace if we have no payload yet. We know the
// backupPath must be a unique path so we leverage its name as workspace ID
if
(
!
payload
)
{
payload
=
{
id
:
configuration
.
backupPath
?
uri
.
from
({
path
:
basename
(
configuration
.
backupPath
),
scheme
:
'
empty
'
}).
toString
()
:
''
}
as
IEmptyWorkspaceInitializationPayload
;
if
(
!
configuration
.
backupPath
)
{
return
Promise
.
reject
(
new
Error
(
'
Unexpected missing backupPath for empty window
'
));
// should not happen in this case
}
payload
=
{
id
:
basename
(
configuration
.
backupPath
)
}
as
IEmptyWorkspaceInitializationPayload
;
}
return
payload
;
...
...
@@ -188,6 +197,8 @@ function resolveSingleFolderWorkspaceInitializationPayload(folderUri: ISingleFol
}
}
// we use the ctime as extra salt to the ID so that we catch the case of a folder getting
// deleted and recreated. in that case we do not want to carry over previous state
return
createHash
(
'
md5
'
).
update
(
folder
.
fsPath
).
update
(
ctime
?
String
(
ctime
)
:
''
).
digest
(
'
hex
'
);
}
...
...
@@ -217,14 +228,28 @@ function resolveSingleFolderWorkspaceInitializationPayload(folderUri: ISingleFol
});
}
function
prepareWorkspaceStorageFolder
(
payload
:
IWorkspaceInitializationPayload
,
environmentService
:
IEnvironmentService
):
Thenable
<
string
>
{
// Workspace storage: scope by workspace identifier
const
storagePath
=
join
(
environmentService
.
workspaceStorageHome
,
payload
.
id
);
return
exists
(
storagePath
).
then
(
exists
=>
{
if
(
exists
)
{
return
storagePath
;
}
return
mkdirp
(
storagePath
).
then
(()
=>
storagePath
);
});
}
function
createWorkspaceService
(
payload
:
IWorkspaceInitializationPayload
,
environmentService
:
IEnvironmentService
):
Promise
<
WorkspaceService
>
{
const
workspaceService
=
new
WorkspaceService
(
environmentService
);
return
workspaceService
.
initialize
(
payload
).
then
(()
=>
workspaceService
,
error
=>
workspaceService
);
}
function
createStorageService
(
environmentService
:
IEnvironmentService
,
logService
:
ILogService
):
Promise
<
StorageService
>
{
const
storageService
=
new
StorageService
(
'
:memory:
'
,
logService
,
environmentService
);
function
createStorageService
(
workspaceStorageFolder
:
string
,
environmentService
:
IEnvironmentService
,
logService
:
ILogService
):
Promise
<
StorageService
>
{
const
storageService
=
new
StorageService
(
join
(
workspaceStorageFolder
,
'
storage.db
'
)
,
logService
,
environmentService
);
return
storageService
.
init
().
then
(()
=>
storageService
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录