MCPcopy
hub / github.com/syncthing/syncthing / handleIndex

Method handleIndex

lib/model/model.go:1163–1193  ·  view source on GitHub ↗
(conn protocol.Connection, folder string, fs []protocol.FileInfo, update bool, prevSequence, lastSequence int64)

Source from the content-addressed store, hash-verified

1161}
1162
1163func (m *model) handleIndex(conn protocol.Connection, folder string, fs []protocol.FileInfo, update bool, prevSequence, lastSequence int64) error {
1164 op := "Index"
1165 if update {
1166 op += " update"
1167 }
1168
1169 deviceID := conn.DeviceID()
1170 l.Debugf("%v (in): %s / %q: %d files", op, deviceID, folder, len(fs))
1171
1172 if cfg, ok := m.cfg.Folder(folder); !ok || !cfg.SharedWith(deviceID) {
1173 slog.Warn(`Operation for unexpected folder ID; ensure that the folder exists and that this device is selected under "Share With" in the folder configuration.`, slog.String("operation", op), cfg.LogAttr(), deviceID.LogAttr())
1174 return fmt.Errorf("%s: %w", folder, ErrFolderMissing)
1175 } else if cfg.Paused {
1176 l.Debugf("%v for paused folder (ID %q) sent from device %q.", op, folder, deviceID)
1177 return fmt.Errorf("%s: %w", folder, ErrFolderPaused)
1178 }
1179
1180 m.mut.RLock()
1181 indexHandler, ok := m.getIndexHandlerRLocked(conn)
1182 m.mut.RUnlock()
1183 if !ok {
1184 // This should be impossible, as an index handler is registered when
1185 // we send a cluster config, and that is what triggers index
1186 // sending.
1187 m.evLogger.Log(events.Failure, "index sender does not exist for connection on which indexes were received")
1188 l.Debugf("%v for folder (ID %q) sent from device %q: missing index handler", op, folder, deviceID)
1189 return fmt.Errorf("%s: %w", folder, ErrFolderNotRunning)
1190 }
1191
1192 return indexHandler.ReceiveIndex(folder, fs, update, op, prevSequence, lastSequence)
1193}
1194
1195type clusterConfigDeviceInfo struct {
1196 local, remote protocol.Device

Callers 2

IndexMethod · 0.95
IndexUpdateMethod · 0.95

Calls 9

DebugfMethod · 0.80
SharedWithMethod · 0.80
ReceiveIndexMethod · 0.80
DeviceIDMethod · 0.65
FolderMethod · 0.65
StringMethod · 0.65
LogMethod · 0.65
LogAttrMethod · 0.45

Tested by

no test coverage detected