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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user