add migrate flag to daemon subcommand
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
Jeromy committed
Jul 6, 2016 at 10:29 UTC
cc73137f741212059b924bca406e3746c8e2565a
3 files changed
+38
-24
cmd/ipfs/daemon.go
+33
-9
@@ -23,6 +23,7 @@ import (
23
"github.com/ipfs/go-ipfs/core/corerouting"
24
nodeMount "github.com/ipfs/go-ipfs/fuse/node"
25
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
26
+ migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
27
pstore "gx/ipfs/QmQdnfvZQuhdT93LNc5bos52wAmdr3G2p6G8teLJMEN32P/go-libp2p-peerstore"
28
conn "gx/ipfs/QmVCe3SNMjkcPgnpFhZs719dheq6xE7gJwjzV7aWcUM4Ms/go-libp2p/p2p/net/conn"
29
util "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
@@ -30,18 +31,19 @@ import (
31
)
32
33
const (
34
+ adjustFDLimitKwd = "manage-fdlimit"
35
+ enableGCKwd = "enable-gc"
36
initOptionKwd = "init"
34
- routingOptionKwd = "routing"
35
- routingOptionSupernodeKwd = "supernode"
36
- mountKwd = "mount"
37
- writableKwd = "writable"
37
ipfsMountKwd = "mount-ipfs"
38
ipnsMountKwd = "mount-ipns"
40
- unrestrictedApiAccessKwd = "unrestricted-api"
41
- unencryptTransportKwd = "disable-transport-encryption"
42
- enableGCKwd = "enable-gc"
43
- adjustFDLimitKwd = "manage-fdlimit"
39
+ migrateKwd = "migrate"
40
+ mountKwd = "mount"
41
offlineKwd = "offline"
42
+ routingOptionKwd = "routing"
43
+ routingOptionSupernodeKwd = "supernode"
44
+ unencryptTransportKwd = "disable-transport-encryption"
45
+ unrestrictedApiAccessKwd = "unrestricted-api"
46
+ writableKwd = "writable"
47
// apiAddrKwd = "address-api"
48
// swarmAddrKwd = "address-swarm"
49
)
@@ -139,6 +141,7 @@ Headers.
141
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection").Default(false),
142
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").Default(true),
143
cmds.BoolOption(offlineKwd, "Run offline. Do not connect to the rest of the network but provide local API.").Default(false),
144
+ cmds.BoolOption(migrateKwd, "If true, assume yes at the migrate prompt. If false, assume no."),
145
146
// TODO: add way to override addresses. tricky part: updating the config if also --init.
147
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
@@ -216,9 +219,30 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
219
// acquire the repo lock _before_ constructing a node. we need to make
220
// sure we are permitted to access the resources (datastore, etc.)
221
repo, err := fsrepo.Open(req.InvocContext().ConfigRoot)
219
- if err != nil {
222
+ switch err {
223
+ default:
224
res.SetError(err, cmds.ErrNormal)
225
return
226
+ case fsrepo.ErrNeedMigration:
227
+ domigrate, found, _ := req.Option(migrateKwd).Bool()
228
+
229
+ if !found {
230
+ err = migrate.TryMigrating(fsrepo.RepoVersion)
231
+ } else if domigrate {
232
+ err = migrate.RunMigration(fsrepo.RepoVersion)
233
+ }
234
+ if err != nil {
235
+ res.SetError(err, cmds.ErrNormal)
236
+ return
237
+ }
238
+
239
+ repo, err = fsrepo.Open(req.InvocContext().ConfigRoot)
240
+ if err != nil {
241
+ res.SetError(err, cmds.ErrNormal)
242
+ return
243
+ }
244
+ case nil:
245
+ break
246
}
247
248
cfg, err := ctx.GetConfig()
repo/fsrepo/fsrepo.go
+4
-14
@@ -43,8 +43,9 @@ a migration in reverse.
43
See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md for details.`
44
45
var (
46
- ErrNoVersion = errors.New("no version file found, please run 0-to-1 migration tool.\n" + migrationInstructions)
47
- ErrOldRepo = errors.New("ipfs repo found in old '~/.go-ipfs' location, please run migration tool.\n" + migrationInstructions)
46
+ ErrNoVersion = errors.New("no version file found, please run 0-to-1 migration tool.\n" + migrationInstructions)
47
+ ErrOldRepo = errors.New("ipfs repo found in old '~/.go-ipfs' location, please run migration tool.\n" + migrationInstructions)
48
+ ErrNeedMigration = errors.New("ipfs repo needs migration.")
49
)
50
51
type NoRepoError struct {
@@ -141,18 +142,7 @@ func open(repoPath string) (repo.Repo, error) {
142
}
143
144
if RepoVersion > ver {
144
- r.lockfile.Close()
145
-
146
- err := mfsr.TryMigrating(RepoVersion)
147
- if err != nil {
148
- return nil, err
149
- }
150
-
151
- r.lockfile, err = lockfile.Lock(r.path)
152
- if err != nil {
153
- return nil, fmt.Errorf("reacquiring lock: %s", err)
154
- }
155
-
145
+ return nil, ErrNeedMigration
146
} else if ver > RepoVersion {
147
// program version too low for existing repo
148
return nil, fmt.Errorf(programTooLowMessage, RepoVersion, ver)
repo/mock.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"github.com/ipfs/go-ipfs/repo/config"
7
)
8
9
-var errTODO = errors.New("TODO")
9
+var errTODO = errors.New("TODO: mock repo")
10
11
// Mock is not thread-safe
12
type Mock struct {