Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
1558036e
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1558036e
编写于
11月 10, 2016
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Shuffle BackupMainService around
上级
b91bde29
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
81 addition
and
78 deletion
+81
-78
src/vs/code/electron-main/lifecycle.ts
src/vs/code/electron-main/lifecycle.ts
+1
-1
src/vs/code/electron-main/main.ts
src/vs/code/electron-main/main.ts
+3
-2
src/vs/code/electron-main/window.ts
src/vs/code/electron-main/window.ts
+1
-1
src/vs/code/electron-main/windows.ts
src/vs/code/electron-main/windows.ts
+1
-1
src/vs/platform/backup/common/backup.ts
src/vs/platform/backup/common/backup.ts
+47
-0
src/vs/platform/backup/node/backupMainService.ts
src/vs/platform/backup/node/backupMainService.ts
+2
-47
src/vs/platform/backup/test/node/backupMainService.test.ts
src/vs/platform/backup/test/node/backupMainService.test.ts
+26
-26
未找到文件。
src/vs/code/electron-main/lifecycle.ts
浏览文件 @
1558036e
...
...
@@ -12,7 +12,7 @@ import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import
{
ReadyState
,
VSCodeWindow
}
from
'
vs/code/electron-main/window
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IBackupMainService
}
from
'
vs/platform/backup/
node
/backup
'
;
import
{
IBackupMainService
}
from
'
vs/platform/backup/
common
/backup
'
;
import
{
ILogService
}
from
'
vs/code/electron-main/log
'
;
import
{
IStorageService
}
from
'
vs/code/electron-main/storage
'
;
...
...
src/vs/code/electron-main/main.ts
浏览文件 @
1558036e
...
...
@@ -34,7 +34,8 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import
{
SyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
import
{
ILogService
,
MainLogService
}
from
'
vs/code/electron-main/log
'
;
import
{
IStorageService
,
StorageService
}
from
'
vs/code/electron-main/storage
'
;
import
{
IBackupMainService
,
BackupService
}
from
'
vs/platform/backup/node/backup
'
;
import
{
IBackupMainService
}
from
'
vs/platform/backup/common/backup
'
;
import
{
BackupMainService
}
from
'
vs/platform/backup/node/backupMainService
'
;
import
{
IEnvironmentService
,
ParsedArgs
}
from
'
vs/platform/environment/common/environment
'
;
import
{
EnvironmentService
}
from
'
vs/platform/environment/node/environmentService
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
...
...
@@ -427,7 +428,7 @@ function createServices(args): IInstantiationService {
services
.
set
(
IConfigurationService
,
new
SyncDescriptor
(
ConfigurationService
));
services
.
set
(
IRequestService
,
new
SyncDescriptor
(
RequestService
));
services
.
set
(
IURLService
,
new
SyncDescriptor
(
URLService
,
args
[
'
open-url
'
]));
services
.
set
(
IBackupMainService
,
new
SyncDescriptor
(
BackupService
));
services
.
set
(
IBackupMainService
,
new
SyncDescriptor
(
Backup
Main
Service
));
return
new
InstantiationService
(
services
,
true
);
}
...
...
src/vs/code/electron-main/window.ts
浏览文件 @
1558036e
...
...
@@ -17,7 +17,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import
{
parseArgs
}
from
'
vs/platform/environment/node/argv
'
;
import
product
from
'
vs/platform/product
'
;
import
{
getCommonHTTPHeaders
}
from
'
vs/platform/environment/node/http
'
;
import
{
IBackupMainService
}
from
'
vs/platform/backup/
node
/backup
'
;
import
{
IBackupMainService
}
from
'
vs/platform/backup/
common
/backup
'
;
import
Uri
from
'
vs/base/common/uri
'
;
export
interface
IWindowState
{
...
...
src/vs/code/electron-main/windows.ts
浏览文件 @
1558036e
...
...
@@ -14,7 +14,7 @@ import * as paths from 'vs/base/common/paths';
import
*
as
types
from
'
vs/base/common/types
'
;
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
{
assign
,
mixin
}
from
'
vs/base/common/objects
'
;
import
{
IBackupMainService
}
from
'
vs/platform/backup/
node
/backup
'
;
import
{
IBackupMainService
}
from
'
vs/platform/backup/
common
/backup
'
;
import
{
trim
}
from
'
vs/base/common/strings
'
;
import
{
IEnvironmentService
,
ParsedArgs
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IStorageService
}
from
'
vs/code/electron-main/storage
'
;
...
...
src/vs/platform/backup/common/backup.ts
浏览文件 @
1558036e
...
...
@@ -3,6 +3,53 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Uri
from
'
vs/base/common/uri
'
;
export
interface
IBackupWorkspacesFormat
{
folderWorkspaces
:
string
[];
}
export
const
IBackupMainService
=
createDecorator
<
IBackupMainService
>
(
'
backupService
'
);
export
interface
IBackupMainService
{
_serviceBrand
:
any
;
/**
* Gets the set of active workspace backup paths being tracked for restoration.
*
* @return The set of active workspace backup paths being tracked for restoration.
*/
getWorkspaceBackupPaths
():
string
[];
/**
* Pushes workspace backup paths to be tracked for restoration.
*
* @param workspaces The workspaces to add.
*/
pushWorkspaceBackupPathsSync
(
workspaces
:
Uri
[]):
void
;
/**
* Removes a workspace backup path being tracked for restoration.
*
* @param workspace The workspace to remove.
*/
removeWorkspaceBackupPathSync
(
workspace
:
Uri
):
void
;
/**
* Gets the set of untitled file backups for a particular workspace.
*
* @param workspace The workspace to get the backups for.
* @return The absolute paths for all the untitled file _backups_.
*/
getWorkspaceUntitledFileBackupsSync
(
workspace
:
Uri
):
string
[];
/**
* Gets whether the workspace has backup(s) associated with it (ie. if the workspace backup
* directory exists).
*
* @param workspace The workspace to evaluate.
* @return Whether the workspace has backups.
*/
hasWorkspaceBackup
(
workspace
:
Uri
):
boolean
;
}
src/vs/platform/backup/node/backup.ts
→
src/vs/platform/backup/node/backup
MainService
.ts
浏览文件 @
1558036e
...
...
@@ -8,55 +8,10 @@ import * as fs from 'fs';
import
*
as
path
from
'
path
'
;
import
Uri
from
'
vs/base/common/uri
'
;
import
{
readdirSync
}
from
'
vs/base/node/extfs
'
;
import
{
IBackupWorkspacesFormat
}
from
'
vs/platform/backup/common/backup
'
;
import
{
IBackupWorkspacesFormat
,
IBackupMainService
}
from
'
vs/platform/backup/common/backup
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
export
const
IBackupMainService
=
createDecorator
<
IBackupMainService
>
(
'
backupService
'
);
export
interface
IBackupMainService
{
_serviceBrand
:
any
;
/**
* Gets the set of active workspace backup paths being tracked for restoration.
*
* @return The set of active workspace backup paths being tracked for restoration.
*/
getWorkspaceBackupPaths
():
string
[];
/**
* Pushes workspace backup paths to be tracked for restoration.
*
* @param workspaces The workspaces to add.
*/
pushWorkspaceBackupPathsSync
(
workspaces
:
Uri
[]):
void
;
/**
* Removes a workspace backup path being tracked for restoration.
*
* @param workspace The workspace to remove.
*/
removeWorkspaceBackupPathSync
(
workspace
:
Uri
):
void
;
/**
* Gets the set of untitled file backups for a particular workspace.
*
* @param workspace The workspace to get the backups for.
* @return The absolute paths for all the untitled file _backups_.
*/
getWorkspaceUntitledFileBackupsSync
(
workspace
:
Uri
):
string
[];
/**
* Gets whether the workspace has backup(s) associated with it (ie. if the workspace backup
* directory exists).
*
* @param workspace The workspace to evaluate.
* @return Whether the workspace has backups.
*/
hasWorkspaceBackup
(
workspace
:
Uri
):
boolean
;
}
export
class
BackupService
implements
IBackupMainService
{
export
class
Backup
Main
Service
implements
IBackupMainService
{
public
_serviceBrand
:
any
;
...
...
src/vs/platform/backup/test/node/backup.test.ts
→
src/vs/platform/backup/test/node/backup
MainService
.test.ts
浏览文件 @
1558036e
...
...
@@ -15,10 +15,10 @@ import extfs = require('vs/base/node/extfs');
import
pfs
=
require
(
'
vs/base/node/pfs
'
);
import
Uri
from
'
vs/base/common/uri
'
;
import
{
TestEnvironmentService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
Backup
Service
}
from
'
vs/platform/backup/node/backup
'
;
import
{
Backup
MainService
}
from
'
vs/platform/backup/node/backupMainService
'
;
import
{
IBackupWorkspacesFormat
}
from
'
vs/platform/backup/common/backup
'
;
class
TestBackup
Service
extends
Backup
Service
{
class
TestBackup
MainService
extends
BackupMain
Service
{
constructor
(
backupHome
:
string
,
backupWorkspacesPath
:
string
)
{
super
(
TestEnvironmentService
);
...
...
@@ -30,7 +30,7 @@ class TestBackupService extends BackupService {
}
}
suite
(
'
BackupService
'
,
()
=>
{
suite
(
'
Backup
Main
Service
'
,
()
=>
{
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
'
service
'
);
const
backupHome
=
path
.
join
(
parentDir
,
'
Backups
'
);
const
backupWorkspacesPath
=
path
.
join
(
backupHome
,
'
workspaces.json
'
);
...
...
@@ -40,10 +40,10 @@ suite('BackupService', () => {
const
fooWorkspaceBackupDir
=
path
.
join
(
backupHome
,
crypto
.
createHash
(
'
md5
'
).
update
(
fooFile
.
fsPath
).
digest
(
'
hex
'
));
let
backupService
:
Backup
Service
;
let
service
:
BackupMain
Service
;
setup
(
done
=>
{
backupService
=
new
TestBackup
Service
(
backupHome
,
backupWorkspacesPath
);
service
=
new
TestBackupMain
Service
(
backupHome
,
backupWorkspacesPath
);
// Delete any existing backups completely and then re-create it.
extfs
.
del
(
backupHome
,
os
.
tmpdir
(),
()
=>
{
...
...
@@ -58,41 +58,41 @@ suite('BackupService', () => {
});
test
(
'
getWorkspaceBackupPathsSync should return [] when workspaces.json doesn
\'
t exist
'
,
()
=>
{
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
});
test
(
'
getWorkspaceBackupPathsSync should return [] when workspaces.json is not properly formed JSON
'
,
()
=>
{
fs
.
writeFileSync
(
backupWorkspacesPath
,
''
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{]
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
foo
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
});
test
(
'
getWorkspaceBackupPathsSync should return [] when folderWorkspaces in workspaces.json is absent
'
,
()
=>
{
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{}
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
});
test
(
'
getWorkspaceBackupPathsSync should return [] when folderWorkspaces in workspaces.json is not a string array
'
,
()
=>
{
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"folderWorkspaces":{}}
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"folderWorkspaces":{"foo": ["bar"]}}
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"folderWorkspaces":{"foo": []}}
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"folderWorkspaces":{"foo": "bar"}}
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"folderWorkspaces":"foo"}
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"folderWorkspaces":1}
'
);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[]);
});
test
(
'
pushWorkspaceBackupPathsSync should persist paths to workspaces.json
'
,
()
=>
{
backupS
ervice
.
pushWorkspaceBackupPathsSync
([
fooFile
,
barFile
]);
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceBackupPaths
(),
[
fooFile
.
fsPath
,
barFile
.
fsPath
]);
s
ervice
.
pushWorkspaceBackupPathsSync
([
fooFile
,
barFile
]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceBackupPaths
(),
[
fooFile
.
fsPath
,
barFile
.
fsPath
]);
});
test
(
'
getWorkspaceUntitledFileBackupsSync should return untitled file backup resources
'
,
done
=>
{
...
...
@@ -101,9 +101,9 @@ suite('BackupService', () => {
const
untitledBackup2
=
path
.
join
(
untitledBackupDir
,
'
foo
'
);
pfs
.
mkdirp
(
untitledBackupDir
).
then
(()
=>
{
pfs
.
writeFile
(
untitledBackup1
,
'
test
'
).
then
(()
=>
{
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceUntitledFileBackupsSync
(
fooFile
),
[
untitledBackup1
]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceUntitledFileBackupsSync
(
fooFile
),
[
untitledBackup1
]);
pfs
.
writeFile
(
untitledBackup2
,
'
test
'
).
then
(()
=>
{
assert
.
deepEqual
(
backupS
ervice
.
getWorkspaceUntitledFileBackupsSync
(
fooFile
),
[
untitledBackup1
,
untitledBackup2
]);
assert
.
deepEqual
(
s
ervice
.
getWorkspaceUntitledFileBackupsSync
(
fooFile
),
[
untitledBackup1
,
untitledBackup2
]);
done
();
});
});
...
...
@@ -111,12 +111,12 @@ suite('BackupService', () => {
});
test
(
'
removeWorkspaceBackupPath should remove workspaces from workspaces.json
'
,
done
=>
{
backupS
ervice
.
pushWorkspaceBackupPathsSync
([
fooFile
,
barFile
]);
backupS
ervice
.
removeWorkspaceBackupPathSync
(
fooFile
);
s
ervice
.
pushWorkspaceBackupPathsSync
([
fooFile
,
barFile
]);
s
ervice
.
removeWorkspaceBackupPathSync
(
fooFile
);
pfs
.
readFile
(
backupWorkspacesPath
,
'
utf-8
'
).
then
(
buffer
=>
{
const
json
=
<
IBackupWorkspacesFormat
>
JSON
.
parse
(
buffer
);
assert
.
deepEqual
(
json
.
folderWorkspaces
,
[
barFile
.
fsPath
]);
backupS
ervice
.
removeWorkspaceBackupPathSync
(
barFile
);
s
ervice
.
removeWorkspaceBackupPathSync
(
barFile
);
pfs
.
readFile
(
backupWorkspacesPath
,
'
utf-8
'
).
then
(
content
=>
{
const
json2
=
<
IBackupWorkspacesFormat
>
JSON
.
parse
(
content
);
assert
.
deepEqual
(
json2
.
folderWorkspaces
,
[]);
...
...
@@ -128,7 +128,7 @@ suite('BackupService', () => {
test
(
'
removeWorkspaceBackupPath should fail gracefully when removing a path that doesn
\'
t exist
'
,
done
=>
{
const
workspacesJson
:
IBackupWorkspacesFormat
=
{
folderWorkspaces
:
[
fooFile
.
fsPath
]
};
pfs
.
writeFileAndFlush
(
backupWorkspacesPath
,
JSON
.
stringify
(
workspacesJson
)).
then
(()
=>
{
backupS
ervice
.
removeWorkspaceBackupPathSync
(
barFile
);
s
ervice
.
removeWorkspaceBackupPathSync
(
barFile
);
pfs
.
readFile
(
backupWorkspacesPath
,
'
utf-8
'
).
then
(
content
=>
{
const
json
=
<
IBackupWorkspacesFormat
>
JSON
.
parse
(
content
);
assert
.
deepEqual
(
json
.
folderWorkspaces
,
[
fooFile
.
fsPath
]);
...
...
@@ -138,8 +138,8 @@ suite('BackupService', () => {
});
test
(
'
doesWorkspaceHaveBackups should return whether the workspace
\'
s backup exists
'
,
()
=>
{
assert
.
equal
(
backupS
ervice
.
hasWorkspaceBackup
(
fooFile
),
false
);
assert
.
equal
(
s
ervice
.
hasWorkspaceBackup
(
fooFile
),
false
);
fs
.
mkdirSync
(
fooWorkspaceBackupDir
);
assert
.
equal
(
backupS
ervice
.
hasWorkspaceBackup
(
fooFile
),
true
);
assert
.
equal
(
s
ervice
.
hasWorkspaceBackup
(
fooFile
),
true
);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录