150
cmds.StringOption(outputOptionName, "o", "The path where the output should be stored."),
151
},
152
NoRemote: true,
153
+ PreRun: DaemonNotRunning,
154
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
155
name := req.Arguments[0]
156
460
cmds.IntOption(keyStoreSizeOptionName, "s", "size of the key to generate"),
461
},
462
NoRemote: true,
462
- PreRun: func(req *cmds.Request, env cmds.Environment) error {
463
- cctx := env.(*oldcmds.Context)
464
- daemonLocked, err := fsrepo.LockedByOtherProcess(cctx.ConfigRoot)
465
- if err != nil {
466
- return err
467
- }
468
-
469
- log.Info("checking if daemon is running...")
470
- if daemonLocked {
471
- log.Debug("ipfs daemon is running")
472
- e := "ipfs daemon is running. please stop it to run this command"
473
- return cmds.ClientError(e)
474
- }
475
-
476
- return nil
477
- },
463
+ PreRun: DaemonNotRunning,
464
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
465
cctx := env.(*oldcmds.Context)
466
nBitsForKeypair, nBitsGiven := req.Options[keyStoreSizeOptionName].(int)
542
return nil
543
})
544
}
545
+
546
+// DaemonNotRunning checks to see if the ipfs repo is locked, indicating that
547
+// the daemon is running, and returns and error if the daemon is running.
548
+func DaemonNotRunning(req *cmds.Request, env cmds.Environment) error {
549
+ cctx := env.(*oldcmds.Context)
550
+ daemonLocked, err := fsrepo.LockedByOtherProcess(cctx.ConfigRoot)
551
+ if err != nil {
552
+ return err
553
+ }
554
+
555
+ log.Info("checking if daemon is running...")
556
+ if daemonLocked {
557
+ log.Debug("ipfs daemon is running")
558
+ e := "ipfs daemon is running. please stop it to run this command"
559
+ return cmds.ClientError(e)
560
+ }
561
+
562
+ return nil
563
+}