fix(db): report write errors, multi-step changes all or nothing (FLAW-14)
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m4s

Store.execInTx runs related statements in one transaction and returns
the first error. Used for deleting and moving folders (with the trash),
shared folders, folder shares and mounts, deleting task lists and
accounts, pinning, and the password reset (new password and the end of
all other links together). Writes whose success the API reports now
pass their error to the client (logout, new password, setup, sharing
mode, new group, restore, unlinking a note block), follow-up tasks and
alarm markers log failures. Remaining ignored writes are listed as
intentional in flaws.md.

Found on the way: DeleteTaskList unlinked all tasks before checking
ownership, so a stranger with the list ID could empty it; viewers could
unlink tasks from note blocks. Both fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-10-29 14:59:23 +01:00
1 parent 792ca946f8
commit 6b56a33500
19 files changed
+274 -112

No files matched your search

+31 -1
View File
@@ -5,6 +5,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
@@ -665,7 +666,36 @@ func (s *Store) migrateWorkspaceToPureDB() {
}
_ = sfRows.Close()
for _, info := range sfs {
s.syncSharedFolderContents(info.ownerID, info.id, info.mountPath)
if err := s.syncSharedFolderContents(info.ownerID, info.id, info.mountPath); err != nil {
slog.Error("Geteilte Ordner abgleichen fehlgeschlagen", "folder", info.id, "error", err)
}
}
}
}
// sqlStmt is one statement of a change with several steps (FLAW-14).
type sqlStmt struct {
query string
args []interface{}
}
func stmt(query string, args ...interface{}) sqlStmt { return sqlStmt{query, args} }
// execInTx runs all statements in one transaction: either every step is stored or none, and the
// first error is returned instead of being ignored.
func (s *Store) execInTx(stmts ...sqlStmt) error {
if len(stmts) == 0 {
return nil
}
tx, err := s.db.Begin()
if err != nil {
return err
}
defer tx.Rollback()
for _, st := range stmts {
if _, err := tx.Exec(st.query, st.args...); err != nil {
return err
}
}
return tx.Commit()
}