Skip to content

Commit 9a2167f

Browse files
authored
feat(migrate): support moving sourcecode.vhdx to a new location (#115)
* feat(migrate): support for moving the source code file sourcecode.vhdx to a new location * remove oldSourceCodeDiskPath
1 parent bffb16f commit 9a2167f

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

pkg/cli/migrate.go

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package cli
55

66
import (
7-
"encoding/json"
87
"errors"
98
"fmt"
109
"os"
@@ -90,6 +89,19 @@ func (m *MigrateContext) Start() error {
9089

9190
log.Info("File data.vhdx is copied to new dir")
9291
}
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+
}
93105

94106
// copy versions.json
95107
oldVersions := filepath.Join(m.OldImageDir, "versions.json")
@@ -134,44 +146,11 @@ func (m *MigrateContext) Start() error {
134146
log.Warnf("Failed to remove old versions.json: %v", err)
135147
}
136148

137-
ResetData(log, newVersions)
149+
if err := os.RemoveAll(oldSourceCodeDiskPath); err != nil {
150+
log.Warnf("Failed to remove old sourcecode.vhdx: %v", err)
151+
}
138152

139153
log.Infof("Success to migrate, from %s to %s", m.OldImageDir, m.NewImageDir)
140154

141155
return nil
142156
}
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

Comments
 (0)