Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ce7982b6
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,发现更多精彩内容 >>
提交
ce7982b6
编写于
6月 14, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
introduce and use extfs.realpath
上级
fda3ed38
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
87 addition
and
13 deletion
+87
-13
src/vs/base/node/extfs.ts
src/vs/base/node/extfs.ts
+45
-5
src/vs/base/node/pfs.ts
src/vs/base/node/pfs.ts
+1
-1
src/vs/base/test/node/extfs/extfs.test.ts
src/vs/base/test/node/extfs/extfs.test.ts
+37
-3
src/vs/code/node/paths.ts
src/vs/code/node/paths.ts
+2
-2
src/vs/workbench/services/files/node/watcher/unix/chokidarWatcherService.ts
...ervices/files/node/watcher/unix/chokidarWatcherService.ts
+2
-2
未找到文件。
src/vs/base/node/extfs.ts
浏览文件 @
ce7982b6
...
...
@@ -374,13 +374,13 @@ export function writeFileAndFlush(path: string, data: string | NodeBuffer, optio
/**
* Copied from: https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/pathUtilities.ts#L83
*
* Given an absolute, normalized, and existing file path 'real
path
' returns the exact path that the file has on disk.
* Given an absolute, normalized, and existing file path 'real
case
' returns the exact path that the file has on disk.
* On a case insensitive file system, the returned path might differ from the original path by character casing.
* On a case sensitive file system, the returned path will always be identical to the original path.
* In case of errors, null is returned. But you cannot use this function to verify that a path exists.
* real
path
Sync does not handle '..' or '.' path segments and it does not take the locale into account.
* real
case
Sync does not handle '..' or '.' path segments and it does not take the locale into account.
*/
export
function
real
path
Sync
(
path
:
string
):
string
{
export
function
real
case
Sync
(
path
:
string
):
string
{
const
dir
=
paths
.
dirname
(
path
);
if
(
path
===
dir
)
{
// end recursion
return
path
;
...
...
@@ -392,7 +392,7 @@ export function realpathSync(path: string): string {
const
found
=
entries
.
filter
(
e
=>
e
.
toLowerCase
()
===
name
);
// use a case insensitive search
if
(
found
.
length
===
1
)
{
// on a case sensitive filesystem we cannot determine here, whether the file exists or not, hence we need the 'file exists' precondition
const
prefix
=
real
path
Sync
(
dir
);
// recurse
const
prefix
=
real
case
Sync
(
dir
);
// recurse
if
(
prefix
)
{
return
paths
.
join
(
prefix
,
found
[
0
]);
}
...
...
@@ -400,7 +400,7 @@ export function realpathSync(path: string): string {
// must be a case sensitive $filesystem
const
ix
=
found
.
indexOf
(
name
);
if
(
ix
>=
0
)
{
// case sensitive
const
prefix
=
real
path
Sync
(
dir
);
// recurse
const
prefix
=
real
case
Sync
(
dir
);
// recurse
if
(
prefix
)
{
return
paths
.
join
(
prefix
,
found
[
ix
]);
}
...
...
@@ -411,4 +411,44 @@ export function realpathSync(path: string): string {
}
return
null
;
}
export
function
realpathSync
(
path
:
string
):
string
{
try
{
return
fs
.
realpathSync
(
path
);
}
catch
(
error
)
{
// We hit an error calling fs.realpathSync(). Since fs.realpathSync() is doing some path normalization
// we now do a similar normalization and then try again if we can access the path with read
// permissions at least. If that succeeds, we return that path.
// fs.realpath() is resolving symlinks and that can fail in certain cases. The workaround is
// to not resolve links but to simply see if the path is read accessible or not.
const
normalizedPath
=
normalizePath
(
path
);
fs
.
accessSync
(
normalizedPath
,
fs
.
constants
.
R_OK
);
// throws in case of an error
return
normalizedPath
;
}
}
export
function
realpath
(
path
:
string
,
callback
:
(
error
:
Error
,
realpath
:
string
)
=>
void
):
void
{
return
fs
.
realpath
(
path
,
(
error
,
realpath
)
=>
{
if
(
!
error
)
{
return
callback
(
null
,
realpath
);
}
// We hit an error calling fs.realpath(). Since fs.realpath() is doing some path normalization
// we now do a similar normalization and then try again if we can access the path with read
// permissions at least. If that succeeds, we return that path.
// fs.realpath() is resolving symlinks and that can fail in certain cases. The workaround is
// to not resolve links but to simply see if the path is read accessible or not.
const
normalizedPath
=
normalizePath
(
path
);
return
fs
.
access
(
normalizedPath
,
fs
.
constants
.
R_OK
,
error
=>
{
return
callback
(
error
,
normalizedPath
);
});
});
}
function
normalizePath
(
path
:
string
):
string
{
return
strings
.
rtrim
(
paths
.
normalize
(
path
),
paths
.
sep
);
}
\ No newline at end of file
src/vs/base/node/pfs.ts
浏览文件 @
ce7982b6
...
...
@@ -72,7 +72,7 @@ export function rimraf(path: string): TPromise<void> {
}
export
function
realpath
(
path
:
string
):
TPromise
<
string
>
{
return
nfcall
(
fs
.
realpath
,
path
,
null
);
return
nfcall
(
extfs
.
realpath
,
path
);
}
export
function
stat
(
path
:
string
):
TPromise
<
fs
.
Stats
>
{
...
...
src/vs/base/test/node/extfs/extfs.test.ts
浏览文件 @
ce7982b6
...
...
@@ -203,7 +203,7 @@ suite('Extfs', () => {
});
});
test
(
'
real
path
'
,
(
done
)
=>
{
test
(
'
real
case
'
,
(
done
)
=>
{
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
);
...
...
@@ -213,7 +213,7 @@ suite('Extfs', () => {
// assume case insensitive file system
if
(
process
.
platform
===
'
win32
'
||
process
.
platform
===
'
darwin
'
)
{
const
upper
=
newDir
.
toUpperCase
();
const
real
=
extfs
.
real
path
Sync
(
upper
);
const
real
=
extfs
.
real
case
Sync
(
upper
);
if
(
real
)
{
// can be null in case of permission errors
assert
.
notEqual
(
real
,
upper
);
...
...
@@ -224,11 +224,45 @@ suite('Extfs', () => {
// linux, unix, etc. -> assume case sensitive file system
else
{
const
real
=
extfs
.
real
path
Sync
(
newDir
);
const
real
=
extfs
.
real
case
Sync
(
newDir
);
assert
.
equal
(
real
,
newDir
);
}
extfs
.
del
(
parentDir
,
os
.
tmpdir
(),
()
=>
{
},
done
);
});
});
test
(
'
realpath
'
,
(
done
)
=>
{
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
);
extfs
.
mkdirp
(
newDir
,
493
,
(
error
)
=>
{
extfs
.
realpath
(
newDir
,
(
error
,
realpath
)
=>
{
assert
.
ok
(
realpath
);
assert
.
ok
(
!
error
);
extfs
.
del
(
parentDir
,
os
.
tmpdir
(),
()
=>
{
},
done
);
});
});
});
test
(
'
realpathSync
'
,
(
done
)
=>
{
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
);
extfs
.
mkdirp
(
newDir
,
493
,
(
error
)
=>
{
let
realpath
:
string
;
try
{
realpath
=
extfs
.
realpathSync
(
newDir
);
}
catch
(
error
)
{
assert
.
ok
(
!
error
);
}
assert
.
ok
(
realpath
);
extfs
.
del
(
parentDir
,
os
.
tmpdir
(),
()
=>
{
},
done
);
});
});
});
\ No newline at end of file
src/vs/code/node/paths.ts
浏览文件 @
ce7982b6
...
...
@@ -5,7 +5,6 @@
'
use strict
'
;
import
*
as
fs
from
'
original-fs
'
;
import
*
as
path
from
'
path
'
;
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
...
...
@@ -13,6 +12,7 @@ import * as paths from 'vs/base/common/paths';
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
*
as
types
from
'
vs/base/common/types
'
;
import
{
ParsedArgs
}
from
'
vs/platform/environment/common/environment
'
;
import
{
realpathSync
}
from
"
vs/base/node/extfs
"
;
export
function
validatePaths
(
args
:
ParsedArgs
):
ParsedArgs
{
...
...
@@ -43,7 +43,7 @@ function doValidatePaths(args: string[], gotoLineMode?: boolean): string[] {
let
realPath
:
string
;
try
{
realPath
=
fs
.
realpathSync
(
pathCandidate
);
realPath
=
realpathSync
(
pathCandidate
);
}
catch
(
error
)
{
// in case of an error, assume the user wants to create this file
// if the path is relative, we join it to the cwd
...
...
src/vs/workbench/services/files/node/watcher/unix/chokidarWatcherService.ts
浏览文件 @
ce7982b6
...
...
@@ -15,7 +15,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
FileChangeType
}
from
'
vs/platform/files/common/files
'
;
import
{
ThrottledDelayer
}
from
'
vs/base/common/async
'
;
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
{
real
path
Sync
}
from
'
vs/base/node/extfs
'
;
import
{
real
case
Sync
}
from
'
vs/base/node/extfs
'
;
import
{
isMacintosh
}
from
'
vs/base/common/platform
'
;
import
watcher
=
require
(
'
vs/workbench/services/files/node/watcher/common
'
);
import
{
IWatcherRequest
,
IWatcherService
}
from
'
./watcher
'
;
...
...
@@ -43,7 +43,7 @@ export class ChokidarWatcherService implements IWatcherService {
// so we have to find the real casing of the path and do some path massaging to fix this
// see https://github.com/paulmillr/chokidar/issues/418
const
originalBasePath
=
request
.
basePath
;
const
realBasePath
=
isMacintosh
?
(
real
path
Sync
(
originalBasePath
)
||
originalBasePath
)
:
originalBasePath
;
const
realBasePath
=
isMacintosh
?
(
real
case
Sync
(
originalBasePath
)
||
originalBasePath
)
:
originalBasePath
;
const
realBasePathLength
=
realBasePath
.
length
;
const
realBasePathDiffers
=
(
originalBasePath
!==
realBasePath
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录