Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ac012cb8
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,发现更多精彩内容 >>
提交
ac012cb8
编写于
2月 18, 2020
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #89750
上级
e5dadf5e
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
112 addition
and
7 deletion
+112
-7
src/vs/platform/userDataSync/common/userDataAutoSyncService.ts
...s/platform/userDataSync/common/userDataAutoSyncService.ts
+7
-0
src/vs/platform/userDataSync/common/userDataSync.ts
src/vs/platform/userDataSync/common/userDataSync.ts
+1
-0
src/vs/platform/userDataSync/common/userDataSyncService.ts
src/vs/platform/userDataSync/common/userDataSyncService.ts
+22
-1
src/vs/platform/userDataSync/test/common/userDataSyncClient.ts
...s/platform/userDataSync/test/common/userDataSyncClient.ts
+9
-2
src/vs/platform/userDataSync/test/common/userDataSyncService.test.ts
...form/userDataSync/test/common/userDataSyncService.test.ts
+72
-3
src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
...vs/workbench/contrib/userDataSync/browser/userDataSync.ts
+1
-1
未找到文件。
src/vs/platform/userDataSync/common/userDataAutoSyncService.ts
浏览文件 @
ac012cb8
...
...
@@ -72,6 +72,13 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto
return
this
.
sync
(
loop
,
auto
);
}
}
if
(
e
instanceof
UserDataSyncError
&&
e
.
code
===
UserDataSyncErrorCode
.
SessionExpired
)
{
this
.
logService
.
info
(
'
Auto Sync: Cloud has new session
'
);
this
.
logService
.
info
(
'
Auto Sync: Resetting the local sync state.
'
);
await
this
.
userDataSyncService
.
resetLocal
();
this
.
logService
.
info
(
'
Auto Sync: Completed resetting the local sync state.
'
);
return
this
.
sync
(
loop
,
auto
);
}
this
.
logService
.
error
(
e
);
this
.
successiveFailures
++
;
this
.
_onError
.
fire
(
e
instanceof
UserDataSyncError
?
{
code
:
e
.
code
,
source
:
e
.
source
}
:
{
code
:
UserDataSyncErrorCode
.
Unknown
});
...
...
src/vs/platform/userDataSync/common/userDataSync.ts
浏览文件 @
ac012cb8
...
...
@@ -166,6 +166,7 @@ export enum UserDataSyncErrorCode {
TooLarge
=
'
TooLarge
'
,
NoRef
=
'
NoRef
'
,
TurnedOff
=
'
TurnedOff
'
,
SessionExpired
=
'
SessionExpired
'
,
// Local Errors
LocalPreconditionFailed
=
'
LocalPreconditionFailed
'
,
...
...
src/vs/platform/userDataSync/common/userDataSyncService.ts
浏览文件 @
ac012cb8
...
...
@@ -14,11 +14,14 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
equals
}
from
'
vs/base/common/arrays
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
IStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
type
SyncErrorClassification
=
{
source
:
{
classification
:
'
SystemMetaData
'
,
purpose
:
'
FeatureInsight
'
,
isMeasurement
:
true
};
};
const
SESSION_ID_KEY
=
'
sync.sessionId
'
;
export
class
UserDataSyncService
extends
Disposable
implements
IUserDataSyncService
{
_serviceBrand
:
any
;
...
...
@@ -48,6 +51,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
@
IUserDataSyncLogService
private
readonly
logService
:
IUserDataSyncLogService
,
@
IUserDataAuthTokenService
private
readonly
userDataAuthTokenService
:
IUserDataAuthTokenService
,
@
ITelemetryService
private
readonly
telemetryService
:
ITelemetryService
,
@
IStorageService
private
readonly
storageService
:
IStorageService
,
)
{
super
();
this
.
keybindingsSynchroniser
=
this
.
_register
(
this
.
instantiationService
.
createInstance
(
KeybindingsSynchroniser
));
...
...
@@ -96,7 +100,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
this
.
setStatus
(
SyncStatus
.
Syncing
);
}
cons
t
manifest
=
await
this
.
userDataSyncStoreService
.
manifest
();
le
t
manifest
=
await
this
.
userDataSyncStoreService
.
manifest
();
// Server has no data but this machine was synced before
if
(
manifest
===
null
&&
await
this
.
hasPreviouslySynced
())
{
...
...
@@ -104,6 +108,12 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
throw
new
UserDataSyncError
(
localize
(
'
turned off
'
,
"
Cannot sync because syncing is turned off in the cloud
"
),
UserDataSyncErrorCode
.
TurnedOff
);
}
const
sessionId
=
this
.
storageService
.
get
(
SESSION_ID_KEY
,
StorageScope
.
GLOBAL
);
// Server session is different from client session
if
(
sessionId
&&
manifest
&&
sessionId
!==
manifest
.
session
)
{
throw
new
UserDataSyncError
(
localize
(
'
session expired
'
,
"
Cannot sync because current session is expired
"
),
UserDataSyncErrorCode
.
SessionExpired
);
}
for
(
const
synchroniser
of
this
.
synchronisers
)
{
try
{
await
synchroniser
.
sync
(
manifest
&&
manifest
.
latest
?
manifest
.
latest
[
synchroniser
.
resourceKey
]
:
undefined
);
...
...
@@ -112,6 +122,16 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
}
}
// After syncing, get the manifest if it was not available before
if
(
manifest
===
null
)
{
manifest
=
await
this
.
userDataSyncStoreService
.
manifest
();
}
// Update local session id
if
(
manifest
&&
manifest
.
session
!==
sessionId
)
{
this
.
storageService
.
store
(
SESSION_ID_KEY
,
manifest
.
session
,
StorageScope
.
GLOBAL
);
}
this
.
logService
.
info
(
`Sync done. Took
${
new
Date
().
getTime
()
-
startTime
}
ms`
);
}
finally
{
...
...
@@ -169,6 +189,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
async
resetLocal
():
Promise
<
void
>
{
await
this
.
checkEnablement
();
this
.
storageService
.
remove
(
SESSION_ID_KEY
,
StorageScope
.
GLOBAL
);
for
(
const
synchroniser
of
this
.
synchronisers
)
{
try
{
synchroniser
.
resetLocal
();
...
...
src/vs/platform/userDataSync/test/common/userDataSyncClient.ts
浏览文件 @
ac012cb8
...
...
@@ -44,7 +44,7 @@ export class UserDataSyncClient extends Disposable {
this
.
instantiationService
=
new
TestInstantiationService
();
}
async
setUp
():
Promise
<
void
>
{
async
setUp
(
empty
:
boolean
=
false
):
Promise
<
void
>
{
const
userDataDirectory
=
URI
.
file
(
'
userdata
'
).
with
({
scheme
:
Schemas
.
inMemory
});
const
userDataSyncHome
=
joinPath
(
userDataDirectory
,
'
.sync
'
);
const
environmentService
=
this
.
instantiationService
.
stub
(
IEnvironmentService
,
<
Partial
<
IEnvironmentService
>>
{
...
...
@@ -71,7 +71,6 @@ export class UserDataSyncClient extends Disposable {
authenticationProviderId
:
'
test
'
}
})));
await
fileService
.
writeFile
(
environmentService
.
keybindingsResource
,
VSBuffer
.
fromString
(
JSON
.
stringify
([])));
const
configurationService
=
new
ConfigurationService
(
environmentService
.
settingsResource
,
fileService
);
await
configurationService
.
initialize
();
...
...
@@ -102,6 +101,14 @@ export class UserDataSyncClient extends Disposable {
this
.
instantiationService
.
stub
(
ISettingsSyncService
,
this
.
instantiationService
.
createInstance
(
SettingsSynchroniser
));
this
.
instantiationService
.
stub
(
IUserDataSyncService
,
this
.
instantiationService
.
createInstance
(
UserDataSyncService
));
if
(
empty
)
{
await
fileService
.
del
(
environmentService
.
settingsResource
);
}
else
{
await
fileService
.
writeFile
(
environmentService
.
keybindingsResource
,
VSBuffer
.
fromString
(
JSON
.
stringify
([])));
await
fileService
.
writeFile
(
environmentService
.
argvResource
,
VSBuffer
.
fromString
(
JSON
.
stringify
({
'
locale
'
:
'
en
'
})));
}
await
configurationService
.
reloadConfiguration
();
}
}
...
...
src/vs/platform/userDataSync/test/common/userDataSyncService.test.ts
浏览文件 @
ac012cb8
...
...
@@ -41,7 +41,38 @@ suite('UserDataSyncService', () => {
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/globalState`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
},
// Extensions
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions/latest`
,
headers
:
{}
},
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
}
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
},
// Manifest
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/manifest`
,
headers
:
{}
},
]);
});
test
(
'
test first time sync ever with no data
'
,
async
()
=>
{
// Setup the client
const
target
=
new
UserDataSyncTestServer
();
const
client
=
disposableStore
.
add
(
new
UserDataSyncClient
(
target
));
await
client
.
setUp
(
true
);
const
testObject
=
client
.
instantiationService
.
get
(
IUserDataSyncService
);
// Sync for first time
await
testObject
.
sync
();
assert
.
deepEqual
(
target
.
requests
,
[
// Manifest
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/manifest`
,
headers
:
{}
},
// Settings
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/resource/settings/latest`
,
headers
:
{}
},
// Keybindings
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/resource/keybindings/latest`
,
headers
:
{}
},
// Global state
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/resource/globalState/latest`
,
headers
:
{}
},
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/globalState`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
},
// Extensions
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions/latest`
,
headers
:
{}
},
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
},
// Manifest
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/manifest`
,
headers
:
{}
},
]);
});
...
...
@@ -333,12 +364,14 @@ suite('UserDataSyncService', () => {
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/globalState`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
},
// Extensions
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions/latest`
,
headers
:
{}
},
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
}
{
type
:
'
POST
'
,
url
:
`
${
target
.
url
}
/v1/resource/extensions`
,
headers
:
{
'
If-Match
'
:
'
0
'
}
},
// Manifest
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/manifest`
,
headers
:
{}
},
]);
});
test
(
'
test delete on one client throws error on other client while syncing
'
,
async
()
=>
{
test
(
'
test delete on one client throws
turned off
error on other client while syncing
'
,
async
()
=>
{
const
target
=
new
UserDataSyncTestServer
();
// Set up and sync from the client
...
...
@@ -371,6 +404,42 @@ suite('UserDataSyncService', () => {
throw
assert
.
fail
(
'
Should fail with turned off error
'
);
});
test
(
'
test creating new session from one client throws session expired error on another client while syncing
'
,
async
()
=>
{
const
target
=
new
UserDataSyncTestServer
();
// Set up and sync from the client
const
client
=
disposableStore
.
add
(
new
UserDataSyncClient
(
target
));
await
client
.
setUp
();
await
client
.
instantiationService
.
get
(
IUserDataSyncService
).
sync
();
// Set up and sync from the test client
const
testClient
=
disposableStore
.
add
(
new
UserDataSyncClient
(
target
));
await
testClient
.
setUp
();
const
testObject
=
testClient
.
instantiationService
.
get
(
IUserDataSyncService
);
await
testObject
.
sync
();
// Reset from the first client
await
client
.
instantiationService
.
get
(
IUserDataSyncService
).
reset
();
// Sync again from the first client to create new session
await
client
.
instantiationService
.
get
(
IUserDataSyncService
).
sync
();
// Sync from the test client
target
.
reset
();
try
{
await
testObject
.
sync
();
}
catch
(
e
)
{
assert
.
ok
(
e
instanceof
UserDataSyncError
);
assert
.
deepEqual
((
<
UserDataSyncError
>
e
).
code
,
UserDataSyncErrorCode
.
SessionExpired
);
assert
.
deepEqual
(
target
.
requests
,
[
// Manifest
{
type
:
'
GET
'
,
url
:
`
${
target
.
url
}
/v1/manifest`
,
headers
:
{}
},
]);
return
;
}
throw
assert
.
fail
(
'
Should fail with turned off error
'
);
});
test
(
'
test sync status
'
,
async
()
=>
{
const
target
=
new
UserDataSyncTestServer
();
...
...
src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
浏览文件 @
ac012cb8
...
...
@@ -540,13 +540,13 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
}
});
if
(
result
.
confirmed
)
{
await
this
.
disableSync
();
if
(
result
.
checkboxChecked
)
{
this
.
telemetryService
.
publicLog2
(
'
sync/turnOffEveryWhere
'
);
await
this
.
userDataSyncService
.
reset
();
}
else
{
await
this
.
userDataSyncService
.
resetLocal
();
}
await
this
.
disableSync
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录