Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
38311adc
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,发现更多精彩内容 >>
提交
38311adc
编写于
11月 23, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add and use writeFileAndFlushSync
上级
d691f07a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
69 addition
and
16 deletion
+69
-16
src/typings/node.d.ts
src/typings/node.d.ts
+3
-3
src/vs/base/node/extfs.ts
src/vs/base/node/extfs.ts
+29
-0
src/vs/base/test/node/extfs/extfs.test.ts
src/vs/base/test/node/extfs/extfs.test.ts
+25
-0
src/vs/code/node/cli.ts
src/vs/code/node/cli.ts
+2
-2
src/vs/code/node/cliProcessMain.ts
src/vs/code/node/cliProcessMain.ts
+4
-6
src/vs/platform/backup/electron-main/backupMainService.ts
src/vs/platform/backup/electron-main/backupMainService.ts
+1
-1
src/vs/platform/storage/node/storage.ts
src/vs/platform/storage/node/storage.ts
+2
-1
src/vs/platform/workspaces/electron-main/workspacesMainService.ts
...latform/workspaces/electron-main/workspacesMainService.ts
+3
-3
未找到文件。
src/typings/node.d.ts
浏览文件 @
38311adc
...
...
@@ -2718,9 +2718,9 @@ declare module "fs" {
export
function
writeFile
(
filename
:
string
|
number
,
data
:
any
,
encoding
:
string
,
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
,
encoding
:
string
):
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
writeFileSync
(
filename
:
string
|
number
,
data
:
any
,
encoding
:
string
):
void
;
export
function
writeFileSync
(
filename
:
string
|
number
,
data
:
any
,
options
?:
{
encoding
?:
string
;
mode
?:
number
;
flag
?:
string
;
}):
void
;
export
function
writeFileSync
(
filename
:
string
|
number
,
data
:
any
,
options
?:
{
encoding
?:
string
;
mode
?:
string
;
flag
?:
string
;
}):
void
;
export
function
appendFile
(
filename
:
string
,
data
:
any
,
encoding
:
string
,
callback
:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
appendFile
(
filename
:
string
,
data
:
any
,
options
:
{
encoding
?:
string
;
mode
?:
number
;
flag
?:
string
;
},
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
export
function
appendFile
(
filename
:
string
,
data
:
any
,
options
:
{
encoding
?:
string
;
mode
?:
string
;
flag
?:
string
;
},
callback
?:
(
err
:
NodeJS
.
ErrnoException
)
=>
void
):
void
;
...
...
src/vs/base/node/extfs.ts
浏览文件 @
38311adc
...
...
@@ -363,6 +363,35 @@ export function writeFileAndFlush(path: string, data: string | NodeBuffer, optio
});
}
export
function
writeFileAndFlushSync
(
path
:
string
,
data
:
string
|
NodeBuffer
,
options
?:
{
mode
?:
number
;
flag
?:
string
;
}):
void
{
if
(
!
canFlush
)
{
return
fs
.
writeFileSync
(
path
,
data
,
options
);
}
if
(
!
options
)
{
options
=
{
mode
:
0o666
,
flag
:
'
w
'
};
}
// Open the file with same flags and mode as fs.writeFile()
const
fd
=
fs
.
openSync
(
path
,
options
.
flag
,
options
.
mode
);
try
{
// It is valid to pass a fd handle to fs.writeFile() and this will keep the handle open!
fs
.
writeFileSync
(
fd
,
data
);
// Flush contents (not metadata) of the file to disk
try
{
fs
.
fdatasyncSync
(
fd
);
}
catch
(
syncError
)
{
console
.
warn
(
'
[node.js fs] fdatasyncSync is now disabled for this session because it failed:
'
,
syncError
);
canFlush
=
false
;
}
}
finally
{
fs
.
closeSync
(
fd
);
}
}
/**
* Copied from: https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/pathUtilities.ts#L83
*
...
...
src/vs/base/test/node/extfs/extfs.test.ts
浏览文件 @
38311adc
...
...
@@ -209,6 +209,31 @@ suite('Extfs', () => {
});
});
test
(
'
writeFileAndFlushSync
'
,
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
'
);
mkdirp
(
newDir
,
493
,
error
=>
{
if
(
error
)
{
return
onError
(
error
,
done
);
}
assert
.
ok
(
fs
.
existsSync
(
newDir
));
extfs
.
writeFileAndFlushSync
(
testFile
,
'
Hello World
'
,
null
);
assert
.
equal
(
fs
.
readFileSync
(
testFile
),
'
Hello World
'
);
const
largeString
=
(
new
Array
(
100
*
1024
)).
join
(
'
Large String
\n
'
);
extfs
.
writeFileAndFlushSync
(
testFile
,
largeString
,
null
);
assert
.
equal
(
fs
.
readFileSync
(
testFile
),
largeString
);
extfs
.
del
(
parentDir
,
os
.
tmpdir
(),
done
,
ignore
);
});
});
test
(
'
realcase
'
,
(
done
)
=>
{
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
...
...
src/vs/code/node/cli.ts
浏览文件 @
38311adc
...
...
@@ -11,10 +11,10 @@ import { ParsedArgs } from 'vs/platform/environment/common/environment';
import
product
from
'
vs/platform/node/product
'
;
import
pkg
from
'
vs/platform/node/package
'
;
import
*
as
fs
from
'
fs
'
;
import
*
as
paths
from
'
path
'
;
import
*
as
os
from
'
os
'
;
import
{
whenDeleted
}
from
'
vs/base/node/pfs
'
;
import
{
writeFileAndFlushSync
}
from
'
vs/base/node/extfs
'
;
function
shouldSpawnCliProcess
(
argv
:
ParsedArgs
):
boolean
{
return
!!
argv
[
'
install-source
'
]
...
...
@@ -66,7 +66,7 @@ export function main(argv: string[]): TPromise<void> {
let
waitMarkerError
:
Error
;
const
randomTmpFile
=
paths
.
join
(
os
.
tmpdir
(),
Math
.
random
().
toString
(
36
).
replace
(
/
[^
a-z
]
+/g
,
''
).
substr
(
0
,
10
));
try
{
fs
.
writeFile
Sync
(
randomTmpFile
,
''
);
writeFileAndFlush
Sync
(
randomTmpFile
,
''
);
waitMarkerFilePath
=
randomTmpFile
;
argv
.
push
(
'
--waitMarkerFilePath
'
,
waitMarkerFilePath
);
}
catch
(
error
)
{
...
...
src/vs/code/node/cliProcessMain.ts
浏览文件 @
38311adc
...
...
@@ -7,7 +7,6 @@ import { localize } from 'vs/nls';
import
product
from
'
vs/platform/node/product
'
;
import
pkg
from
'
vs/platform/node/package
'
;
import
*
as
path
from
'
path
'
;
import
*
as
fs
from
'
fs
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
sequence
}
from
'
vs/base/common/async
'
;
...
...
@@ -30,7 +29,7 @@ import { RequestService } from 'vs/platform/request/node/requestService';
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ConfigurationService
}
from
'
vs/platform/configuration/node/configurationService
'
;
import
{
AppInsightsAppender
}
from
'
vs/platform/telemetry/node/appInsightsAppender
'
;
import
{
mkdirp
}
from
'
vs/base/node/pfs
'
;
import
{
mkdirp
,
writeFile
}
from
'
vs/base/node/pfs
'
;
import
{
IChoiceService
}
from
'
vs/platform/message/common/message
'
;
import
{
ChoiceCliService
}
from
'
vs/platform/message/node/messageCli
'
;
import
{
getBaseLabel
}
from
'
vs/base/common/labels
'
;
...
...
@@ -77,10 +76,9 @@ class Main {
}
private
setInstallSource
(
installSource
:
string
):
TPromise
<
any
>
{
return
new
TPromise
<
void
>
((
c
,
e
)
=>
{
const
path
=
getInstallSourcePath
(
this
.
environmentService
.
userDataPath
);
fs
.
writeFile
(
path
,
installSource
.
slice
(
0
,
30
),
'
utf8
'
,
err
=>
err
?
e
(
err
)
:
c
(
null
));
});
const
path
=
getInstallSourcePath
(
this
.
environmentService
.
userDataPath
);
return
writeFile
(
path
,
installSource
.
slice
(
0
,
30
));
}
private
listExtensions
(
showVersions
:
boolean
):
TPromise
<
any
>
{
...
...
src/vs/platform/backup/electron-main/backupMainService.ts
浏览文件 @
38311adc
...
...
@@ -309,7 +309,7 @@ export class BackupMainService implements IBackupMainService {
fs
.
mkdirSync
(
this
.
backupHome
);
}
fs
.
writeFile
Sync
(
this
.
workspacesJsonPath
,
JSON
.
stringify
(
this
.
backups
));
extfs
.
writeFileAndFlush
Sync
(
this
.
workspacesJsonPath
,
JSON
.
stringify
(
this
.
backups
));
}
catch
(
ex
)
{
this
.
logService
.
error
(
`Backup: Could not save workspaces.json:
${
ex
.
toString
()}
`
);
}
...
...
src/vs/platform/storage/node/storage.ts
浏览文件 @
38311adc
...
...
@@ -9,6 +9,7 @@ import * as path from 'path';
import
*
as
fs
from
'
original-fs
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
writeFileAndFlushSync
}
from
'
vs/base/node/extfs
'
;
export
const
IStorageService
=
createDecorator
<
IStorageService
>
(
'
storageService
'
);
...
...
@@ -84,7 +85,7 @@ export class StorageService implements IStorageService {
private
save
():
void
{
try
{
fs
.
writeFile
Sync
(
this
.
dbPath
,
JSON
.
stringify
(
this
.
database
,
null
,
4
));
// permission issue can happen here
writeFileAndFlush
Sync
(
this
.
dbPath
,
JSON
.
stringify
(
this
.
database
,
null
,
4
));
// permission issue can happen here
}
catch
(
error
)
{
if
(
this
.
environmentService
.
verbose
)
{
console
.
error
(
error
);
...
...
src/vs/platform/workspaces/electron-main/workspacesMainService.ts
浏览文件 @
38311adc
...
...
@@ -11,9 +11,9 @@ import { isParent } from 'vs/platform/files/common/files';
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
extname
,
join
,
dirname
,
isAbsolute
,
resolve
}
from
'
path
'
;
import
{
mkdirp
,
writeFile
,
readFile
}
from
'
vs/base/node/pfs
'
;
import
{
readFileSync
,
writeFileSync
,
existsSync
,
mkdirSync
}
from
'
fs
'
;
import
{
readFileSync
,
existsSync
,
mkdirSync
}
from
'
fs
'
;
import
{
isLinux
,
isMacintosh
}
from
'
vs/base/common/platform
'
;
import
{
delSync
,
readdirSync
}
from
'
vs/base/node/extfs
'
;
import
{
delSync
,
readdirSync
,
writeFileAndFlushSync
}
from
'
vs/base/node/extfs
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
isEqual
}
from
'
vs/base/common/paths
'
;
...
...
@@ -136,7 +136,7 @@ export class WorkspacesMainService implements IWorkspacesMainService {
mkdirSync
(
configParent
);
writeFileSync
(
workspace
.
configPath
,
JSON
.
stringify
(
storedWorkspace
,
null
,
'
\t
'
));
writeFile
AndFlush
Sync
(
workspace
.
configPath
,
JSON
.
stringify
(
storedWorkspace
,
null
,
'
\t
'
));
return
workspace
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录