Completion returns the completion status, in percent with some counters, for the given device and folder. The device can be any known device ID (including the local device) or explicitly protocol.LocalDeviceID. An empty folder string means the aggregate of all folders shared with the given device.
(device protocol.DeviceID, folder string)
| 881 | // empty folder string means the aggregate of all folders shared with the |
| 882 | // given device. |
| 883 | func (m *model) Completion(device protocol.DeviceID, folder string) (FolderCompletion, error) { |
| 884 | // The user specifically asked for our own device ID. Internally that is |
| 885 | // known as protocol.LocalDeviceID so translate. |
| 886 | if device == m.id { |
| 887 | device = protocol.LocalDeviceID |
| 888 | } |
| 889 | |
| 890 | if folder != "" { |
| 891 | // We want completion for a specific folder. |
| 892 | return m.folderCompletion(device, folder) |
| 893 | } |
| 894 | |
| 895 | // We want completion for all (shared) folders as an aggregate. |
| 896 | var comp FolderCompletion |
| 897 | for _, fcfg := range m.cfg.FolderList() { |
| 898 | if fcfg.Paused { |
| 899 | continue |
| 900 | } |
| 901 | if device == protocol.LocalDeviceID || fcfg.SharedWith(device) { |
| 902 | folderComp, err := m.folderCompletion(device, fcfg.ID) |
| 903 | if errors.Is(err, ErrFolderPaused) { |
| 904 | continue |
| 905 | } else if err != nil { |
| 906 | return FolderCompletion{}, err |
| 907 | } |
| 908 | comp.add(folderComp) |
| 909 | } |
| 910 | } |
| 911 | return comp, nil |
| 912 | } |
| 913 | |
| 914 | func (m *model) folderCompletion(device protocol.DeviceID, folder string) (FolderCompletion, error) { |
| 915 | m.mut.RLock() |
nothing calls this directly
no test coverage detected