MCPcopy Index your code
hub / github.com/anomalyco/opencode / migrateFile

Function migrateFile

packages/desktop/src/main/migrate.ts:39–67  ·  view source on GitHub ↗
(datPath: string, filename: string)

Source from the content-addressed store, hash-verified

37// keep their full filename as the electron-store name so they match what the
38// renderer already passes via IPC (e.g. `"default.dat"`, `"opencode.global.dat"`).
39function migrateFile(datPath: string, filename: string) {
40 let data: Record<string, unknown>
41 try {
42 data = JSON.parse(readFileSync(datPath, "utf-8"))
43 } catch (err) {
44 log.warn("tauri migration: failed to parse", filename, err)
45 return
46 }
47
48 // opencode.settings.dat → the electron settings store ("opencode.settings").
49 // All other .dat files keep their full filename as the store name so they match
50 // what the renderer passes via IPC (e.g. "default.dat", "opencode.global.dat").
51 const storeName = filename === "opencode.settings.dat" ? "opencode.settings" : filename
52 const target = getStore(storeName)
53 const migrated: string[] = []
54 const skipped: string[] = []
55
56 for (const [key, value] of Object.entries(data)) {
57 // Don't overwrite values the user has already set in the Electron app.
58 if (target.has(key)) {
59 skipped.push(key)
60 continue
61 }
62 target.set(key, value)
63 migrated.push(key)
64 }
65
66 log.log("tauri migration: migrated", filename, "→", storeName, { migrated, skipped })
67}
68
69export function migrate() {
70 if (getStore().get(TAURI_MIGRATED_KEY)) {

Callers 1

migrateFunction · 0.85

Calls 4

getStoreFunction · 0.90
pushMethod · 0.80
setMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected