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..1fb4bd79e86 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -44,11 +44,28 @@ type FileSystem struct { // NewFileSystem constructs new fs using given core.IpfsNode instance. func NewFileSystem(ctx context.Context, ipfs iface.CoreAPI, ipfspath, ipnspath string) (*FileSystem, error) { - key, err := ipfs.Key().Self(ctx) + + keys, err := ipfs.Key().List(ctx) + if err != nil { + return nil, err + } + + selfkey, err := ipfs.Key().Self(ctx) if err != nil { return nil, err } - root, err := CreateRoot(ctx, ipfs, map[string]iface.Key{"local": key}, ipfspath, ipnspath) + + var keymap = make(map[string]iface.Key) + keymap["local"] = selfkey + for _, k := range keys { + if k.ID() == selfkey.ID() { + continue + } + keymap[k.Name()] = k + } + + fmt.Println(keymap) + root, err := CreateRoot(ctx, ipfs, keymap, ipfspath, ipnspath) if err != nil { return nil, err } @@ -85,7 +102,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 } } @@ -120,6 +137,11 @@ func CreateRoot(ctx context.Context, ipfs iface.CoreAPI, keys map[string]iface.K links := make(map[string]*Link) for alias, k := range keys { root, fsn, err := loadRoot(ctx, ipfs, k) + if err == dag.ErrNotProtobuf { + log.Errorf("skipping non-protobuf key %s: %s", alias, k.Path()) + delete(keys, alias) + continue + } if err != nil { return nil, err }