Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
05b3b817
Unverified
提交
05b3b817
authored
10月 04, 2018
作者:
Steven Allen
提交者:
GitHub
10月 04, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5555 from overbool/feat/add-force-flag-for-files-rm
feat(command): add force flag for files rm
上级
823d9b98
a86cde50
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
13 行删除
+34
-13
files.go
core/commands/files.go
+20
-13
t0250-files-api.sh
test/sharness/t0250-files-api.sh
+14
-0
没有找到文件。
core/commands/files.go
浏览文件 @
05b3b817
...
@@ -1002,6 +1002,7 @@ Remove files or directories.
...
@@ -1002,6 +1002,7 @@ Remove files or directories.
},
},
Options
:
[]
cmdkit
.
Option
{
Options
:
[]
cmdkit
.
Option
{
cmdkit
.
BoolOption
(
"recursive"
,
"r"
,
"Recursively remove directories."
),
cmdkit
.
BoolOption
(
"recursive"
,
"r"
,
"Recursively remove directories."
),
cmdkit
.
BoolOption
(
"force"
,
"Forcibly remove target at path; implies -r for directories"
),
},
},
Run
:
func
(
req
oldcmds
.
Request
,
res
oldcmds
.
Response
)
{
Run
:
func
(
req
oldcmds
.
Request
,
res
oldcmds
.
Response
)
{
defer
res
.
SetOutput
(
nil
)
defer
res
.
SetOutput
(
nil
)
...
@@ -1041,8 +1042,6 @@ Remove files or directories.
...
@@ -1041,8 +1042,6 @@ Remove files or directories.
return
return
}
}
dashr
,
_
,
_
:=
req
.
Option
(
"r"
)
.
Bool
()
var
success
bool
var
success
bool
defer
func
()
{
defer
func
()
{
if
success
{
if
success
{
...
@@ -1054,8 +1053,10 @@ Remove files or directories.
...
@@ -1054,8 +1053,10 @@ Remove files or directories.
}
}
}()
}()
// if '-r' specified, don't check file type (in bad scenarios, the block may not exist)
// if '--force' specified, it will remove anything else,
if
dashr
{
// including file, directory, corrupted node, etc
force
,
_
,
_
:=
req
.
Option
(
"force"
)
.
Bool
()
if
force
{
err
:=
pdir
.
Unlink
(
name
)
err
:=
pdir
.
Unlink
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
...
@@ -1066,25 +1067,31 @@ Remove files or directories.
...
@@ -1066,25 +1067,31 @@ Remove files or directories.
return
return
}
}
childi
,
err
:=
pdir
.
Child
(
name
)
// get child node by name, when the node is corrupted and nonexistent,
// it will return specific error.
child
,
err
:=
pdir
.
Child
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
}
}
switch
childi
.
(
type
)
{
dashr
,
_
,
_
:=
req
.
Option
(
"r"
)
.
Bool
()
switch
child
.
(
type
)
{
case
*
mfs
.
Directory
:
case
*
mfs
.
Directory
:
res
.
SetError
(
fmt
.
Errorf
(
"%s is a directory, use -r to remove directories"
,
path
),
cmdkit
.
ErrNormal
)
if
!
dashr
{
return
res
.
SetError
(
fmt
.
Errorf
(
"%s is a directory, use -r to remove directories"
,
path
),
cmdkit
.
ErrNormal
)
default
:
err
:=
pdir
.
Unlink
(
name
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
}
}
}
success
=
true
err
=
pdir
.
Unlink
(
name
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
}
success
=
true
},
},
}
}
...
...
test/sharness/t0250-files-api.sh
浏览文件 @
05b3b817
...
@@ -629,6 +629,20 @@ test_files_api() {
...
@@ -629,6 +629,20 @@ test_files_api() {
test_expect_success
"repo gc
$EXTRA
"
'
test_expect_success
"repo gc
$EXTRA
"
'
ipfs repo gc
ipfs repo gc
'
'
# test rm
test_expect_success
"remove file forcibly"
'
echo "hello world" | ipfs files write --create /forcibly &&
ipfs files rm --force /forcibly &&
verify_dir_contents /
'
test_expect_success
"remove directory forcibly"
'
ipfs files mkdir /forcibly-dir &&
ipfs files rm --force /forcibly-dir &&
verify_dir_contents /
'
}
}
# test offline and online
# test offline and online
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论