|
4 | 4 | package cli |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "encoding/json" |
8 | 7 | "errors" |
9 | 8 | "fmt" |
10 | 9 | "os" |
@@ -90,6 +89,19 @@ func (m *MigrateContext) Start() error { |
90 | 89 |
|
91 | 90 | log.Info("File data.vhdx is copied to new dir") |
92 | 91 | } |
| 92 | + // copy sourcecode.vhdx |
| 93 | + oldSourceCodeDiskPath := filepath.Join(m.OldImageDir, "sourcecode.vhdx") |
| 94 | + { |
| 95 | + if err := wsl.UmountVHDX(m.Logger, oldSourceCodeDiskPath); err != nil { |
| 96 | + return fmt.Errorf("failed to umount sourcecode.vhdx: %w", err) |
| 97 | + } |
| 98 | + |
| 99 | + if err := sys.CopyFile(oldSourceCodeDiskPath, filepath.Join(m.NewImageDir, "sourcecode.vhdx"), true); err != nil { |
| 100 | + return fmt.Errorf("failed to copy sourcecode.vhdx: %w", err) |
| 101 | + } |
| 102 | + |
| 103 | + log.Info("File sourcecode.vhdx is copied to new dir") |
| 104 | + } |
93 | 105 |
|
94 | 106 | // copy versions.json |
95 | 107 | oldVersions := filepath.Join(m.OldImageDir, "versions.json") |
@@ -134,44 +146,11 @@ func (m *MigrateContext) Start() error { |
134 | 146 | log.Warnf("Failed to remove old versions.json: %v", err) |
135 | 147 | } |
136 | 148 |
|
137 | | - ResetData(log, newVersions) |
| 149 | + if err := os.RemoveAll(oldSourceCodeDiskPath); err != nil { |
| 150 | + log.Warnf("Failed to remove old sourcecode.vhdx: %v", err) |
| 151 | + } |
138 | 152 |
|
139 | 153 | log.Infof("Success to migrate, from %s to %s", m.OldImageDir, m.NewImageDir) |
140 | 154 |
|
141 | 155 | return nil |
142 | 156 | } |
143 | | - |
144 | | -// TODO(BlackHole1): DELETE IT! REF: https://github.com/oomol-lab/ovm-win/issues/97 |
145 | | - |
146 | | -func ResetData(log *logger.Context, versionJSONPath string) { |
147 | | - raw, err := os.ReadFile(versionJSONPath) |
148 | | - if err != nil { |
149 | | - log.Warnf("Failed to read versions.json: %v", err) |
150 | | - _ = os.RemoveAll(versionJSONPath) |
151 | | - return |
152 | | - } |
153 | | - |
154 | | - content := &types.Version{} |
155 | | - if err := json.Unmarshal(raw, content); err != nil { |
156 | | - log.Warnf("Failed to unmarshal versions.json file, json content: %s, %v", raw, err) |
157 | | - _ = os.RemoveAll(versionJSONPath) |
158 | | - return |
159 | | - } |
160 | | - |
161 | | - content.Data = "RESET" |
162 | | - |
163 | | - newContent, err := json.Marshal(content) |
164 | | - if err != nil { |
165 | | - log.Warnf("Failed to marshal versions: %v", err) |
166 | | - _ = os.RemoveAll(versionJSONPath) |
167 | | - return |
168 | | - } |
169 | | - |
170 | | - if err := os.WriteFile(versionJSONPath, newContent, 0644); err != nil { |
171 | | - log.Warnf("Failed to write versions to %s: %v", versionJSONPath, err) |
172 | | - _ = os.RemoveAll(versionJSONPath) |
173 | | - return |
174 | | - } |
175 | | - |
176 | | - log.Info("Success to reset data") |
177 | | -} |
0 commit comments