mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-02 06:47:51 +08:00
Merge pull request #7152 from ipfs/fix/sharness-partial-publish
fix: invalidate cache on failed publish
This commit is contained in:
commit
b760d89e02
@ -49,6 +49,13 @@ func (ns *mpns) cacheSet(name string, val path.Path, ttl time.Duration) {
|
||||
})
|
||||
}
|
||||
|
||||
func (ns *mpns) cacheInvalidate(name string) {
|
||||
if ns.cache == nil {
|
||||
return
|
||||
}
|
||||
ns.cache.Remove(name)
|
||||
}
|
||||
|
||||
type cacheEntry struct {
|
||||
val path.Path
|
||||
eol time.Time
|
||||
|
||||
@ -218,6 +218,9 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.
|
||||
return err
|
||||
}
|
||||
if err := ns.ipnsPublisher.PublishWithEOL(ctx, name, value, eol); err != nil {
|
||||
// Invalidate the cache. Publishing may _partially_ succeed but
|
||||
// still return an error.
|
||||
ns.cacheInvalidate(peer.Encode(id))
|
||||
return err
|
||||
}
|
||||
ttl := DefaultResolverCacheTTL
|
||||
|
||||
@ -153,17 +153,24 @@ test_resolve_cmd_fail() {
|
||||
test_resolve "/ipld/$dag_hash/i/j" "/ipld/$dag_hash/i/j"
|
||||
test_resolve "/ipld/$dag_hash/i" "/ipld/$dag_hash/i"
|
||||
|
||||
# At the moment, publishing _fails_ because we fail to put to the DHT.
|
||||
# However, resolving succeeds because we resolve the record we put to our own
|
||||
# node.
|
||||
#
|
||||
# We should find a nice way to truly support offline publishing. But this
|
||||
# behavior isn't terrible.
|
||||
|
||||
test_resolve_setup_name_fail "self" "/ipfs/$a_hash"
|
||||
test_resolve_fail "/ipns/$self_hash" "/ipfs/$a_hash"
|
||||
test_resolve_fail "/ipns/$self_hash/b" "/ipfs/$b_hash"
|
||||
test_resolve_fail "/ipns/$self_hash/b/c" "/ipfs/$c_hash"
|
||||
test_resolve "/ipns/$self_hash" "/ipfs/$a_hash"
|
||||
test_resolve "/ipns/$self_hash/b" "/ipfs/$b_hash"
|
||||
test_resolve "/ipns/$self_hash/b/c" "/ipfs/$c_hash"
|
||||
|
||||
test_resolve_setup_name_fail "self" "/ipfs/$b_hash"
|
||||
test_resolve_fail "/ipns/$self_hash" "/ipfs/$b_hash"
|
||||
test_resolve_fail "/ipns/$self_hash/c" "/ipfs/$c_hash"
|
||||
test_resolve "/ipns/$self_hash" "/ipfs/$b_hash"
|
||||
test_resolve "/ipns/$self_hash/c" "/ipfs/$c_hash"
|
||||
|
||||
test_resolve_setup_name_fail "self" "/ipfs/$c_hash"
|
||||
test_resolve_fail "/ipns/$self_hash" "/ipfs/$c_hash"
|
||||
test_resolve "/ipns/$self_hash" "/ipfs/$c_hash"
|
||||
}
|
||||
|
||||
# should work offline
|
||||
|
||||
Loading…
Reference in New Issue
Block a user