Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fbbc8c59
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,发现更多精彩内容 >>
提交
fbbc8c59
编写于
1月 11, 2019
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make path.dirname root aware (for #64429)
上级
ff9f7cfb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
25 deletion
+61
-25
src/vs/base/common/paths.ts
src/vs/base/common/paths.ts
+28
-11
src/vs/base/common/resources.ts
src/vs/base/common/resources.ts
+3
-0
src/vs/base/test/common/paths.test.ts
src/vs/base/test/common/paths.test.ts
+27
-14
src/vs/base/test/common/resources.test.ts
src/vs/base/test/common/resources.test.ts
+3
-0
未找到文件。
src/vs/base/common/paths.ts
浏览文件 @
fbbc8c59
...
...
@@ -17,6 +17,11 @@ export const sep = '/';
*/
export
const
nativeSep
=
isWindows
?
'
\\
'
:
'
/
'
;
function
isPathSeparator
(
code
:
number
)
{
return
code
===
CharCode
.
Slash
||
code
===
CharCode
.
Backslash
;
}
/**
* @param path the path to get the dirname from
* @param separator the separator to use
...
...
@@ -24,20 +29,32 @@ export const nativeSep = isWindows ? '\\' : '/';
*
*/
export
function
dirname
(
path
:
string
,
separator
=
nativeSep
):
string
{
const
idx
=
~
path
.
lastIndexOf
(
'
/
'
)
||
~
path
.
lastIndexOf
(
'
\\
'
)
;
if
(
idx
===
0
)
{
const
len
=
path
.
length
;
if
(
len
===
0
)
{
return
'
.
'
;
}
else
if
(
~
idx
===
0
)
{
return
path
[
0
];
}
else
if
(
~
idx
===
path
.
length
-
1
)
{
return
dirname
(
path
.
substring
(
0
,
path
.
length
-
1
));
}
else
{
let
res
=
path
.
substring
(
0
,
~
idx
);
if
(
isWindows
&&
res
[
res
.
length
-
1
]
===
'
:
'
)
{
res
+=
separator
;
// make sure drive letters end with backslash
}
else
if
(
len
===
1
)
{
return
isPathSeparator
(
path
.
charCodeAt
(
0
))
?
path
:
'
.
'
;
}
const
root
=
getRoot
(
path
,
separator
);
let
rootLength
=
root
.
length
;
if
(
rootLength
>=
len
)
{
return
root
;
// matched the root
}
if
(
rootLength
===
0
&&
isPathSeparator
(
path
.
charCodeAt
(
0
)))
{
rootLength
=
1
;
// absolute paths stay absolute paths.
}
let
i
=
len
-
1
;
if
(
i
>
rootLength
)
{
i
--
;
// no need to look at the last character. If it's a trailing slash, we ignore it.
while
(
i
>
rootLength
&&
!
isPathSeparator
(
path
.
charCodeAt
(
i
)))
{
i
--
;
}
return
res
;
}
if
(
i
===
0
)
{
return
'
.
'
;
// it was a relative path with a single segment, no root. Nodejs returns '.' here.
}
return
path
.
substr
(
0
,
i
);
}
/**
...
...
src/vs/base/common/resources.ts
浏览文件 @
fbbc8c59
...
...
@@ -76,6 +76,9 @@ export function dirname(resource: URI): URI | null {
if
(
resource
.
scheme
===
Schemas
.
file
)
{
return
URI
.
file
(
paths
.
dirname
(
fsPath
(
resource
)));
}
if
(
resource
.
path
.
length
===
0
)
{
return
resource
;
}
let
dirname
=
paths
.
dirname
(
resource
.
path
,
'
/
'
);
if
(
resource
.
authority
&&
dirname
.
length
&&
dirname
.
charCodeAt
(
0
)
!==
CharCode
.
Slash
)
{
return
null
;
// If a URI contains an authority component, then the path component must either be empty or begin with a CharCode.Slash ("/") character
...
...
src/vs/base/test/common/paths.test.ts
浏览文件 @
fbbc8c59
...
...
@@ -8,21 +8,34 @@ import * as platform from 'vs/base/common/platform';
suite
(
'
Paths
'
,
()
=>
{
test
(
'
dirname
'
,
()
=>
{
assert
.
equal
(
paths
.
dirname
(
'
foo/bar
'
),
'
foo
'
);
assert
.
equal
(
paths
.
dirname
(
'
foo
\\
bar
'
),
'
foo
'
);
assert
.
equal
(
paths
.
dirname
(
'
/foo/bar
'
),
'
/foo
'
);
assert
.
equal
(
paths
.
dirname
(
'
\\
foo
\\
bar
'
),
'
\\
foo
'
);
assert
.
equal
(
paths
.
dirname
(
'
/foo
'
),
'
/
'
);
assert
.
equal
(
paths
.
dirname
(
'
\\
foo
'
),
'
\\
'
);
assert
.
equal
(
paths
.
dirname
(
'
/
'
),
'
/
'
);
assert
.
equal
(
paths
.
dirname
(
'
\\
'
),
'
\\
'
);
assert
.
equal
(
paths
.
dirname
(
'
foo
'
),
'
.
'
);
assert
.
equal
(
paths
.
dirname
(
'
/folder/
'
),
'
/
'
);
if
(
platform
.
isWindows
)
{
assert
.
equal
(
paths
.
dirname
(
'
c:
\\
some
\\
file.txt
'
),
'
c:
\\
some
'
);
assert
.
equal
(
paths
.
dirname
(
'
c:
\\
some
'
),
'
c:
\\
'
);
function
assertDirname
(
path
:
string
,
expected
:
string
,
win
=
false
)
{
const
actual
=
paths
.
dirname
(
path
,
win
?
'
\\
'
:
'
/
'
);
if
(
actual
!==
expected
)
{
assert
.
fail
(
`
${
path
}
: expected:
${
expected
}
, ours:
${
actual
}
`
);
}
}
test
(
'
dirname
'
,
()
=>
{
assertDirname
(
'
foo/bar
'
,
'
foo
'
);
assertDirname
(
'
foo
\\
bar
'
,
'
foo
'
,
true
);
assertDirname
(
'
/foo/bar
'
,
'
/foo
'
);
assertDirname
(
'
\\
foo
\\
bar
'
,
'
\\
foo
'
,
true
);
assertDirname
(
'
/foo
'
,
'
/
'
);
assertDirname
(
'
\\
foo
'
,
'
\\
'
,
true
);
assertDirname
(
'
/
'
,
'
/
'
);
assertDirname
(
'
\\
'
,
'
\\
'
,
true
);
assertDirname
(
'
foo
'
,
'
.
'
);
assertDirname
(
'
f
'
,
'
.
'
);
assertDirname
(
'
f/
'
,
'
.
'
);
assertDirname
(
'
/folder/
'
,
'
/
'
);
assertDirname
(
'
c:
\\
some
\\
file.txt
'
,
'
c:
\\
some
'
,
true
);
assertDirname
(
'
c:
\\
some
'
,
'
c:
\\
'
,
true
);
assertDirname
(
'
c:
\\
'
,
'
c:
\\
'
,
true
);
assertDirname
(
'
c:
'
,
'
c:
'
,
true
);
assertDirname
(
'
\\\\
server
\\
share
\\
some
\\
path
'
,
'
\\\\
server
\\
share
\\
some
'
,
true
);
assertDirname
(
'
\\\\
server
\\
share
\\
some
'
,
'
\\\\
server
\\
share
\\
'
,
true
);
assertDirname
(
'
\\\\
server
\\
share
\\
'
,
'
\\\\
server
\\
share
\\
'
,
true
);
});
test
(
'
normalize
'
,
()
=>
{
...
...
src/vs/base/test/common/resources.test.ts
浏览文件 @
fbbc8c59
...
...
@@ -47,6 +47,7 @@ suite('Resources', () => {
assert
.
equal
(
dirname
(
URI
.
file
(
'
c:
\\
some
\\
file
\\
'
))
!
.
toString
(),
'
file:///c%3A/some
'
);
assert
.
equal
(
dirname
(
URI
.
file
(
'
c:
\\
some
'
))
!
.
toString
(),
'
file:///c%3A/
'
);
assert
.
equal
(
dirname
(
URI
.
file
(
'
C:
\\
some
'
))
!
.
toString
(),
'
file:///c%3A/
'
);
assert
.
equal
(
dirname
(
URI
.
file
(
'
c:
\\
'
))
!
.
toString
(),
'
file:///c%3A/
'
);
}
else
{
assert
.
equal
(
dirname
(
URI
.
file
(
'
/some/file/test.txt
'
))
!
.
toString
(),
'
file:///some/file
'
);
assert
.
equal
(
dirname
(
URI
.
file
(
'
/some/file/
'
))
!
.
toString
(),
'
file:///some
'
);
...
...
@@ -56,6 +57,8 @@ suite('Resources', () => {
assert
.
equal
(
dirname
(
URI
.
parse
(
'
foo://a/some/file/
'
))
!
.
toString
(),
'
foo://a/some
'
);
assert
.
equal
(
dirname
(
URI
.
parse
(
'
foo://a/some/file
'
))
!
.
toString
(),
'
foo://a/some
'
);
assert
.
equal
(
dirname
(
URI
.
parse
(
'
foo://a/some
'
))
!
.
toString
(),
'
foo://a/
'
);
assert
.
equal
(
dirname
(
URI
.
parse
(
'
foo://a/
'
))
!
.
toString
(),
'
foo://a/
'
);
assert
.
equal
(
dirname
(
URI
.
parse
(
'
foo://a
'
))
!
.
toString
(),
'
foo://a
'
);
// does not explode (https://github.com/Microsoft/vscode/issues/41987)
dirname
(
URI
.
from
({
scheme
:
'
file
'
,
authority
:
'
/users/someone/portal.h
'
}));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录