Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
52fe5f21
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 搜索 >>
提交
52fe5f21
编写于
3月 27, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
backups - ensure to discard all on shutdown without dirty (#92962)
上级
92b9e7f5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
70 addition
and
2 deletion
+70
-2
src/vs/workbench/contrib/backup/electron-browser/backupTracker.ts
...orkbench/contrib/backup/electron-browser/backupTracker.ts
+19
-1
src/vs/workbench/services/backup/common/backup.ts
src/vs/workbench/services/backup/common/backup.ts
+6
-1
src/vs/workbench/services/backup/common/backupFileService.ts
src/vs/workbench/services/backup/common/backupFileService.ts
+16
-0
src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts
...es/backup/test/electron-browser/backupFileService.test.ts
+28
-0
src/vs/workbench/test/browser/workbenchTestServices.ts
src/vs/workbench/test/browser/workbenchTestServices.ts
+1
-0
未找到文件。
src/vs/workbench/contrib/backup/electron-browser/backupTracker.ts
浏览文件 @
52fe5f21
...
...
@@ -47,7 +47,8 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
return
this
.
onBeforeShutdownWithDirty
(
reason
,
dirtyWorkingCopies
);
}
return
false
;
// no veto (no dirty working copies)
// No dirty working copies
return
this
.
onBeforeShutdownWithoutDirty
();
}
protected
async
onBeforeShutdownWithDirty
(
reason
:
ShutdownReason
,
workingCopies
:
IWorkingCopy
[]):
Promise
<
boolean
>
{
...
...
@@ -253,4 +254,21 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
return
Promise
.
all
(
backupsToDiscard
.
map
(
workingCopy
=>
this
.
backupFileService
.
discardBackup
(
workingCopy
.
resource
))).
then
(()
=>
false
,
()
=>
false
);
}
private
async
onBeforeShutdownWithoutDirty
():
Promise
<
boolean
>
{
// If we have proceeded enough that editors and dirty state
// has restored, we make sure that no backups lure around
// given we have no known dirty working copy. This helps
// to clean up stale backups as for example reported in
// https://github.com/microsoft/vscode/issues/92962
if
(
this
.
lifecycleService
.
phase
>=
LifecyclePhase
.
Restored
)
{
try
{
await
this
.
backupFileService
.
discardBackups
();
}
catch
(
error
)
{
this
.
logService
.
error
(
`[backup tracker] error discarding backups:
${
error
}
`
);
}
}
return
false
;
}
}
src/vs/workbench/services/backup/common/backup.ts
浏览文件 @
52fe5f21
...
...
@@ -63,9 +63,14 @@ export interface IBackupFileService {
backup
<
T
extends
object
>
(
resource
:
URI
,
content
?:
ITextSnapshot
,
versionId
?:
number
,
meta
?:
T
):
Promise
<
void
>
;
/**
* Discards the backup associated with a resource if it exists.
.
* Discards the backup associated with a resource if it exists.
*
* @param resource The resource whose backup is being discarded discard to back up.
*/
discardBackup
(
resource
:
URI
):
Promise
<
void
>
;
/**
* Discards all backups.
*/
discardBackups
():
Promise
<
void
>
;
}
src/vs/workbench/services/backup/common/backupFileService.ts
浏览文件 @
52fe5f21
...
...
@@ -165,6 +165,10 @@ export class BackupFileService implements IBackupFileService {
return
this
.
impl
.
discardBackup
(
resource
);
}
discardBackups
():
Promise
<
void
>
{
return
this
.
impl
.
discardBackups
();
}
getBackups
():
Promise
<
URI
[]
>
{
return
this
.
impl
.
getBackups
();
}
...
...
@@ -260,6 +264,14 @@ class BackupFileServiceImpl extends Disposable implements IBackupFileService {
});
}
async
discardBackups
():
Promise
<
void
>
{
const
model
=
await
this
.
ready
;
await
this
.
deleteIgnoreFileNotFound
(
this
.
backupWorkspacePath
);
model
.
clear
();
}
discardBackup
(
resource
:
URI
):
Promise
<
void
>
{
const
backupResource
=
this
.
toBackupResource
(
resource
);
...
...
@@ -429,6 +441,10 @@ export class InMemoryBackupFileService implements IBackupFileService {
this
.
backups
.
delete
(
this
.
toBackupResource
(
resource
).
toString
());
}
async
discardBackups
():
Promise
<
void
>
{
this
.
backups
.
clear
();
}
toBackupResource
(
resource
:
URI
):
URI
{
return
URI
.
file
(
join
(
resource
.
scheme
,
this
.
hashPath
(
resource
)));
}
...
...
src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts
浏览文件 @
52fe5f21
...
...
@@ -43,6 +43,7 @@ const barFile = URI.file(platform.isWindows ? 'c:\\Bar' : '/Bar');
const
fooBarFile
=
URI
.
file
(
platform
.
isWindows
?
'
c:
\\
Foo Bar
'
:
'
/Foo Bar
'
);
const
untitledFile
=
URI
.
from
({
scheme
:
Schemas
.
untitled
,
path
:
'
Untitled-1
'
});
const
fooBackupPath
=
path
.
join
(
workspaceBackupPath
,
'
file
'
,
hashPath
(
fooFile
));
const
barBackupPath
=
path
.
join
(
workspaceBackupPath
,
'
file
'
,
hashPath
(
barFile
));
const
untitledBackupPath
=
path
.
join
(
workspaceBackupPath
,
'
untitled
'
,
hashPath
(
untitledFile
));
class
TestBackupEnvironmentService
extends
NativeWorkbenchEnvironmentService
{
...
...
@@ -285,6 +286,33 @@ suite('BackupFileService', () => {
});
});
suite
(
'
discardBackups
'
,
()
=>
{
test
(
'
text file
'
,
async
()
=>
{
await
service
.
backup
(
fooFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
));
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
file
'
)).
length
,
1
);
await
service
.
backup
(
barFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
));
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
file
'
)).
length
,
2
);
await
service
.
discardBackups
();
assert
.
equal
(
fs
.
existsSync
(
fooBackupPath
),
false
);
assert
.
equal
(
fs
.
existsSync
(
barBackupPath
),
false
);
assert
.
equal
(
fs
.
existsSync
(
path
.
join
(
workspaceBackupPath
,
'
file
'
)),
false
);
});
test
(
'
untitled file
'
,
async
()
=>
{
await
service
.
backup
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
));
assert
.
equal
(
fs
.
readdirSync
(
path
.
join
(
workspaceBackupPath
,
'
untitled
'
)).
length
,
1
);
await
service
.
discardBackups
();
assert
.
equal
(
fs
.
existsSync
(
untitledBackupPath
),
false
);
assert
.
equal
(
fs
.
existsSync
(
path
.
join
(
workspaceBackupPath
,
'
untitled
'
)),
false
);
});
test
(
'
can backup after discarding all
'
,
async
()
=>
{
await
service
.
discardBackups
();
await
service
.
backup
(
untitledFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
));
assert
.
equal
(
fs
.
existsSync
(
workspaceBackupPath
),
true
);
});
});
suite
(
'
getBackups
'
,
()
=>
{
test
(
'
("file") - text file
'
,
async
()
=>
{
await
service
.
backup
(
fooFile
,
createTextBufferFactory
(
'
test
'
).
create
(
DefaultEndOfLine
.
LF
).
createSnapshot
(
false
));
...
...
src/vs/workbench/test/browser/workbenchTestServices.ts
浏览文件 @
52fe5f21
...
...
@@ -811,6 +811,7 @@ export class TestBackupFileService implements IBackupFileService {
getBackups
():
Promise
<
URI
[]
>
{
return
Promise
.
resolve
([]);
}
resolve
<
T
extends
object
>
(
_backup
:
URI
):
Promise
<
IResolvedBackup
<
T
>
|
undefined
>
{
return
Promise
.
resolve
(
undefined
);
}
discardBackup
(
_resource
:
URI
):
Promise
<
void
>
{
return
Promise
.
resolve
();
}
discardBackups
():
Promise
<
void
>
{
return
Promise
.
resolve
();
}
parseBackupContent
(
textBufferFactory
:
ITextBufferFactory
):
string
{
const
textBuffer
=
textBufferFactory
.
create
(
DefaultEndOfLine
.
LF
);
const
lineCount
=
textBuffer
.
getLineCount
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录