mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-06 08:47:52 +08:00
add -w: fix to work correctly with dirs.
this commit changes the behavior of ipfs add -w: - it makes it able to work with ipfs add -r <dir> - instead of hacking around the add, we simply just add a wrapper directory around the whole result of the add. this means that ipfs add -w calls will output _two_ lines, but this is actually more correct than outputting one line, as two objects were added. this _may_ break scripts out there which expect the output to look a certain way. we should consider whether the old output is more _useful_ (even if less in-line with the model.) License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
This commit is contained in:
parent
578fd02ce3
commit
6e6badf105
@ -10,7 +10,6 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
files "github.com/ipfs/go-ipfs/commands/files"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||
importer "github.com/ipfs/go-ipfs/importer"
|
||||
"github.com/ipfs/go-ipfs/importer/chunk"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
@ -128,10 +127,14 @@ remains to be implemented.
|
||||
node: n,
|
||||
out: outChan,
|
||||
progress: progress,
|
||||
wrap: wrap,
|
||||
hidden: hidden,
|
||||
trickle: trickle,
|
||||
}
|
||||
|
||||
if wrap {
|
||||
file = files.NewSliceFile("", []files.File{file})
|
||||
}
|
||||
|
||||
rootnd, err := addParams.addFile(file)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
@ -247,7 +250,6 @@ type adder struct {
|
||||
node *core.IpfsNode
|
||||
out chan interface{}
|
||||
progress bool
|
||||
wrap bool
|
||||
hidden bool
|
||||
trickle bool
|
||||
}
|
||||
@ -299,18 +301,6 @@ func (params *adder) addFile(file files.File) (*dag.Node, error) {
|
||||
reader = &progressReader{file: file, out: params.out}
|
||||
}
|
||||
|
||||
if params.wrap {
|
||||
p, dagnode, err := coreunix.AddWrapped(params.node, reader, path.Base(file.FileName()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.out <- &AddedObject{
|
||||
Hash: p,
|
||||
Name: file.FileName(),
|
||||
}
|
||||
return dagnode, nil
|
||||
}
|
||||
|
||||
dagnode, err := add(params.node, reader, params.trickle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -212,6 +212,28 @@ test_expect_success "'ipfs cat' output looks good" '
|
||||
test_cmp mountdir/bigfile actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs add -w succeeds" '
|
||||
ipfs add -w mountdir/hello.txt >actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs add -w output looks good" '
|
||||
HASH_W1="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
|
||||
HASH_W2="QmVJfrqd4ogGZME6LWkkikAGddYgh9dBs2U14DHZZUBk7W" &&
|
||||
echo "added $HASH_W1 mountdir/hello.txt" >expected &&
|
||||
echo "added $HASH_W2 " >>expected &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs add -w succeeds (dir)" '
|
||||
ipfs add -r -w mountdir | tail -n1 >actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs add -w output looks good (dir)" '
|
||||
HASH_W="Qmc341yGztU1o8n3c1u5xTYF3uE3zPPP2NYemG9MKz775V" &&
|
||||
echo "added $HASH_W " >expected &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success FUSE "cat ipfs/bigfile succeeds" '
|
||||
cat "ipfs/$HASH" >actual
|
||||
'
|
||||
@ -262,16 +284,6 @@ test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
|
||||
test_cmp sha1_expected sha1_actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs add -w succeeds" '
|
||||
ipfs add -w mountdir/hello.txt >actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs add -w output looks good" '
|
||||
HASH="QmVJfrqd4ogGZME6LWkkikAGddYgh9dBs2U14DHZZUBk7W" &&
|
||||
echo "added $HASH/hello.txt mountdir/hello.txt" >expected &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_kill_ipfs_daemon
|
||||
|
||||
test_done
|
||||
|
||||
Loading…
Reference in New Issue
Block a user