Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
34ce3941
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,发现更多精彩内容 >>
提交
34ce3941
编写于
1月 21, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix fdatasync working properly
上级
c7da35f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
24 deletion
+28
-24
src/vs/base/node/extfs.ts
src/vs/base/node/extfs.ts
+25
-19
src/vs/workbench/services/files/node/fileService.ts
src/vs/workbench/services/files/node/fileService.ts
+3
-5
未找到文件。
src/vs/base/node/extfs.ts
浏览文件 @
34ce3941
...
...
@@ -356,14 +356,13 @@ function doWriteFileStreamAndFlush(path: string, reader: NodeJS.ReadableStream,
}
};
// create writer to target
const
writer
=
fs
.
createWriteStream
(
path
,
options
);
// create writer to target. we set autoClose: false because we want to use the streams
// file descriptor to call fs.fdatasync to ensure the data is flushed to disk
const
writer
=
fs
.
createWriteStream
(
path
,
{
mode
:
options
.
mode
,
flags
:
options
.
flag
,
autoClose
:
false
});
// handle errors properly
reader
.
once
(
'
error
'
,
error
=>
finish
(
error
));
writer
.
once
(
'
error
'
,
error
=>
finish
(
error
));
// save the fd for later use
// Event: 'open'
// Purpose: save the fd for later use
// Notes: will not be called when there is an error opening the file descriptor!
let
fd
:
number
;
let
isOpen
:
boolean
;
writer
.
once
(
'
open
'
,
descriptor
=>
{
...
...
@@ -371,11 +370,16 @@ function doWriteFileStreamAndFlush(path: string, reader: NodeJS.ReadableStream,
isOpen
=
true
;
});
// we are done (underlying fd has been closed)
writer
.
once
(
'
close
'
,
()
=>
finish
());
// Event: 'error'
// Purpose: to return the error to the outside and to close the write stream (does not happen automatically)
reader
.
once
(
'
error
'
,
error
=>
finish
(
error
));
writer
.
once
(
'
error
'
,
error
=>
finish
(
error
));
// handle end event because we are in charge
reader
.
once
(
'
end
'
,
()
=>
{
// Event: 'finish'
// Purpose: use fs.fdatasync to flush the contents to disk
// Notes: event is called when the writer has finished writing to the underlying resource. we must call writer.close()
// because we have created the WriteStream with autoClose: false
writer
.
once
(
'
finish
'
,
()
=>
{
// flush to disk
if
(
canFlush
&&
isOpen
)
{
...
...
@@ -388,18 +392,20 @@ function doWriteFileStreamAndFlush(path: string, reader: NodeJS.ReadableStream,
canFlush
=
false
;
}
writer
.
end
();
writer
.
close
();
});
}
// do not flush
else
{
writer
.
end
();
}
else
{
writer
.
close
();
}
});
// end: false means we are in charge of ending the streams properly
reader
.
pipe
(
writer
,
{
end
:
false
});
// Event: 'close'
// Purpose: signal we are done to the outside
// Notes: event is called when the writer's filedescriptor is closed
writer
.
once
(
'
close
'
,
()
=>
finish
());
// start data piping
reader
.
pipe
(
writer
);
}
// Calls fs.writeFile() followed by a fs.sync() call to flush the changes to disk
...
...
src/vs/workbench/services/files/node/fileService.ts
浏览文件 @
34ce3941
...
...
@@ -10,8 +10,7 @@ import fs = require('fs');
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
,
FileChangesEvent
,
ICreateFileOptions
,
IContentData
,
ITextSnapshot
,
snapshotToString
}
from
'
vs/platform/files/common/files
'
;
import
{
isParent
,
FileOperation
,
FileOperationEvent
,
IContent
,
IFileService
,
IResolveFileOptions
,
IResolveFileResult
,
IResolveContentOptions
,
IFileStat
,
IStreamContent
,
FileOperationError
,
FileOperationResult
,
IUpdateContentOptions
,
FileChangeType
,
IImportResult
,
FileChangesEvent
,
ICreateFileOptions
,
IContentData
,
ITextSnapshot
}
from
'
vs/platform/files/common/files
'
;
import
{
MAX_FILE_SIZE
}
from
'
vs/platform/files/node/files
'
;
import
{
isEqualOrParent
}
from
'
vs/base/common/paths
'
;
import
{
ResourceMap
}
from
'
vs/base/common/map
'
;
...
...
@@ -508,8 +507,7 @@ export class FileService implements IFileService {
public
updateContent
(
resource
:
uri
,
value
:
string
|
ITextSnapshot
,
options
:
IUpdateContentOptions
=
Object
.
create
(
null
)):
TPromise
<
IFileStat
>
{
if
(
this
.
options
.
elevationSupport
&&
options
.
writeElevated
)
{
// We can currently only write strings elevated, so we need to convert snapshots properly
return
this
.
doUpdateContentElevated
(
resource
,
typeof
value
===
'
string
'
?
value
:
snapshotToString
(
value
),
options
);
return
this
.
doUpdateContentElevated
(
resource
,
value
,
options
);
}
return
this
.
doUpdateContent
(
resource
,
value
,
options
);
...
...
@@ -635,7 +633,7 @@ export class FileService implements IFileService {
});
}
private
doUpdateContentElevated
(
resource
:
uri
,
value
:
string
,
options
:
IUpdateContentOptions
=
Object
.
create
(
null
)):
TPromise
<
IFileStat
>
{
private
doUpdateContentElevated
(
resource
:
uri
,
value
:
string
|
ITextSnapshot
,
options
:
IUpdateContentOptions
=
Object
.
create
(
null
)):
TPromise
<
IFileStat
>
{
const
absolutePath
=
this
.
toAbsolutePath
(
resource
);
// 1.) check file
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录