MCPcopy Index your code
hub / github.com/syncthing/syncthing / Update

Method Update

internal/db/sqlite/folderdb_update.go:34–189  ·  view source on GitHub ↗
(device protocol.DeviceID, fs []protocol.FileInfo, options db.UpdateOptions)

Source from the content-addressed store, hash-verified

32)
33
34func (s *folderDB) Update(device protocol.DeviceID, fs []protocol.FileInfo, options db.UpdateOptions) error {
35 s.updateLock.Lock()
36 defer s.updateLock.Unlock()
37
38 deviceIdx, err := s.deviceIdxLocked(device)
39 if err != nil {
40 return wrap(err)
41 }
42
43 tx, err := s.sql.BeginTxx(context.Background(), nil)
44 if err != nil {
45 return wrap(err)
46 }
47 defer tx.Rollback() //nolint:errcheck
48 txp := &txPreparedStmts{Tx: tx}
49
50 //nolint:sqlclosecheck
51 insertNameStmt, err := txp.Preparex(`
52 INSERT INTO file_names(name)
53 VALUES (?)
54 ON CONFLICT(name) DO UPDATE
55 SET name = excluded.name
56 RETURNING idx
57 `)
58 if err != nil {
59 return wrap(err, "prepare insert name")
60 }
61
62 //nolint:sqlclosecheck
63 insertVersionStmt, err := txp.Preparex(`
64 INSERT INTO file_versions (version)
65 VALUES (?)
66 ON CONFLICT(version) DO UPDATE
67 SET version = excluded.version
68 RETURNING idx
69 `)
70 if err != nil {
71 return wrap(err, "prepare insert version")
72 }
73
74 //nolint:sqlclosecheck
75 insertFileStmt, err := txp.Preparex(`
76 INSERT OR REPLACE INTO files (device_idx, remote_sequence, type, modified, size, deleted, local_flags, blocklist_hash, name_idx, version_idx)
77 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
78 RETURNING sequence
79 `)
80 if err != nil {
81 return wrap(err, "prepare insert file")
82 }
83
84 //nolint:sqlclosecheck
85 insertFileInfoStmt, err := txp.Preparex(`
86 INSERT INTO fileinfos (sequence, fiprotobuf)
87 VALUES (?, ?)
88 `)
89 if err != nil {
90 return wrap(err, "prepare insert fileinfo")
91 }

Callers

nothing calls this directly

Calls 15

deviceIdxLockedMethod · 0.95
PreparexMethod · 0.95
insertBlocksLockedMethod · 0.95
recalcGlobalForFileMethod · 0.95
NormalizedFilenameFunction · 0.92
BlocksHashFunction · 0.92
MapFunction · 0.92
UnlockMethod · 0.80
RollbackMethod · 0.80
IsDeletedMethod · 0.80
MarshalMethod · 0.80

Tested by

no test coverage detected