Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
7683db24
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,体验更适合开发者的 AI 搜索 >>
提交
7683db24
编写于
9月 15, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create File overwrites existing files without warning (fixes #33899)
上级
b0c06343
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
15 deletion
+81
-15
src/vs/platform/files/common/files.ts
src/vs/platform/files/common/files.ts
+10
-1
src/vs/workbench/services/files/electron-browser/fileService.ts
.../workbench/services/files/electron-browser/fileService.ts
+3
-3
src/vs/workbench/services/files/node/fileService.ts
src/vs/workbench/services/files/node/fileService.ts
+27
-9
src/vs/workbench/services/files/test/node/fileService.test.ts
...vs/workbench/services/files/test/node/fileService.test.ts
+39
-0
src/vs/workbench/test/workbenchTestServices.ts
src/vs/workbench/test/workbenchTestServices.ts
+2
-2
未找到文件。
src/vs/platform/files/common/files.ts
浏览文件 @
7683db24
...
...
@@ -93,7 +93,7 @@ export interface IFileService {
*
* The optional parameter content can be used as value to fill into the new file.
*/
createFile
(
resource
:
URI
,
content
?:
string
):
TPromise
<
IFileStat
>
;
createFile
(
resource
:
URI
,
content
?:
string
,
options
?:
ICreateFileOptions
):
TPromise
<
IFileStat
>
;
/**
* Creates a new folder with the given path. The returned promise
...
...
@@ -491,6 +491,15 @@ export interface IResolveFileOptions {
resolveSingleChildDescendants
?:
boolean
;
}
export
interface
ICreateFileOptions
{
/**
* Overwrite the file to create if it already exists on disk. Otherwise
* an error will be thrown (FILE_MODIFIED_SINCE).
*/
overwrite
?:
boolean
;
}
export
interface
IImportResult
{
stat
:
IFileStat
;
isNew
:
boolean
;
...
...
src/vs/workbench/services/files/electron-browser/fileService.ts
浏览文件 @
7683db24
...
...
@@ -12,7 +12,7 @@ import encoding = require('vs/base/node/encoding');
import
errors
=
require
(
'
vs/base/common/errors
'
);
import
uri
from
'
vs/base/common/uri
'
;
import
{
toResource
}
from
'
vs/workbench/common/editor
'
;
import
{
FileOperation
,
FileOperationEvent
,
IFileService
,
IFilesConfiguration
,
IResolveFileOptions
,
IFileStat
,
IResolveFileResult
,
IContent
,
IStreamContent
,
IImportResult
,
IResolveContentOptions
,
IUpdateContentOptions
,
FileChangesEvent
}
from
'
vs/platform/files/common/files
'
;
import
{
FileOperation
,
FileOperationEvent
,
IFileService
,
IFilesConfiguration
,
IResolveFileOptions
,
IFileStat
,
IResolveFileResult
,
IContent
,
IStreamContent
,
IImportResult
,
IResolveContentOptions
,
IUpdateContentOptions
,
FileChangesEvent
,
ICreateFileOptions
}
from
'
vs/platform/files/common/files
'
;
import
{
FileService
as
NodeFileService
,
IFileServiceOptions
,
IEncodingOverride
}
from
'
vs/workbench/services/files/node/fileService
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
...
...
@@ -224,8 +224,8 @@ export class FileService implements IFileService {
return
this
.
raw
.
copyFile
(
source
,
target
,
overwrite
);
}
public
createFile
(
resource
:
uri
,
content
?:
string
):
TPromise
<
IFileStat
>
{
return
this
.
raw
.
createFile
(
resource
,
content
);
public
createFile
(
resource
:
uri
,
content
?:
string
,
options
?:
ICreateFileOptions
):
TPromise
<
IFileStat
>
{
return
this
.
raw
.
createFile
(
resource
,
content
,
options
);
}
public
createFolder
(
resource
:
uri
):
TPromise
<
IFileStat
>
{
...
...
src/vs/workbench/services/files/node/fileService.ts
浏览文件 @
7683db24
...
...
@@ -11,7 +11,7 @@ import os = require('os');
import
crypto
=
require
(
'
crypto
'
);
import
assert
=
require
(
'
assert
'
);
import
{
isParent
,
FileOperation
,
FileOperationEvent
,
IContent
,
IFileService
,
IResolveFileOptions
,
IResolveFileResult
,
IResolveContentOptions
,
IFileStat
,
IStreamContent
,
FileOperationError
,
FileOperationResult
,
IUpdateContentOptions
,
FileChangeType
,
IImportResult
,
MAX_FILE_SIZE
,
FileChangesEvent
,
IFilesConfiguration
}
from
'
vs/platform/files/common/files
'
;
import
{
isParent
,
FileOperation
,
FileOperationEvent
,
IContent
,
IFileService
,
IResolveFileOptions
,
IResolveFileResult
,
IResolveContentOptions
,
IFileStat
,
IStreamContent
,
FileOperationError
,
FileOperationResult
,
IUpdateContentOptions
,
FileChangeType
,
IImportResult
,
MAX_FILE_SIZE
,
FileChangesEvent
,
IFilesConfiguration
,
ICreateFileOptions
}
from
'
vs/platform/files/common/files
'
;
import
{
isEqualOrParent
}
from
'
vs/base/common/paths
'
;
import
{
ResourceMap
}
from
'
vs/base/common/map
'
;
import
arrays
=
require
(
'
vs/base/common/arrays
'
);
...
...
@@ -220,7 +220,7 @@ export class FileService implements IFileService {
// Guard early against attempts to resolve an invalid file path
if
(
resource
.
scheme
!==
'
file
'
||
!
resource
.
fsPath
)
{
return
TPromise
.
wrapError
<
IStreamContent
>
(
new
FileOperationError
(
nls
.
localize
(
'
fileInvalidPath
'
,
"
Invalid file resource ({0})
"
,
resource
.
toString
()),
nls
.
localize
(
'
fileInvalidPath
'
,
"
Invalid file resource ({0})
"
,
resource
.
toString
(
true
)),
FileOperationResult
.
FILE_INVALID_PATH
));
}
...
...
@@ -292,7 +292,7 @@ export class FileService implements IFileService {
// Return if file not found
if
(
!
exists
)
{
return
TPromise
.
wrapError
<
IStreamContent
>
(
new
FileOperationError
(
nls
.
localize
(
'
fileNotFoundError
'
,
"
File not found ({0})
"
,
resource
.
toString
()),
nls
.
localize
(
'
fileNotFoundError
'
,
"
File not found ({0})
"
,
resource
.
toString
(
true
)),
FileOperationResult
.
FILE_NOT_FOUND
));
}
...
...
@@ -381,15 +381,33 @@ export class FileService implements IFileService {
});
}
public
createFile
(
resource
:
uri
,
content
:
string
=
''
):
TPromise
<
IFileStat
>
{
public
createFile
(
resource
:
uri
,
content
:
string
=
''
,
options
:
ICreateFileOptions
=
Object
.
create
(
null
)):
TPromise
<
IFileStat
>
{
const
absolutePath
=
this
.
toAbsolutePath
(
resource
);
// Create file
return
this
.
updateContent
(
resource
,
content
).
then
(
result
=>
{
let
checkFilePromise
:
TPromise
<
boolean
>
;
if
(
options
.
overwrite
)
{
checkFilePromise
=
TPromise
.
as
(
false
);
}
else
{
checkFilePromise
=
pfs
.
exists
(
absolutePath
);
}
// Events
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
CREATE
,
result
));
// Check file exists
return
checkFilePromise
.
then
(
exists
=>
{
if
(
exists
&&
!
options
.
overwrite
)
{
return
TPromise
.
wrapError
<
IFileStat
>
(
new
FileOperationError
(
nls
.
localize
(
'
fileExists
'
,
"
File to create already exits ({0})
"
,
resource
.
toString
(
true
)),
FileOperationResult
.
FILE_MODIFIED_SINCE
));
}
return
result
;
// Create file
return
this
.
updateContent
(
resource
,
content
).
then
(
result
=>
{
// Events
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
CREATE
,
result
));
return
result
;
});
});
}
...
...
src/vs/workbench/services/files/test/node/fileService.test.ts
浏览文件 @
7683db24
...
...
@@ -71,6 +71,45 @@ suite('FileService', () => {
},
error
=>
onError
(
error
,
done
));
});
test
(
'
createFile (does not overwrite by default)
'
,
function
(
done
:
()
=>
void
)
{
const
contents
=
'
Hello World
'
;
const
resource
=
uri
.
file
(
path
.
join
(
testDir
,
'
test.txt
'
));
fs
.
writeFileSync
(
resource
.
fsPath
,
''
);
// create file
service
.
createFile
(
resource
,
contents
).
done
(
null
,
error
=>
{
assert
.
ok
(
error
);
done
();
});
});
test
(
'
createFile (allows to overwrite existing)
'
,
function
(
done
:
()
=>
void
)
{
let
event
:
FileOperationEvent
;
const
toDispose
=
service
.
onAfterOperation
(
e
=>
{
event
=
e
;
});
const
contents
=
'
Hello World
'
;
const
resource
=
uri
.
file
(
path
.
join
(
testDir
,
'
test.txt
'
));
fs
.
writeFileSync
(
resource
.
fsPath
,
''
);
// create file
service
.
createFile
(
resource
,
contents
,
{
overwrite
:
true
}).
done
(
s
=>
{
assert
.
equal
(
s
.
name
,
'
test.txt
'
);
assert
.
equal
(
fs
.
existsSync
(
s
.
resource
.
fsPath
),
true
);
assert
.
equal
(
fs
.
readFileSync
(
s
.
resource
.
fsPath
),
contents
);
assert
.
ok
(
event
);
assert
.
equal
(
event
.
resource
.
fsPath
,
resource
.
fsPath
);
assert
.
equal
(
event
.
operation
,
FileOperation
.
CREATE
);
assert
.
equal
(
event
.
target
.
resource
.
fsPath
,
resource
.
fsPath
);
toDispose
.
dispose
();
done
();
},
error
=>
onError
(
error
,
done
));
});
test
(
'
createFolder
'
,
function
(
done
:
()
=>
void
)
{
let
event
:
FileOperationEvent
;
const
toDispose
=
service
.
onAfterOperation
(
e
=>
{
...
...
src/vs/workbench/test/workbenchTestServices.ts
浏览文件 @
7683db24
...
...
@@ -34,7 +34,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
import
{
IEditorGroupService
,
GroupArrangement
,
GroupOrientation
,
IEditorTabOptions
,
IMoveOptions
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
TextFileService
}
from
'
vs/workbench/services/textfile/common/textFileService
'
;
import
{
FileOperationEvent
,
IFileService
,
IResolveContentOptions
,
FileOperationError
,
IFileStat
,
IResolveFileResult
,
IImportResult
,
FileChangesEvent
,
IResolveFileOptions
,
IContent
,
IUpdateContentOptions
,
IStreamContent
}
from
'
vs/platform/files/common/files
'
;
import
{
FileOperationEvent
,
IFileService
,
IResolveContentOptions
,
FileOperationError
,
IFileStat
,
IResolveFileResult
,
IImportResult
,
FileChangesEvent
,
IResolveFileOptions
,
IContent
,
IUpdateContentOptions
,
IStreamContent
,
ICreateFileOptions
}
from
'
vs/platform/files/common/files
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
ModeServiceImpl
}
from
'
vs/editor/common/services/modeServiceImpl
'
;
import
{
ModelServiceImpl
}
from
'
vs/editor/common/services/modelServiceImpl
'
;
...
...
@@ -749,7 +749,7 @@ export class TestFileService implements IFileService {
return
TPromise
.
as
(
null
);
}
createFile
(
resource
:
URI
,
content
?:
string
):
TPromise
<
IFileStat
>
{
createFile
(
resource
:
URI
,
content
?:
string
,
options
?:
ICreateFileOptions
):
TPromise
<
IFileStat
>
{
return
TPromise
.
as
(
null
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录