MCPcopy
hub / github.com/syncthing/syncthing / runScripts

Method runScripts

internal/db/sqlite/basedb.go:295–329  ·  view source on GitHub ↗
(tx *sqlx.Tx, glob string, filter ...func(s string) bool)

Source from the content-addressed store, hash-verified

293func (f failedStmt) Select(_ any, _ ...any) error { return f.err }
294
295func (s *baseDB) runScripts(tx *sqlx.Tx, glob string, filter ...func(s string) bool) error {
296 scripts, err := fs.Glob(embedded, glob)
297 if err != nil {
298 return wrap(err)
299 }
300
301nextScript:
302 for _, scr := range scripts {
303 for _, fn := range filter {
304 if !fn(scr) {
305 continue nextScript
306 }
307 }
308 bs, err := fs.ReadFile(embedded, scr)
309 if err != nil {
310 return wrap(err, scr)
311 }
312 // SQLite requires one statement per exec, so we split the init
313 // files on lines containing only a semicolon and execute them
314 // separately. We require it on a separate line because there are
315 // also statement-internal semicolons in the triggers.
316 for _, stmt := range strings.Split(string(bs), "\n;") {
317 if _, err := tx.Exec(s.expandTemplateVars(stmt)); err != nil {
318 if strings.Contains(stmt, "syncthing:ignore-failure") {
319 // We're ok with this failing. Just note it.
320 slog.Debug("Script failed, but with ignore-failure annotation", slog.String("script", scr), slogutil.Error(wrap(err, stmt)))
321 } else {
322 return wrap(err, stmt)
323 }
324 }
325 }
326 }
327
328 return nil
329}
330
331type schemaVersion struct {
332 SchemaVersion int

Callers 1

openBaseFunction · 0.95

Calls 7

expandTemplateVarsMethod · 0.95
ErrorFunction · 0.92
ContainsMethod · 0.80
wrapFunction · 0.70
GlobMethod · 0.65
ExecMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected