Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
72950f8b
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(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
72950f8b
编写于
10月 16, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
backup - wire in cancellation token to implementation
上级
29d459b6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
8 deletion
+29
-8
src/vs/workbench/contrib/backup/common/backupTracker.ts
src/vs/workbench/contrib/backup/common/backupTracker.ts
+1
-1
src/vs/workbench/services/backup/common/backup.ts
src/vs/workbench/services/backup/common/backup.ts
+3
-1
src/vs/workbench/services/backup/common/backupFileService.ts
src/vs/workbench/services/backup/common/backupFileService.ts
+12
-4
src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts
...es/backup/test/electron-browser/backupFileService.test.ts
+13
-2
未找到文件。
src/vs/workbench/contrib/backup/common/backupTracker.ts
浏览文件 @
72950f8b
...
...
@@ -128,7 +128,7 @@ export abstract class BackupTracker extends Disposable {
if
(
workingCopy
.
isDirty
())
{
this
.
logService
.
trace
(
`[backup tracker] storing backup`
,
workingCopy
.
resource
.
toString
());
await
this
.
backupFileService
.
backup
(
workingCopy
.
resource
,
backup
.
content
,
this
.
getContentVersion
(
workingCopy
),
backup
.
meta
);
await
this
.
backupFileService
.
backup
(
workingCopy
.
resource
,
backup
.
content
,
this
.
getContentVersion
(
workingCopy
),
backup
.
meta
,
cts
.
token
);
}
}
catch
(
error
)
{
this
.
logService
.
error
(
error
);
...
...
src/vs/workbench/services/backup/common/backup.ts
浏览文件 @
72950f8b
...
...
@@ -6,6 +6,7 @@
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ITextBufferFactory
,
ITextSnapshot
}
from
'
vs/editor/common/model
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
export
const
IBackupFileService
=
createDecorator
<
IBackupFileService
>
(
'
backupFileService
'
);
...
...
@@ -59,8 +60,9 @@ export interface IBackupFileService {
* @param versionId The optionsl version id of the resource to backup.
* @param meta The optional meta data of the resource to backup. This information
* can be restored later when loading the backup again.
* @param token The optional cancellation token if the operation can be cancelled.
*/
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
):
Promise
<
void
>
;
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
,
token
?:
CancellationToken
):
Promise
<
void
>
;
/**
* Discards the backup associated with a resource if it exists.
...
...
src/vs/workbench/services/backup/common/backupFileService.ts
浏览文件 @
72950f8b
...
...
@@ -21,6 +21,7 @@ import { VSBuffer } from 'vs/base/common/buffer';
import
{
TextSnapshotReadable
,
stringToSnapshot
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
export
interface
IBackupFilesModel
{
resolve
(
backupRoot
:
URI
):
Promise
<
IBackupFilesModel
>
;
...
...
@@ -157,8 +158,8 @@ export class BackupFileService implements IBackupFileService {
return
this
.
impl
.
hasBackupSync
(
resource
,
versionId
);
}
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
):
Promise
<
void
>
{
return
this
.
impl
.
backup
(
resource
,
content
,
versionId
,
meta
);
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
,
token
?:
CancellationToken
):
Promise
<
void
>
{
return
this
.
impl
.
backup
(
resource
,
content
,
versionId
,
meta
,
token
);
}
discardBackup
(
resource
:
URI
):
Promise
<
void
>
{
...
...
@@ -232,8 +233,11 @@ class BackupFileServiceImpl extends Disposable implements IBackupFileService {
return
this
.
model
.
has
(
backupResource
,
versionId
);
}
async
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
):
Promise
<
void
>
{
async
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
,
token
?:
CancellationToken
):
Promise
<
void
>
{
const
model
=
await
this
.
ready
;
if
(
token
?.
isCancellationRequested
)
{
return
;
}
const
backupResource
=
this
.
toBackupResource
(
resource
);
if
(
model
.
has
(
backupResource
,
versionId
,
meta
))
{
...
...
@@ -241,6 +245,10 @@ class BackupFileServiceImpl extends Disposable implements IBackupFileService {
}
return
this
.
ioOperationQueues
.
queueFor
(
backupResource
).
queue
(
async
()
=>
{
if
(
token
?.
isCancellationRequested
)
{
return
;
}
let
preamble
:
string
|
undefined
=
undefined
;
// With Metadata: URI + META-START + Meta + END
...
...
@@ -419,7 +427,7 @@ export class InMemoryBackupFileService implements IBackupFileService {
return
this
.
backups
.
has
(
backupResource
.
toString
());
}
async
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
):
Promise
<
void
>
{
async
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
,
token
?:
CancellationToken
):
Promise
<
void
>
{
const
backupResource
=
this
.
toBackupResource
(
resource
);
this
.
backups
.
set
(
backupResource
.
toString
(),
content
||
stringToSnapshot
(
''
));
}
...
...
src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts
浏览文件 @
72950f8b
...
...
@@ -28,6 +28,7 @@ import { FileUserDataProvider } from 'vs/workbench/services/userData/common/file
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
import
{
TestWorkbenchConfiguration
}
from
'
vs/workbench/test/electron-browser/workbenchTestServices
'
;
import
{
TestProductService
}
from
'
vs/workbench/test/browser/workbenchTestServices
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
const
userdataDir
=
getRandomTestPath
(
os
.
tmpdir
(),
'
vsctests
'
,
'
backupfileservice
'
);
const
backupHome
=
path
.
join
(
userdataDir
,
'
Backups
'
);
...
...
@@ -80,8 +81,8 @@ export class NodeTestBackupFileService extends BackupFileService {
return
new
Promise
(
resolve
=>
this
.
backupResourceJoiners
.
push
(
resolve
));
}
async
backup
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
any
):
Promise
<
void
>
{
await
super
.
backup
(
resource
,
content
,
versionId
,
meta
);
async
backup
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
any
,
token
?:
CancellationToken
):
Promise
<
void
>
{
await
super
.
backup
(
resource
,
content
,
versionId
,
meta
,
token
);
while
(
this
.
backupResourceJoiners
.
length
)
{
this
.
backupResourceJoiners
.
pop
()
!
();
...
...
@@ -262,6 +263,16 @@ suite('BackupFileService', () => {
model
.
dispose
();
});
test
(
'
cancellation
'
,
async
()
=>
{
const
cts
=
new
CancellationTokenSource
();
const
promise
=
service
.
backup
(
fooFile
,
undefined
,
undefined
,
undefined
,
cts
.
token
);
cts
.
cancel
();
await
promise
;
assert
.
equal
(
fs
.
existsSync
(
fooBackupPath
),
false
);
assert
.
ok
(
!
service
.
hasBackupSync
(
fooFile
));
});
});
suite
(
'
discardBackup
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录