mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 20:07:45 +08:00
Merge pull request #942 from jbenet/fix/pin-init
fix for weird repo init issue
This commit is contained in:
commit
415aa2c661
@ -148,7 +148,9 @@ func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, p
|
||||
return err
|
||||
}
|
||||
|
||||
err = pins.Pin(emptyDir, false)
|
||||
// pin recursively because this might already be pinned
|
||||
// and doing a direct pin would throw an error in that case
|
||||
err = pins.Pin(emptyDir, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -152,3 +152,41 @@ func TestPinnerBasic(t *testing.T) {
|
||||
t.Fatal("could not find recursively pinned node")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDuplicateSemantics(t *testing.T) {
|
||||
dstore := dssync.MutexWrap(ds.NewMapDatastore())
|
||||
bstore := blockstore.NewBlockstore(dstore)
|
||||
bserv, err := bs.New(bstore, offline.Exchange(bstore))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dserv := mdag.NewDAGService(bserv)
|
||||
|
||||
// TODO does pinner need to share datastore with blockservice?
|
||||
p := NewPinner(dstore, dserv)
|
||||
|
||||
a, _ := randNode()
|
||||
_, err = dserv.Add(a)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// pin is recursively
|
||||
err = p.Pin(a, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// pinning directly should fail
|
||||
err = p.Pin(a, false)
|
||||
if err == nil {
|
||||
t.Fatal("expected direct pin to fail")
|
||||
}
|
||||
|
||||
// pinning recursively again should succeed
|
||||
err = p.Pin(a, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ test_expect_success "file no longer pinned" '
|
||||
# we expect the welcome files to show up here
|
||||
echo "$HASH_WELCOME_DOCS" >expected2 &&
|
||||
ipfs refs -r "$HASH_WELCOME_DOCS" >>expected2 &&
|
||||
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >> expected2 &&
|
||||
sort expected2 >expected_sorted2 &&
|
||||
ipfs pin ls -type=recursive >actual2 &&
|
||||
sort actual2 >actual_sorted2 &&
|
||||
@ -127,7 +128,6 @@ test_expect_success "pin something directly" '
|
||||
|
||||
test_expect_success "'ipfs pin ls -type=direct' is correct" '
|
||||
echo "$DIRECTPIN" >directpinexpected &&
|
||||
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>directpinexpected &&
|
||||
sort directpinexpected >dp_exp_sorted &&
|
||||
ipfs pin ls -type=direct >directpinout &&
|
||||
sort directpinout >dp_out_sorted &&
|
||||
@ -137,6 +137,7 @@ test_expect_success "'ipfs pin ls -type=direct' is correct" '
|
||||
test_expect_success "'ipfs pin ls -type=recursive' is correct" '
|
||||
echo "$MBLOCKHASH" >rp_expected &&
|
||||
echo "$HASH_WELCOME_DOCS" >>rp_expected &&
|
||||
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>rp_expected &&
|
||||
ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
|
||||
sort rp_expected >rp_exp_sorted &&
|
||||
ipfs pin ls -type=recursive >rp_actual &&
|
||||
|
||||
Loading…
Reference in New Issue
Block a user