Files
Reims-Go/internal/datamigrate/owner_markers.go
T
NwflowerandClaude Opus 5.5 809ce68cf3 feat(datamigrate): version the data folder and migrate it on startup
The data folder had no record of which layout wrote it, so a new release
could not tell old data from current data. <DataRoot>\.reims-go-data.json
now records data_version and the app version that last raised it. It is
kept out of reims-go.json, which is rewritten whole on every save and
would drop the field under an older build.

Each build carries every step from older layouts to its own; the GUI and
CLI run them in order before reading the folder, so users can jump
straight from any old version. A failed step leaves the version at the
last success and resumes next launch; a folder from a newer build is left
untouched.

Step v1 writes the driver ownership marker into every reims-ctl VM.
driver.RenamedDriverIDs maps old driver IDs to new ones for when a driver
moves to another plugin; markers are not rewritten, so downgrades still
resolve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 05:16:38 -07:00

51 lines
1.4 KiB
Go

package datamigrate
import (
"errors"
"os"
"path/filepath"
"github.com/Nwflower/reims-go/internal/config"
"github.com/Nwflower/reims-go/internal/driver"
)
// VMRoot is where reims-ctl keeps VM folders; the driver router scans the
// same folder.
func VMRoot(dataRoot string) string {
return filepath.Join((&config.Config{DataRoot: dataRoot}).XDGDataDir(), "reims-ctl", "vms")
}
// backfillOwnerMarkers writes driver.OwnerMarkerFile into every VM folder
// that lacks one. Those VMs predate the marker and belong to the built-in
// macOS driver. With the marker on disk, a release that no longer ships
// that driver still lists them as needing a driver instead of losing them.
func backfillOwnerMarkers(dataRoot string) error {
root := VMRoot(dataRoot)
entries, err := os.ReadDir(root)
if errors.Is(err, os.ErrNotExist) {
return nil
}
if err != nil {
return err
}
var errs []error
for _, e := range entries {
if !e.IsDir() {
continue
}
dir := filepath.Join(root, e.Name())
if _, err := os.Stat(filepath.Join(dir, driver.OwnerMarkerFile)); err == nil {
continue
}
// Only real VMs: reims-ctl writes vm.toml for each one. Leftover or
// half-created folders stay unmarked.
if _, err := os.Stat(filepath.Join(dir, "vm.toml")); err != nil {
continue
}
if err := driver.WriteOwnerDriver(dir, driver.BuiltinReimsMacOSDriverID); err != nil {
errs = append(errs, err)
}
}
return errors.Join(errs...)
}