Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
51108dd8
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,发现更多精彩内容 >>
提交
51108dd8
编写于
11月 29, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
💄
上级
092718c5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
14 deletion
+17
-14
src/vs/workbench/services/backup/node/backupFileService.ts
src/vs/workbench/services/backup/node/backupFileService.ts
+12
-8
src/vs/workbench/services/backup/test/backupFileService.test.ts
.../workbench/services/backup/test/backupFileService.test.ts
+5
-5
src/vs/workbench/services/textfile/common/textFileEditorModel.ts
...workbench/services/textfile/common/textFileEditorModel.ts
+0
-1
未找到文件。
src/vs/workbench/services/backup/node/backupFileService.ts
浏览文件 @
51108dd8
...
...
@@ -21,12 +21,11 @@ export interface IBackupFilesModel {
add
(
resource
:
Uri
,
versionId
?:
number
):
void
;
has
(
resource
:
Uri
,
versionId
?:
number
):
boolean
;
get
(
scheme
:
string
):
Uri
[];
remove
(
resource
:
Uri
):
void
;
clear
():
void
;
getFilesByScheme
(
scheme
:
string
):
Uri
[];
}
// TODO@daniel this should resolve the backups with their file names once we have the metadata in place
export
class
BackupFilesModel
implements
IBackupFilesModel
{
private
cache
:
{
[
resource
:
string
]:
number
/* version ID */
}
=
Object
.
create
(
null
);
...
...
@@ -67,7 +66,7 @@ export class BackupFilesModel implements IBackupFilesModel {
return
true
;
}
public
get
FilesByScheme
(
scheme
:
string
):
Uri
[]
{
public
get
(
scheme
:
string
):
Uri
[]
{
return
Object
.
keys
(
this
.
cache
).
filter
(
k
=>
path
.
basename
(
path
.
dirname
(
k
))
===
scheme
).
map
(
k
=>
Uri
.
parse
(
k
));
}
...
...
@@ -84,6 +83,8 @@ export class BackupFileService implements IBackupFileService {
public
_serviceBrand
:
any
;
private
static
readonly
META_MARKER
=
'
\n
'
;
protected
backupHome
:
string
;
protected
workspacesJsonPath
:
string
;
...
...
@@ -155,7 +156,7 @@ export class BackupFileService implements IBackupFileService {
}
// Add metadata to top of file
content
=
`
${
resource
.
toString
()}
\n
${
content
}
`
;
content
=
`
${
resource
.
toString
()}
${
BackupFileService
.
META_MARKER
}
${
content
}
`
;
return
this
.
fileService
.
updateContent
(
backupResource
,
content
,
BACKUP_FILE_UPDATE_OPTIONS
).
then
(()
=>
model
.
add
(
backupResource
,
versionId
));
});
...
...
@@ -184,23 +185,26 @@ export class BackupFileService implements IBackupFileService {
public
getWorkspaceFileBackups
(
scheme
:
string
):
TPromise
<
Uri
[]
>
{
return
this
.
ready
.
then
(
model
=>
{
let
readPromises
:
TPromise
<
Uri
>
[]
=
[];
model
.
getFilesByScheme
(
scheme
).
forEach
(
textFile
=>
{
const
readPromises
:
TPromise
<
Uri
>
[]
=
[];
model
.
get
(
scheme
).
forEach
(
fileBackup
=>
{
readPromises
.
push
(
new
TPromise
<
Uri
>
((
c
,
e
)
=>
{
readToMatchingString
(
textFile
.
fsPath
,
'
\n
'
,
2000
,
10000
,
(
error
,
result
)
=>
{
readToMatchingString
(
fileBackup
.
fsPath
,
BackupFileService
.
META_MARKER
,
2000
,
10000
,
(
error
,
result
)
=>
{
if
(
result
===
null
)
{
e
(
error
);
}
c
(
Uri
.
parse
(
result
));
});
}));
});
return
TPromise
.
join
(
readPromises
);
});
}
public
parseBackupContent
(
rawText
:
IRawTextContent
):
string
{
return
rawText
.
value
.
lines
.
slice
(
1
).
join
(
'
\n
'
);
return
rawText
.
value
.
lines
.
slice
(
1
).
join
(
'
\n
'
);
// The first line of a backup text file is the file name
}
protected
getBackupResource
(
resource
:
Uri
):
Uri
{
...
...
src/vs/workbench/services/backup/test/backupFileService.test.ts
浏览文件 @
51108dd8
...
...
@@ -290,11 +290,11 @@ suite('BackupFileService', () => {
});
});
test
(
'
BackupFilesModel - get
FilesByScheme
'
,
()
=>
{
test
(
'
BackupFilesModel - get
'
,
()
=>
{
const
model
=
new
BackupFilesModel
();
assert
.
deepEqual
(
model
.
get
FilesByScheme
(
'
file
'
),
[]);
assert
.
deepEqual
(
model
.
get
FilesByScheme
(
'
untitled
'
),
[]);
assert
.
deepEqual
(
model
.
get
(
'
file
'
),
[]);
assert
.
deepEqual
(
model
.
get
(
'
untitled
'
),
[]);
const
file1
=
Uri
.
file
(
'
/root/file/foo.html
'
);
const
file2
=
Uri
.
file
(
'
/root/file/bar.html
'
);
...
...
@@ -304,7 +304,7 @@ suite('BackupFileService', () => {
model
.
add
(
file2
);
model
.
add
(
untitled
);
assert
.
deepEqual
(
model
.
get
FilesByScheme
(
'
file
'
).
map
(
f
=>
f
.
fsPath
),
[
file1
.
fsPath
,
file2
.
fsPath
]);
assert
.
deepEqual
(
model
.
get
FilesByScheme
(
'
untitled
'
).
map
(
f
=>
f
.
fsPath
),
[
untitled
.
fsPath
]);
assert
.
deepEqual
(
model
.
get
(
'
file
'
).
map
(
f
=>
f
.
fsPath
),
[
file1
.
fsPath
,
file2
.
fsPath
]);
assert
.
deepEqual
(
model
.
get
(
'
untitled
'
).
map
(
f
=>
f
.
fsPath
),
[
untitled
.
fsPath
]);
});
});
\ No newline at end of file
src/vs/workbench/services/textfile/common/textFileEditorModel.ts
浏览文件 @
51108dd8
...
...
@@ -295,7 +295,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
// Try get restore content, if there is an issue fallback silently to the original file's content
if
(
backupResource
)
{
resolveBackupPromise
=
this
.
textFileService
.
resolveTextContent
(
backupResource
,
BACKUP_FILE_RESOLVE_OPTIONS
).
then
(
backup
=>
{
// The first line of a backup text file is the file name
return
this
.
backupFileService
.
parseBackupContent
(
backup
);
},
error
=>
content
.
value
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录