package admin import ( "fmt" "path/filepath" "thehouseoficarus/internal/behavior" "thehouseoficarus/internal/persistence" ) // rewriteContentRoomRefs rewrites structural room-ID references in every // non-room content file under dataDir per idMap, stages the changed files into // txn, and returns the before/after images so the caller can record them for // undo. This keeps a room rename's content updates in the SAME journaled // commit as the room files. func rewriteContentRoomRefs(dataDir string, idMap map[int]int, txn *persistence.Transaction) ([]ExtraFile, error) { if len(idMap) == 0 { return nil, nil } var extras []ExtraFile for _, sub := range behavior.RoomRefContentDirs { changes, err := behavior.RewriteRoomRefsInDir(filepath.Join(dataDir, sub), idMap) if err != nil { return extras, fmt.Errorf("scan %s: %w", sub, err) } for _, ch := range changes { if err := txn.Replace(ch.Path, ch.Content, 0644); err != nil { return extras, fmt.Errorf("stage %s: %w", ch.Path, err) } extras = append(extras, ExtraFile{ FilePath: ch.Path, OldContent: ch.Old, NewContent: ch.Content, }) } } return extras, nil }