Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit ace85ca

Browse files
committed
[#1800] Don't drop /ipns/persistentcache records from datastore cache
1 parent 319cdba commit ace85ca

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

repo/migrations/Migration026.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package migrations
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/ipfs/go-ipfs/repo/fsrepo"
78
ds "gx/ipfs/QmUadX5EcvrBmxAV9sE7wUWtWSqxns5K84qKJBixmcT1w9/go-datastore"
@@ -49,6 +50,9 @@ func (cleanIPNSRecordsFromDatastore) Up(repoPath, databasePassword string, testn
4950

5051
log.Debugf("found %d IPNS records to cull...", len(results))
5152
for _, rawResult := range results {
53+
if strings.HasPrefix(rawResult.Key, "/ipns/persistentcache") {
54+
continue
55+
}
5256
rec := new(ipnspb.IpnsEntry)
5357
if err = proto.Unmarshal(rawResult.Value, rec); err != nil {
5458
log.Warningf("failed unmarshaling record (%s): %s", rawResult.Key, err.Error())

repo/migrations/Migration026_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212

1313
func TestCleanIPNSRecordsMigration(t *testing.T) {
1414
var (
15-
basePath = schema.GenerateTempPath()
16-
ipnsKey = "/ipns/shoulddelete"
17-
otherKey = "/ipfs/shouldNOTdelete"
18-
migration = cleanIPNSRecordsFromDatastore{}
15+
basePath = schema.GenerateTempPath()
16+
ipnsKey = "/ipns/shoulddelete"
17+
ipnsFalsePositiveKey = "/ipns/persistentcache/shouldNOTdelete"
18+
otherKey = "/ipfs/shouldNOTdelete"
19+
migration = cleanIPNSRecordsFromDatastore{}
1920

2021
testRepoPath, err = schema.OpenbazaarPathTransform(basePath, true)
2122
)
@@ -46,6 +47,10 @@ func TestCleanIPNSRecordsMigration(t *testing.T) {
4647
if err != nil {
4748
t.Fatal("unable to put ipns record")
4849
}
50+
err = r.Datastore().Put(ds.NewKey(ipnsFalsePositiveKey), []byte("randomdata"))
51+
if err != nil {
52+
t.Fatal("unable to put other record")
53+
}
4954
err = r.Datastore().Put(ds.NewKey(otherKey), []byte("randomdata"))
5055
if err != nil {
5156
t.Fatal("unable to put other record")
@@ -60,6 +65,13 @@ func TestCleanIPNSRecordsMigration(t *testing.T) {
6065
if _, err := r.Datastore().Get(ds.NewKey(ipnsKey)); err != ds.ErrNotFound {
6166
t.Errorf("expected the IPNS record to be removed, but was not")
6267
}
68+
if val, err := r.Datastore().Get(ds.NewKey(ipnsFalsePositiveKey)); err != nil {
69+
t.Errorf("expected the false-positive record to be present, but was not")
70+
} else {
71+
if !bytes.Equal([]byte("randomdata"), val) {
72+
t.Errorf("expected the false-positive record data to be intact, but was not")
73+
}
74+
}
6375
if val, err := r.Datastore().Get(ds.NewKey(otherKey)); err != nil {
6476
t.Errorf("expected the other record to be present, but was not")
6577
} else {

0 commit comments

Comments
 (0)