@@ -12,11 +12,13 @@ import (
12
12
13
13
cmds "github.com/ipfs/go-ipfs-cmds"
14
14
config "github.com/ipfs/go-ipfs-config"
15
+ keystore "github.com/ipfs/go-ipfs-keystore"
15
16
oldcmds "github.com/ipfs/go-ipfs/commands"
16
17
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
17
18
"github.com/ipfs/go-ipfs/core/commands/e"
18
19
ke "github.com/ipfs/go-ipfs/core/commands/keyencode"
19
20
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
21
+ migrations "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
20
22
options "github.com/ipfs/interface-go-ipfs-core/options"
21
23
"github.com/libp2p/go-libp2p-core/crypto"
22
24
peer "github.com/libp2p/go-libp2p-core/peer"
@@ -150,7 +152,6 @@ path can be specified with '--output=<path>' or '-o=<path>'.
150
152
cmds .StringOption (outputOptionName , "o" , "The path where the output should be stored." ),
151
153
},
152
154
NoRemote : true ,
153
- PreRun : DaemonNotRunning ,
154
155
Run : func (req * cmds.Request , res cmds.ResponseEmitter , env cmds.Environment ) error {
155
156
name := req .Arguments [0 ]
156
157
@@ -163,13 +164,24 @@ path can be specified with '--output=<path>' or '-o=<path>'.
163
164
return err
164
165
}
165
166
166
- r , err := fsrepo .Open (cfgRoot )
167
+ // Check repo version, and error out if not matching
168
+ ver , err := migrations .RepoVersion (cfgRoot )
169
+ if err != nil {
170
+ return err
171
+ }
172
+ if ver != fsrepo .RepoVersion {
173
+ return fmt .Errorf ("key export expects repo version (%d) but found (%d)" , fsrepo .RepoVersion , ver )
174
+ }
175
+
176
+ // Export is read-only: safe to read it without acquiring repo lock
177
+ // (this makes export work when ipfs daemon is already running)
178
+ ksp := filepath .Join (cfgRoot , "keystore" )
179
+ ks , err := keystore .NewFSKeystore (ksp )
167
180
if err != nil {
168
181
return err
169
182
}
170
- defer r .Close ()
171
183
172
- sk , err := r . Keystore () .Get (name )
184
+ sk , err := ks .Get (name )
173
185
if err != nil {
174
186
return fmt .Errorf ("key with name '%s' doesn't exist" , name )
175
187
}
0 commit comments