mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 07:57:30 +08:00
dag: diff: check CIDs in base case when comparing nodes
Fixes #4591. License: MIT Signed-off-by: Lucas Molas <schomatis@gmail.com>
This commit is contained in:
@ -95,7 +95,12 @@ func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs
|
||||
|
||||
// Diff returns a set of changes that transform node 'a' into node 'b'
|
||||
func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, error) {
|
||||
// Base case where both nodes are leaves, just compare
|
||||
// their CIDs.
|
||||
if len(a.Links()) == 0 && len(b.Links()) == 0 {
|
||||
if a.Cid().Equals(b.Cid()) {
|
||||
return []*Change{}, nil
|
||||
}
|
||||
return []*Change{
|
||||
&Change{
|
||||
Type: Mod,
|
||||
|
@ -20,7 +20,11 @@ test_expect_success "create some objects for testing diffs" '
|
||||
echo "nested" > foo/baz/dog &&
|
||||
C=$(ipfs add -r -q foo | tail -n1)
|
||||
echo "changed" > foo/bar &&
|
||||
D=$(ipfs add -r -q foo | tail -n1)
|
||||
D=$(ipfs add -r -q foo | tail -n1) &&
|
||||
echo "" > single_file &&
|
||||
SINGLE_FILE=$(ipfs add -r -q single_file | tail -n1) &&
|
||||
mkdir empty_dir
|
||||
EMPTY_DIR=$(ipfs add -r -q empty_dir | tail -n1)
|
||||
'
|
||||
|
||||
test_expect_success "diff against self is empty" '
|
||||
@ -32,6 +36,18 @@ test_expect_success "identity diff output looks good" '
|
||||
test_cmp diff_exp diff_out
|
||||
'
|
||||
|
||||
test_expect_success "diff against self (single file) is empty" '
|
||||
ipfs object diff $SINGLE_FILE $SINGLE_FILE > diff_out
|
||||
printf "" > diff_exp &&
|
||||
test_cmp diff_exp diff_out
|
||||
'
|
||||
|
||||
test_expect_success "diff against self (empty dir) is empty" '
|
||||
ipfs object diff $EMPTY_DIR $EMPTY_DIR > diff_out
|
||||
printf "" > diff_exp &&
|
||||
test_cmp diff_exp diff_out
|
||||
'
|
||||
|
||||
test_expect_success "diff added link works" '
|
||||
ipfs object diff $A $B > diff_out
|
||||
'
|
||||
|
Reference in New Issue
Block a user