Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 25 additions & 3 deletions fuse/ipns/ipns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand Down