Feat: Re-import InitializeKeyspace code from go-namesys
The InitializeKeyspace functionality is go-ipfs specific but lives in the go-namesys repo. It is only called from initializeIpnsKeyspace, and therefore the code is directly added to this function. The original function will be removed from go-namesys.
Hector Sanjuan committed
Mar 16, 2021 at 16:32 UTC
5ff3dd8e755f07932443a47dc405a4a9d7e3a5b7
1 file changed
+17
-2
cmd/ipfs/init.go
+17
-2
@@ -15,7 +15,8 @@ import (
15
core "github.com/ipfs/go-ipfs/core"
16
"github.com/ipfs/go-ipfs/core/commands"
17
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
18
- namesys "github.com/ipfs/go-namesys"
18
+ path "github.com/ipfs/go-path"
19
+ unixfs "github.com/ipfs/go-unixfs"
20
21
cmds "github.com/ipfs/go-ipfs-cmds"
22
config "github.com/ipfs/go-ipfs-config"
@@ -245,5 +246,19 @@ func initializeIpnsKeyspace(repoRoot string) error {
246
}
247
defer nd.Close()
248
248
- return namesys.InitializeKeyspace(ctx, nd.Namesys, nd.Pinning, nd.PrivateKey)
249
+ emptyDir := unixfs.EmptyDirNode()
250
+
251
+ // pin recursively because this might already be pinned
252
+ // and doing a direct pin would throw an error in that case
253
+ err = nd.Pinning.Pin(ctx, emptyDir, true)
254
+ if err != nil {
255
+ return err
256
+ }
257
+
258
+ err = nd.Pinning.Flush(ctx)
259
+ if err != nil {
260
+ return err
261
+ }
262
+
263
+ return nd.Namesys.Publish(ctx, nd.PrivateKey, path.FromCid(emptyDir.Cid()))
264
}