@@ -41,31 +41,10 @@ func (m Migration) Apply(opts migrate.Options) error {
4141 return err
4242 }
4343
44- basepath := filepath .Join (opts .Path , "config" )
45- v9path := filepath .Join (opts .Path , "config-v9" )
46- if err := os .Rename (basepath , v9path ); err != nil {
47- if os .IsNotExist (err ) {
48- _ , err2 := os .Stat (v9path )
49- if err2 == nil {
50- log .Log ("... config already renamed to config-v9, continuing" )
51- err = nil
52- }
53- }
54- if err != nil {
55- return err
56- }
57- }
58-
5944 log .Log ("> Upgrading config to new format" )
6045
61- if err := convertFile (v9path , basepath , true , ver9to10Bootstrap , ver9to10Swarm ); err != nil {
62- if opts .NoRevert {
63- return err
64- }
65- err := os .Rename (v9path , basepath )
66- if err != nil {
67- log .Error (err )
68- }
46+ path := filepath .Join (opts .Path , "config" )
47+ if err := convertFile (path , true , ver9to10Bootstrap , ver9to10Swarm ); err != nil {
6948 return err
7049 }
7150
@@ -110,25 +89,21 @@ func (m Migration) Revert(opts migrate.Options) error {
11089 }
11190
11291 phasefile := filepath .Join (opts .Path , "revert-phase" )
113- basepath := filepath .Join (opts .Path , "config" )
114- v10path := filepath .Join (opts .Path , "config-v10" )
92+ path := filepath .Join (opts .Path , "config" )
11593
11694 phase , err := readPhase (phasefile )
11795 if err != nil {
11896 return fmt .Errorf ("reading revert phase: %s" , err )
11997 }
12098
121- for ; phase < 3 ; phase ++ {
99+ defer os .Remove (phasefile )
100+ for ; phase < 2 ; phase ++ {
122101 switch phase {
123102 case 0 :
124- if err := os . Rename ( basepath , v10path ); err != nil {
103+ if err := convertFile ( path , false , ver10to9Bootstrap , ver10to9Swarm ); err != nil {
125104 return err
126105 }
127106 case 1 :
128- if err := convertFile (v10path , basepath , false , ver10to9Bootstrap , ver10to9Swarm ); err != nil {
129- return err
130- }
131- case 2 :
132107 if err := repo .WriteVersion ("9" ); err != nil {
133108 return err
134109 }
@@ -140,7 +115,6 @@ func (m Migration) Revert(opts migrate.Options) error {
140115 return err
141116 }
142117 }
143- os .Remove (phasefile )
144118
145119 return nil
146120}
0 commit comments