提交 bd40cfc8 作者: Kevin Atkinson

Adder: Disallow adding multiple directories unless "-w" is used.

Adding multiple directories without "-w" will not produce the expected
result, so for now it is best to disallow it.

This also added a NumFiles() method to SliceFile.

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 543f6115
...@@ -23,6 +23,10 @@ func (f *SliceFile) IsDirectory() bool { ...@@ -23,6 +23,10 @@ func (f *SliceFile) IsDirectory() bool {
return true return true
} }
func (f *SliceFile) NumFiles() int {
return len(f.files)
}
func (f *SliceFile) NextFile() (File, error) { func (f *SliceFile) NextFile() (File, error) {
if f.n >= len(f.files) { if f.n >= len(f.files) {
return nil, io.EOF return nil, io.EOF
......
...@@ -80,6 +80,16 @@ You can now refer to the added file in a gateway, like so: ...@@ -80,6 +80,16 @@ You can now refer to the added file in a gateway, like so:
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true), cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true),
}, },
PreRun: func(req cmds.Request) error { PreRun: func(req cmds.Request) error {
wrap, _, _ := req.Option(wrapOptionName).Bool()
recursive, _, _ := req.Option(cmds.RecLong).Bool()
sliceFile, ok := req.Files().(*files.SliceFile)
if !ok {
return fmt.Errorf("type assertion failed: req.Files().(*files.SliceFile)")
}
if !wrap && recursive && sliceFile.NumFiles() > 1 {
return fmt.Errorf("adding multiple directories without '-w' unsupported")
}
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet { if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
return nil return nil
} }
......
...@@ -50,4 +50,13 @@ test_expect_success "check that both files are added" ' ...@@ -50,4 +50,13 @@ test_expect_success "check that both files are added" '
test_cmp cat-expected cat-actual test_cmp cat-expected cat-actual
' '
test_expect_success "adding multiple directories fails cleanly" '
test_must_fail ipfs add -q -r dirA dirB
'
test_expect_success "adding multiple directories with -w is okay" '
ipfs add -q -r -w dirA dirB > hashes &&
ipfs ls `tail -1 hashes` > ls-res
'
test_done test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论