Skip to content

Commit

Permalink
Override checkPublishAllowed when the IPNS Fuse mount writes changes
Browse files Browse the repository at this point in the history
Fixes ipfs#2168
  • Loading branch information
ec1oud committed Sep 25, 2022
1 parent baccaef commit 98d342b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions core/coreapi/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion fuse/ipns/ipns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 98d342b

Please sign in to comment.