aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/undo.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-18 17:48:26 -0400
committerhistoria <[not public]>2026-09-18 17:48:26 -0400
commit8fe9e3c3fef0049df82281a62afe35dda516dfe2 (patch)
treedd269f2c0710f334e19f00a191260ebc46284a90 /internal/admin/undo.go
parent194164a77eb4f2479b94c19e6f0e1278ab608781 (diff)
downloadthehouseoficarus-8fe9e3c3fef0049df82281a62afe35dda516dfe2.tar.gz
fix: close combat ghost, admin traversal, login throttle, journal double-pay, and quality/economy gaps
Diffstat (limited to 'internal/admin/undo.go')
-rw-r--r--internal/admin/undo.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/admin/undo.go b/internal/admin/undo.go
index 24ce9c1..c2ea61d 100644
--- a/internal/admin/undo.go
+++ b/internal/admin/undo.go
@@ -115,6 +115,47 @@ func (us *UndoStack) SetPlayerFileOnlineCheck(fn func(relPath string) bool) {
us.playerFileOnlineCheck = fn
}
+// RewritePaths re-prefixes every stored history path under oldPrefix so a
+// directory rename does not leave stale absolute paths behind. Without this
+// a later undo recreates the old directory and writes a duplicate file while
+// the live file stays in the new directory. newPrefix may be empty to leave
+// paths untouched.
+func (us *UndoStack) RewritePaths(oldPrefix, newPrefix string) {
+ if oldPrefix == "" || newPrefix == "" || oldPrefix == newPrefix {
+ return
+ }
+ us.mu.Lock()
+ defer us.mu.Unlock()
+ sep := string(os.PathSeparator)
+ rewrite := func(p string) string {
+ if p == "" {
+ return p
+ }
+ if p == oldPrefix {
+ return newPrefix
+ }
+ if strings.HasPrefix(p, oldPrefix+sep) {
+ return filepath.Join(newPrefix, strings.TrimPrefix(p, oldPrefix+sep))
+ }
+ return p
+ }
+ rewriteDesc := func(c *ChangeDesc) {
+ c.FilePath = rewrite(c.FilePath)
+ c.NewFilePath = rewrite(c.NewFilePath)
+ for i := range c.ExtraFiles {
+ c.ExtraFiles[i].FilePath = rewrite(c.ExtraFiles[i].FilePath)
+ c.ExtraFiles[i].NewFilePath = rewrite(c.ExtraFiles[i].NewFilePath)
+ }
+ }
+ for i := range us.history {
+ rewriteDesc(&us.history[i])
+ }
+ for i := range us.redo {
+ rewriteDesc(&us.redo[i])
+ }
+ us.save()
+}
+
func (us *UndoStack) Push(desc ChangeDesc) {
us.mu.Lock()
defer us.mu.Unlock()