ChangesCount returns the amount of changes on the remote side
(context.Context, *remote.Empty)
| 230 | |
| 231 | // ChangesCount returns the amount of changes on the remote side |
| 232 | func (d *Downstream) ChangesCount(context.Context, *remote.Empty) (*remote.ChangeAmount, error) { |
| 233 | newState := make(map[string]*remote.Change) |
| 234 | throttle := time.Duration(d.options.Throttle) * time.Millisecond |
| 235 | |
| 236 | // Walk through the dir |
| 237 | if d.options.Polling { |
| 238 | walkDir(d.options.RemotePath, d.options.RemotePath, d.ignoreMatcher, newState, d.options.NoRecursiveWatch, throttle) |
| 239 | } |
| 240 | |
| 241 | changeAmount := int64(0) |
| 242 | if d.options.Polling { |
| 243 | var err error |
| 244 | changeAmount, err = streamChanges(d.options.RemotePath, d.watchedFiles, newState, nil, throttle) |
| 245 | if err != nil { |
| 246 | return nil, errors.Wrap(err, "count changes") |
| 247 | } |
| 248 | } else { |
| 249 | d.changesMutex.Lock() |
| 250 | // if rescan is not set we make sure that we say that there |
| 251 | // are changes |
| 252 | if d.lastRescan == nil { |
| 253 | changeAmount = int64(1) |
| 254 | } else { |
| 255 | changeAmount = int64(len(d.changes)) |
| 256 | } |
| 257 | d.changesMutex.Unlock() |
| 258 | } |
| 259 | |
| 260 | return &remote.ChangeAmount{ |
| 261 | Amount: changeAmount, |
| 262 | }, nil |
| 263 | } |
| 264 | |
| 265 | func (d *Downstream) getWatchState() map[string]*remote.Change { |
| 266 | d.changesMutex.Lock() |
nothing calls this directly
no test coverage detected