Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
974bce45
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,发现更多精彩内容 >>
提交
974bce45
编写于
8月 09, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Save: Flush to disk after writing to file (fixes #9589)
上级
6dd65cc0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
83 addition
and
17 deletion
+83
-17
src/typings/node.d.ts
src/typings/node.d.ts
+5
-3
src/vs/base/node/extfs.ts
src/vs/base/node/extfs.ts
+32
-0
src/vs/base/node/pfs.ts
src/vs/base/node/pfs.ts
+6
-0
src/vs/base/test/node/extfs/extfs.test.ts
src/vs/base/test/node/extfs/extfs.test.ts
+38
-12
src/vs/workbench/services/files/node/fileService.ts
src/vs/workbench/services/files/node/fileService.ts
+2
-2
未找到文件。
src/typings/node.d.ts
浏览文件 @
974bce45
...
...
@@ -1442,6 +1442,8 @@ declare module "fs" {
export
function
futimesSync
(
fd
:
number
,
atime
:
Date
,
mtime
:
Date
):
void
;
export
function
fsync
(
fd
:
number
,
callback
?:
(
err
?:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
fsyncSync
(
fd
:
number
):
void
;
export
function
fdatasync
(
fd
:
number
,
callback
?:
(
err
?:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
fdatasyncSync
(
fd
:
number
):
void
;
export
function
write
(
fd
:
number
,
buffer
:
Buffer
,
offset
:
number
,
length
:
number
,
position
:
number
,
callback
?:
(
err
:
NodeJS
.
ErrnoException
,
written
:
number
,
buffer
:
Buffer
)
=>
void
):
void
;
export
function
write
(
fd
:
number
,
buffer
:
Buffer
,
offset
:
number
,
length
:
number
,
callback
?:
(
err
:
NodeJS
.
ErrnoException
,
written
:
number
,
buffer
:
Buffer
)
=>
void
):
void
;
export
function
write
(
fd
:
number
,
data
:
any
,
callback
?:
(
err
:
NodeJS
.
ErrnoException
,
written
:
number
,
str
:
string
)
=>
void
):
void
;
...
...
@@ -1503,9 +1505,9 @@ declare module "fs" {
* @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer.
*/
export
function
readFileSync
(
filename
:
string
,
options
?:
{
flag
?:
string
;
}):
Buffer
;
export
function
writeFile
(
filename
:
string
,
data
:
any
,
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
writeFile
(
filename
:
string
,
data
:
any
,
options
:
{
encoding
?:
string
;
mode
?:
number
;
flag
?:
string
;
},
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
writeFile
(
filename
:
string
,
data
:
any
,
options
:
{
encoding
?:
string
;
mode
?:
string
;
flag
?:
string
;
},
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
writeFile
(
filename
:
string
|
number
,
data
:
any
,
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
writeFile
(
filename
:
string
|
number
,
data
:
any
,
options
:
{
encoding
?:
string
;
mode
?:
number
;
flag
?:
string
;
},
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
writeFile
(
filename
:
string
|
number
,
data
:
any
,
options
:
{
encoding
?:
string
;
mode
?:
string
;
flag
?:
string
;
},
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
writeFileSync
(
filename
:
string
,
data
:
any
,
options
?:
{
encoding
?:
string
;
mode
?:
number
;
flag
?:
string
;
}):
void
;
export
function
writeFileSync
(
filename
:
string
,
data
:
any
,
options
?:
{
encoding
?:
string
;
mode
?:
string
;
flag
?:
string
;
}):
void
;
export
function
appendFile
(
filename
:
string
,
data
:
any
,
options
:
{
encoding
?:
string
;
mode
?:
number
;
flag
?:
string
;
},
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
...
...
src/vs/base/node/extfs.ts
浏览文件 @
974bce45
...
...
@@ -312,4 +312,36 @@ export function mv(source: string, target: string, callback: (error: Error) => v
return
callback
(
err
);
});
}
// Calls fs.writeFile() followed by a fs.sync() call to flush the changes to disk
// We do this in cases where we want to make sure the data is really on disk and
// not in some cache.
//
// See https://github.com/nodejs/node/blob/v5.10.0/lib/fs.js#L1194
export
function
writeFileAndFlush
(
path
:
string
,
data
:
string
|
NodeBuffer
,
options
:
{
encoding
?:
string
;
mode
?:
number
;
flag
?:
string
;
},
callback
:
(
error
:
Error
)
=>
void
):
void
{
if
(
!
options
)
{
options
=
{
encoding
:
'
utf8
'
,
mode
:
0o666
,
flag
:
'
w
'
};
}
else
if
(
typeof
options
===
'
string
'
)
{
options
=
{
encoding
:
<
string
>
options
,
mode
:
0o666
,
flag
:
'
w
'
};
}
// Open the file with same flags and mode as fs.writeFile()
fs
.
open
(
path
,
options
.
flag
,
options
.
mode
,
(
openError
,
fd
)
=>
{
if
(
openError
)
{
return
callback
(
openError
);
}
// It is valid to pass a fd handle to fs.writeFile() and this will keep the handle open!
fs
.
writeFile
(
fd
,
data
,
options
.
encoding
,
(
writeError
)
=>
{
if
(
writeError
)
{
return
fs
.
close
(
fd
,
()
=>
callback
(
writeError
));
// still need to close the handle on error!
}
// Flush contents (not metadata) of the file to disk
fs
.
fdatasync
(
fd
,
(
syncError
)
=>
{
return
fs
.
close
(
fd
,
(
closeError
)
=>
callback
(
syncError
||
closeError
));
// make sure to carry over the fdatasync error if any!
});
});
});
}
\ No newline at end of file
src/vs/base/node/pfs.ts
浏览文件 @
974bce45
...
...
@@ -135,6 +135,12 @@ export function writeFile(path: string, data: any, encoding: string = 'utf8'): P
return
nfcall
(
fs
.
writeFile
,
path
,
data
,
encoding
);
}
export
function
writeFileAndFlush
(
path
:
string
,
data
:
string
,
encoding
?:
string
):
Promise
;
export
function
writeFileAndFlush
(
path
:
string
,
data
:
NodeBuffer
,
encoding
?:
string
):
Promise
;
export
function
writeFileAndFlush
(
path
:
string
,
data
:
any
,
encoding
:
string
=
'
utf8
'
):
Promise
{
return
nfcall
(
extfs
.
writeFileAndFlush
,
path
,
data
,
encoding
);
}
/**
* Read a dir and return only subfolders
*/
...
...
src/vs/base/test/node/extfs/extfs.test.ts
浏览文件 @
974bce45
...
...
@@ -18,9 +18,9 @@ import extfs = require('vs/base/node/extfs');
suite
(
'
Extfs
'
,
()
=>
{
test
(
'
mkdirp
'
,
function
(
done
:
()
=>
void
)
{
var
id
=
uuid
.
generateUuid
();
var
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
var
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
);
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
);
extfs
.
mkdirp
(
newDir
,
493
,
(
error
)
=>
{
assert
.
ok
(
!
error
);
...
...
@@ -31,12 +31,12 @@ suite('Extfs', () => {
});
test
(
'
copy, move and delete
'
,
function
(
done
:
()
=>
void
)
{
var
id
=
uuid
.
generateUuid
();
var
id2
=
uuid
.
generateUuid
();
var
sourceDir
=
require
.
toUrl
(
'
./fixtures
'
);
var
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
'
extfs
'
);
var
targetDir
=
path
.
join
(
parentDir
,
id
);
var
targetDir2
=
path
.
join
(
parentDir
,
id2
);
const
id
=
uuid
.
generateUuid
();
const
id2
=
uuid
.
generateUuid
();
const
sourceDir
=
require
.
toUrl
(
'
./fixtures
'
);
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
'
extfs
'
);
const
targetDir
=
path
.
join
(
parentDir
,
id
);
const
targetDir2
=
path
.
join
(
parentDir
,
id2
);
extfs
.
copy
(
sourceDir
,
targetDir
,
(
error
)
=>
{
assert
.
ok
(
!
error
);
...
...
@@ -76,9 +76,9 @@ suite('Extfs', () => {
test
(
'
readdir
'
,
function
(
done
:
()
=>
void
)
{
if
(
strings
.
canNormalize
&&
typeof
process
.
versions
[
'
electron
'
]
!==
'
undefined
'
/* needs electron */
)
{
var
id
=
uuid
.
generateUuid
();
var
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
var
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
,
'
öäü
'
);
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
,
'
öäü
'
);
extfs
.
mkdirp
(
newDir
,
493
,
(
error
)
=>
{
assert
.
ok
(
!
error
);
...
...
@@ -94,4 +94,30 @@ suite('Extfs', () => {
done
();
}
});
test
(
'
writeFileAndFlush
'
,
function
(
done
:
()
=>
void
)
{
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
);
const
testFile
=
path
.
join
(
newDir
,
'
flushed.txt
'
);
extfs
.
mkdirp
(
newDir
,
493
,
(
error
)
=>
{
assert
.
ok
(
!
error
);
assert
.
ok
(
fs
.
existsSync
(
newDir
));
extfs
.
writeFileAndFlush
(
testFile
,
'
Hello World
'
,
null
,
(
error
)
=>
{
assert
.
ok
(
!
error
);
assert
.
equal
(
fs
.
readFileSync
(
testFile
),
'
Hello World
'
);
const
largeString
=
(
new
Array
(
100
*
1024
)).
join
(
'
Large String
\n
'
);
extfs
.
writeFileAndFlush
(
testFile
,
largeString
,
null
,
(
error
)
=>
{
assert
.
ok
(
!
error
);
assert
.
equal
(
fs
.
readFileSync
(
testFile
),
largeString
);
done
();
});
});
});
});
});
\ No newline at end of file
src/vs/workbench/services/files/node/fileService.ts
浏览文件 @
974bce45
...
...
@@ -272,13 +272,13 @@ export class FileService implements IFileService {
// Write fast if we do UTF 8 without BOM
if
(
!
addBom
&&
encodingToWrite
===
encoding
.
UTF8
)
{
writeFilePromise
=
pfs
.
writeFile
(
absolutePath
,
value
,
encoding
.
UTF8
);
writeFilePromise
=
pfs
.
writeFile
AndFlush
(
absolutePath
,
value
,
encoding
.
UTF8
);
}
// Otherwise use encoding lib
else
{
let
encoded
=
encoding
.
encode
(
value
,
encodingToWrite
,
{
addBOM
:
addBom
});
writeFilePromise
=
pfs
.
writeFile
(
absolutePath
,
encoded
);
writeFilePromise
=
pfs
.
writeFile
AndFlush
(
absolutePath
,
encoded
);
}
// 4.) set contents
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录