fix(syncthing): apply folder migrations with temporary API/GUI server (#10330)

Prevent the feeling that nothing is happening / it's not starting.

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2025-09-01 22:10:48 +02:00
committed by GitHub
parent fafc3ba45e
commit 541678ad9e
5 changed files with 65 additions and 41 deletions
+4
View File
@@ -86,6 +86,10 @@ func Open(path string, opts ...Option) (*DB, error) {
slog.Warn("Failed to clean dropped folders", slogutil.Error(err))
}
if err := db.startFolderDatabases(); err != nil {
return nil, wrap(err)
}
return db, nil
}
+17
View File
@@ -7,6 +7,7 @@
package sqlite
import (
"errors"
"fmt"
"log/slog"
"os"
@@ -77,6 +78,22 @@ func (s *DB) cleanDroppedFolders() error {
return nil
}
// startFolderDatabases loads all existing folder databases, thus causing
// migrations to apply.
func (s *DB) startFolderDatabases() error {
ids, err := s.ListFolders()
if err != nil {
return wrap(err)
}
for _, id := range ids {
_, err := s.getFolderDB(id, false)
if err != nil && !errors.Is(err, errNoSuchFolder) {
return wrap(err)
}
}
return nil
}
// wrap returns the error wrapped with the calling function name and
// optional extra context strings as prefix. A nil error wraps to nil.
func wrap(err error, context ...string) error {