Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
b2157cbe
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,发现更多精彩内容 >>
提交
b2157cbe
编写于
10月 14, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "Revert "debt - adopt new fs.readdir with stat info""
This reverts commit
956208bb
.
上级
21cda4e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
13 deletion
+60
-13
src/vs/base/node/pfs.ts
src/vs/base/node/pfs.ts
+14
-0
src/vs/base/test/node/pfs/pfs.test.ts
src/vs/base/test/node/pfs/pfs.test.ts
+26
-0
src/vs/platform/files/node/diskFileSystemProvider.ts
src/vs/platform/files/node/diskFileSystemProvider.ts
+20
-13
未找到文件。
src/vs/base/node/pfs.ts
浏览文件 @
b2157cbe
...
...
@@ -138,6 +138,20 @@ export async function readdir(path: string): Promise<string[]> {
return
handleDirectoryChildren
(
await
promisify
(
fs
.
readdir
)(
path
));
}
export
async
function
readdirWithFileTypes
(
path
:
string
):
Promise
<
fs
.
Dirent
[]
>
{
const
children
=
await
promisify
(
fs
.
readdir
)(
path
,
{
withFileTypes
:
true
});
// Mac: uses NFD unicode form on disk, but we want NFC
// See also https://github.com/nodejs/node/issues/2165
if
(
platform
.
isMacintosh
)
{
for
(
const
child
of
children
)
{
child
.
name
=
normalizeNFC
(
child
.
name
);
}
}
return
children
;
}
export
function
readdirSync
(
path
:
string
):
string
[]
{
return
handleDirectoryChildren
(
fs
.
readdirSync
(
path
));
}
...
...
src/vs/base/test/node/pfs/pfs.test.ts
浏览文件 @
b2157cbe
...
...
@@ -16,6 +16,7 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation';
import
{
isWindows
,
isLinux
}
from
'
vs/base/common/platform
'
;
import
{
canNormalize
}
from
'
vs/base/common/normalization
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
import
{
join
}
from
'
path
'
;
const
chunkSize
=
64
*
1024
;
const
readError
=
'
Error while reading
'
;
...
...
@@ -386,6 +387,31 @@ suite('PFS', () => {
}
});
test
(
'
readdirWithFileTypes
'
,
async
()
=>
{
if
(
canNormalize
&&
typeof
process
.
versions
[
'
electron
'
]
!==
'
undefined
'
/* needs electron */
)
{
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
testDir
=
join
(
parentDir
,
'
pfs
'
,
id
);
const
newDir
=
path
.
join
(
testDir
,
'
öäü
'
);
await
pfs
.
mkdirp
(
newDir
,
493
);
await
pfs
.
writeFile
(
join
(
testDir
,
'
somefile.txt
'
),
'
contents
'
);
assert
.
ok
(
fs
.
existsSync
(
newDir
));
const
children
=
await
pfs
.
readdirWithFileTypes
(
testDir
);
assert
.
equal
(
children
.
some
(
n
=>
n
.
name
===
'
öäü
'
),
true
);
// Mac always converts to NFD, so
assert
.
equal
(
children
.
some
(
n
=>
n
.
isDirectory
()),
true
);
assert
.
equal
(
children
.
some
(
n
=>
n
.
name
===
'
somefile.txt
'
),
true
);
assert
.
equal
(
children
.
some
(
n
=>
n
.
isFile
()),
true
);
await
pfs
.
rimraf
(
parentDir
);
}
});
test
(
'
writeFile (string)
'
,
async
()
=>
{
const
smallData
=
'
Hello World
'
;
const
bigData
=
(
new
Array
(
100
*
1024
)).
join
(
'
Large String
\n
'
);
...
...
src/vs/platform/files/node/diskFileSystemProvider.ts
浏览文件 @
b2157cbe
...
...
@@ -3,14 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
mkdir
,
open
,
close
,
read
,
write
,
fdatasync
}
from
'
fs
'
;
import
{
mkdir
,
open
,
close
,
read
,
write
,
fdatasync
,
Dirent
,
Stats
}
from
'
fs
'
;
import
{
promisify
}
from
'
util
'
;
import
{
IDisposable
,
Disposable
,
toDisposable
,
dispose
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IFileSystemProvider
,
FileSystemProviderCapabilities
,
IFileChange
,
IWatchOptions
,
IStat
,
FileType
,
FileDeleteOptions
,
FileOverwriteOptions
,
FileWriteOptions
,
FileOpenOptions
,
FileSystemProviderErrorCode
,
createFileSystemProviderError
,
FileSystemProviderError
}
from
'
vs/platform/files/common/files
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
isLinux
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
statLink
,
readdir
,
unlink
,
move
,
copy
,
readFile
,
truncate
,
rimraf
,
RimRafMode
,
exist
s
}
from
'
vs/base/node/pfs
'
;
import
{
statLink
,
unlink
,
move
,
copy
,
readFile
,
truncate
,
rimraf
,
RimRafMode
,
exists
,
readdirWithFileType
s
}
from
'
vs/base/node/pfs
'
;
import
{
normalize
,
basename
,
dirname
}
from
'
vs/base/common/path
'
;
import
{
joinPath
}
from
'
vs/base/common/resources
'
;
import
{
isEqual
}
from
'
vs/base/common/extpath
'
;
...
...
@@ -62,15 +62,8 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
try
{
const
{
stat
,
isSymbolicLink
}
=
await
statLink
(
this
.
toFilePath
(
resource
));
// cannot use fs.stat() here to support links properly
let
type
:
number
;
if
(
isSymbolicLink
)
{
type
=
FileType
.
SymbolicLink
|
(
stat
.
isDirectory
()
?
FileType
.
Directory
:
FileType
.
File
);
}
else
{
type
=
stat
.
isFile
()
?
FileType
.
File
:
stat
.
isDirectory
()
?
FileType
.
Directory
:
FileType
.
Unknown
;
}
return
{
type
,
type
:
this
.
toType
(
stat
,
isSymbolicLink
)
,
ctime
:
stat
.
ctime
.
getTime
(),
mtime
:
stat
.
mtime
.
getTime
(),
size
:
stat
.
size
...
...
@@ -82,13 +75,19 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
async
readdir
(
resource
:
URI
):
Promise
<
[
string
,
FileType
][]
>
{
try
{
const
children
=
await
readdir
(
this
.
toFilePath
(
resource
));
const
children
=
await
readdir
WithFileTypes
(
this
.
toFilePath
(
resource
));
const
result
:
[
string
,
FileType
][]
=
[];
await
Promise
.
all
(
children
.
map
(
async
child
=>
{
try
{
const
stat
=
await
this
.
stat
(
joinPath
(
resource
,
child
));
result
.
push
([
child
,
stat
.
type
]);
let
type
:
FileType
;
if
(
child
.
isSymbolicLink
())
{
type
=
(
await
this
.
stat
(
joinPath
(
resource
,
child
.
name
))).
type
;
// always resolve target the link points to if any
}
else
{
type
=
this
.
toType
(
child
);
}
result
.
push
([
child
.
name
,
type
]);
}
catch
(
error
)
{
this
.
logService
.
trace
(
error
);
// ignore errors for individual entries that can arise from permission denied
}
...
...
@@ -100,6 +99,14 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
}
}
private
toType
(
entry
:
Stats
|
Dirent
,
isSymbolicLink
=
entry
.
isSymbolicLink
()):
FileType
{
if
(
isSymbolicLink
)
{
return
FileType
.
SymbolicLink
|
(
entry
.
isDirectory
()
?
FileType
.
Directory
:
FileType
.
File
);
}
return
entry
.
isFile
()
?
FileType
.
File
:
entry
.
isDirectory
()
?
FileType
.
Directory
:
FileType
.
Unknown
;
}
//#endregion
//#region File Reading/Writing
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录