Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
65c77591
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,发现更多精彩内容 >>
提交
65c77591
编写于
3月 22, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
files2 - stub a createFile implementation
上级
355021ec
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
6 deletion
+47
-6
src/vs/workbench/services/files2/common/fileService2.ts
src/vs/workbench/services/files2/common/fileService2.ts
+47
-6
未找到文件。
src/vs/workbench/services/files2/common/fileService2.ts
浏览文件 @
65c77591
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
{
Disposable
,
IDisposable
,
toDisposable
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IFileService
,
IResolveFileOptions
,
IResourceEncodings
,
FileChangesEvent
,
FileOperationEvent
,
IFileSystemProviderRegistrationEvent
,
IFileSystemProvider
,
IFileStat
,
IResolveFileResult
,
IResolveContentOptions
,
IContent
,
IStreamContent
,
ITextSnapshot
,
IUpdateContentOptions
,
ICreateFileOptions
,
IFileSystemProviderActivationEvent
,
FileOperationError
,
FileOperationResult
,
FileOperation
,
FileSystemProviderCapabilities
,
FileType
,
toFileSystemProviderErrorCode
,
FileSystemProviderErrorCode
,
IStat
,
IFileStatWithMetadata
,
IResolveMetadataFileOptions
,
etag
,
hasReadWriteCapability
,
hasFileFolderCopyCapability
,
hasOpenReadWriteCloseCapability
}
from
'
vs/platform/files/common/files
'
;
import
{
IFileService
,
IResolveFileOptions
,
IResourceEncodings
,
FileChangesEvent
,
FileOperationEvent
,
IFileSystemProviderRegistrationEvent
,
IFileSystemProvider
,
IFileStat
,
IResolveFileResult
,
IResolveContentOptions
,
IContent
,
IStreamContent
,
ITextSnapshot
,
IUpdateContentOptions
,
ICreateFileOptions
,
IFileSystemProviderActivationEvent
,
FileOperationError
,
FileOperationResult
,
FileOperation
,
FileSystemProviderCapabilities
,
FileType
,
toFileSystemProviderErrorCode
,
FileSystemProviderErrorCode
,
IStat
,
IFileStatWithMetadata
,
IResolveMetadataFileOptions
,
etag
,
hasReadWriteCapability
,
hasFileFolderCopyCapability
,
hasOpenReadWriteCloseCapability
,
toFileOperationResult
}
from
'
vs/platform/files/common/files
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
ServiceIdentifier
}
from
'
vs/platform/instantiation/common/instantiation
'
;
...
...
@@ -279,8 +279,49 @@ export class FileService2 extends Disposable implements IFileService {
return
this
.
_legacy
.
encoding
;
}
createFile
(
resource
:
URI
,
content
?:
string
,
options
?:
ICreateFileOptions
):
Promise
<
IFileStatWithMetadata
>
{
return
this
.
joinOnLegacy
.
then
(
legacy
=>
legacy
.
createFile
(
resource
,
content
,
options
));
async
createFile
(
resource
:
URI
,
content
?:
string
,
options
?:
ICreateFileOptions
):
Promise
<
IFileStatWithMetadata
>
{
const
useLegacy
=
true
;
// can only disable this when encoding is sorted out
if
(
useLegacy
)
{
return
this
.
joinOnLegacy
.
then
(
legacy
=>
legacy
.
createFile
(
resource
,
content
,
options
));
}
const
provider
=
this
.
throwIfFileSystemIsReadonly
(
await
this
.
withProvider
(
resource
));
// validate overwrite
const
overwrite
=
!!
(
options
&&
options
.
overwrite
);
if
(
!
overwrite
&&
await
this
.
existsFile
(
resource
))
{
throw
new
FileOperationError
(
localize
(
'
fileExists
'
,
"
File to create already exists ({0})
"
,
resource
.
toString
(
true
)),
FileOperationResult
.
FILE_MODIFIED_SINCE
,
options
);
}
try
{
// mkdir recursively
await
this
.
mkdirp
(
provider
,
dirname
(
resource
));
// create file: buffered
if
(
hasOpenReadWriteCloseCapability
(
provider
))
{
// TODO@ben revisit stream support
return
this
.
joinOnLegacy
.
then
(
legacy
=>
legacy
.
createFile
(
resource
,
content
,
options
));
}
// create file: unbuffered
else
if
(
hasReadWriteCapability
(
provider
))
{
await
provider
.
writeFile
(
resource
,
new
Uint8Array
(
0
),
{
create
:
true
,
overwrite
});
}
// give up if provider has insufficient capabilities
else
{
return
Promise
.
reject
(
'
Provider neither has FileReadWrite nor FileOpenReadWriteClose capability which is needed to support creating a file.
'
);
}
}
catch
(
error
)
{
throw
new
FileOperationError
(
localize
(
'
err.create
'
,
"
Failed to create file {0}
"
,
resource
.
toString
(
false
)),
toFileOperationResult
(
error
),
options
);
}
// events
const
fileStat
=
await
this
.
resolveFile
(
resource
,
{
resolveMetadata
:
true
});
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
CREATE
,
fileStat
));
return
fileStat
;
}
resolveContent
(
resource
:
URI
,
options
?:
IResolveContentOptions
):
Promise
<
IContent
>
{
...
...
@@ -336,17 +377,17 @@ export class FileService2 extends Disposable implements IFileService {
// copy source => target
if
(
mode
===
'
copy
'
)
{
// c
heck if provider supports fast file/folder copy
// c
opy: fast path
if
(
hasFileFolderCopyCapability
(
provider
))
{
return
provider
.
copy
(
source
,
target
,
{
overwrite
:
!!
overwrite
});
}
//
otherwise we need to manually copy: via read/write
//
copy: buffered
if
(
hasOpenReadWriteCloseCapability
(
provider
))
{
return
this
.
joinOnLegacy
.
then
(
legacy
=>
legacy
.
copyFile
(
source
,
target
,
overwrite
)).
then
(()
=>
undefined
);
}
//
otherwise we need to manually copy: via readFile/writeFile
//
copy: unbuffered
if
(
hasReadWriteCapability
(
provider
))
{
return
provider
.
writeFile
(
target
,
await
provider
.
readFile
(
source
),
{
create
:
true
,
overwrite
:
!!
overwrite
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录