/
lockjson.go
54 lines (44 loc) · 1.54 KB
/
lockjson.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package migrate
import (
"errors"
"github.com/vim-volt/volt/lockjson"
"github.com/vim-volt/volt/transaction"
)
func init() {
m := &lockjsonMigrater{}
migrateOps[m.Name()] = m
}
type lockjsonMigrater struct{}
func (*lockjsonMigrater) Name() string {
return "lockjson"
}
func (m *lockjsonMigrater) Description(brief bool) string {
if brief {
return "converts old lock.json format to the latest format"
}
return `Usage
volt migrate [-help] ` + m.Name() + `
Description
Perform migration of $VOLTPATH/lock.json, which means volt converts old version lock.json structure into the latest version. This is always done automatically when reading lock.json content. For example, 'volt get <repos>' will install plugin, and migrate lock.json structure, and write it to lock.json after all. so the migrated content is written to lock.json automatically.
But, for example, 'volt list' does not write to lock.json but does read, so every time when running 'volt list' shows warning about lock.json is old.
To suppress this, running this command simply reads and writes migrated structure to lock.json.`
}
func (*lockjsonMigrater) Migrate() error {
// Read lock.json
lockJSON, err := lockjson.ReadNoMigrationMsg()
if err != nil {
return errors.New("could not read lock.json: " + err.Error())
}
// Begin transaction
err = transaction.Create()
if err != nil {
return err
}
defer transaction.Remove()
// Write to lock.json
err = lockJSON.Write()
if err != nil {
return errors.New("could not write to lock.json: " + err.Error())
}
return nil
}