diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index 515da6930fa..4f59ced92d9 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -73,7 +73,7 @@ type CoreAPI struct { pubSub *pubsub.PubSub - checkPublishAllowed func() error + checkPublishAllowed func(allowWhileMounted bool) error checkOnline func(allowOffline bool) error // ONLY for re-applying options in WithOptions, DO NOT USE ANYWHERE ELSE @@ -197,8 +197,8 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e return nil } - subApi.checkPublishAllowed = func() error { - if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() { + subApi.checkPublishAllowed = func(allowWhileMounted bool) error { + if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() && !allowWhileMounted { return errors.New("cannot manually publish while IPNS is mounted") } return nil diff --git a/core/coreapi/name.go b/core/coreapi/name.go index 69dc1137bf0..d77dcc393db 100644 --- a/core/coreapi/name.go +++ b/core/coreapi/name.go @@ -44,14 +44,15 @@ func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.Nam ctx, span := tracing.Span(ctx, "CoreAPI.NameAPI", "Publish", trace.WithAttributes(attribute.String("path", p.String()))) defer span.End() - if err := api.checkPublishAllowed(); err != nil { + options, err := caopts.NamePublishOptions(opts...) + if err != nil { return nil, err } - options, err := caopts.NamePublishOptions(opts...) - if err != nil { + if err := api.checkPublishAllowed(options.AllowWhileMounted); err != nil { return nil, err } + span.SetAttributes( attribute.Bool("allowoffline", options.AllowOffline), attribute.String("key", options.Key), diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index e1840d25964..87ec5866927 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -85,7 +85,7 @@ type Root struct { func ipnsPubFunc(ipfs iface.CoreAPI, key iface.Key) mfs.PubFunc { return func(ctx context.Context, c cid.Cid) error { - _, err := ipfs.Name().Publish(ctx, path.IpfsPath(c), options.Name.Key(key.Name())) + _, err := ipfs.Name().Publish(ctx, path.IpfsPath(c), options.Name.Key(key.Name()), options.Name.AllowWhileMounted(true)) return err } }