Keep same-named VMs from different drivers, reject ambiguous bare-name resolution, and add exact ResolveRef routing with driver-qualified keys. Declare DataRoot-relative VM roots in guest driver manifests, validate traversal and absolute paths, and scan declarations for unavailable drivers. Add data layout v3 for driver-qualified per-VM plugin settings, preserve explicit values during migration, and pass VMRef keys from the settings UI.
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package datamigrate
|
|
|
|
import (
|
|
"github.com/Nwflower/reims-go/internal/driver"
|
|
"github.com/Nwflower/reims-go/internal/plugin"
|
|
)
|
|
|
|
// migrateVMRefSettings qualifies legacy per-VM plugin settings with the only
|
|
// driver that existed before VMRef. Existing qualified keys win field by field.
|
|
func migrateVMRefSettings(dataRoot string) error {
|
|
store := plugin.NewStateStore(plugin.NewPluginsLayout(dataRoot).Root)
|
|
st, err := store.Load()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
changed := false
|
|
for _, rec := range st.Plugins {
|
|
if rec == nil {
|
|
continue
|
|
}
|
|
for key, values := range rec.VMSettings {
|
|
if _, ok := driver.ParseVMRef(key); ok {
|
|
continue
|
|
}
|
|
newKey := driver.NewVMRef(driver.BuiltinReimsMacOSDriverID, key).Key()
|
|
if current, ok := rec.VMSettings[newKey]; ok {
|
|
for k, v := range values {
|
|
if _, exists := current[k]; !exists {
|
|
current[k] = v
|
|
}
|
|
}
|
|
} else {
|
|
rec.VMSettings[newKey] = values
|
|
}
|
|
delete(rec.VMSettings, key)
|
|
changed = true
|
|
}
|
|
}
|
|
if !changed {
|
|
return nil
|
|
}
|
|
return store.Save(st)
|
|
}
|