Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b29945e7
提交
b29945e7
authored
10月 25, 2016
作者:
Dominic Della Valle
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Windows root parse fix
License: MIT Signed-off-by:
Dominic Della Valle
<
ddvpublic@gmail.com
>
上级
934a0737
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
1 行删除
+48
-1
parse.go
commands/cli/parse.go
+48
-1
没有找到文件。
commands/cli/parse.go
浏览文件 @
b29945e7
...
...
@@ -11,7 +11,9 @@ import (
cmds
"github.com/ipfs/go-ipfs/commands"
files
"github.com/ipfs/go-ipfs/commands/files"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
osh
"gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
u
"gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util"
)
...
...
@@ -398,8 +400,20 @@ func getArgDef(i int, argDefs []cmds.Argument) *cmds.Argument {
const
notRecursiveFmtStr
=
"'%s' is a directory, use the '-%s' flag to specify directories"
const
dirNotSupportedFmtStr
=
"Invalid path '%s', argument '%s' does not support directories"
const
winDriveLetterFmtStr
=
"%q is a drive letter, not a drive path"
func
appendFile
(
fpath
string
,
argDef
*
cmds
.
Argument
,
recursive
,
hidden
bool
)
(
files
.
File
,
error
)
{
// resolve Windows relative dot paths like `X:.\somepath`
if
osh
.
IsWindows
()
{
if
len
(
fpath
)
>=
3
&&
fpath
[
1
:
3
]
==
":."
{
var
err
error
fpath
,
err
=
filepath
.
Abs
(
fpath
)
if
err
!=
nil
{
return
nil
,
err
}
}
}
if
fpath
==
"."
{
cwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
...
...
@@ -412,7 +426,7 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi
fpath
=
cwd
}
fpath
=
filepath
.
ToSlash
(
filepath
.
Clean
(
fpath
)
)
fpath
=
filepath
.
Clean
(
fpath
)
stat
,
err
:=
os
.
Lstat
(
fpath
)
if
err
!=
nil
{
...
...
@@ -428,6 +442,10 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi
}
}
if
osh
.
IsWindows
()
{
return
windowsParseFile
(
fpath
,
hidden
,
stat
)
}
return
files
.
NewSerialFile
(
path
.
Base
(
fpath
),
fpath
,
hidden
,
stat
)
}
...
...
@@ -480,3 +498,32 @@ func (r *messageReader) Read(b []byte) (int, error) {
func
(
r
*
messageReader
)
Close
()
error
{
return
r
.
r
.
Close
()
}
func
windowsParseFile
(
fpath
string
,
hidden
bool
,
stat
os
.
FileInfo
)
(
files
.
File
,
error
)
{
// special cases for Windows drive roots i.e. `X:\` and their long form `\\?\X:\`
// drive path must be preserved as `X:\` (or it's longform) and not converted to `X:`, `X:.`, `\`, or `/` here
switch
len
(
fpath
)
{
case
3
:
// `X:` is cleaned to `X:.` which may not be the expected behaviour by the user, they'll need to provide more specific input
if
fpath
[
1
:
3
]
==
":."
{
return
nil
,
fmt
.
Errorf
(
winDriveLetterFmtStr
,
fpath
[
:
2
])
}
// `X:\` needs to preserve the `\`, path.Base(filepath.ToSlash(fpath)) results in `X:` which is not valid
if
fpath
[
1
:
3
]
==
":
\\
"
{
return
files
.
NewSerialFile
(
fpath
,
fpath
,
hidden
,
stat
)
}
case
6
:
// `\\?\X:` long prefix form of `X:`, still ambiguous
if
fpath
[
:
4
]
==
"
\\\\
?
\\
"
&&
fpath
[
5
]
==
':'
{
return
nil
,
fmt
.
Errorf
(
winDriveLetterFmtStr
,
fpath
)
}
case
7
:
// `\\?\X:\` long prefix form is translated into short form `X:\`
if
fpath
[
:
4
]
==
"
\\\\
?
\\
"
&&
fpath
[
5
]
==
':'
&&
fpath
[
6
]
==
'\\'
{
fpath
=
string
(
fpath
[
4
])
+
":
\\
"
return
files
.
NewSerialFile
(
fpath
,
fpath
,
hidden
,
stat
)
}
}
return
files
.
NewSerialFile
(
path
.
Base
(
filepath
.
ToSlash
(
fpath
)),
fpath
,
hidden
,
stat
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论