(changes []*FileInformation, remove bool)
| 370 | } |
| 371 | |
| 372 | func (s *Sync) sendChangesToUpstream(changes []*FileInformation, remove bool) { |
| 373 | for j := 0; j < len(changes); j += initialUpstreamBatchSize { |
| 374 | // Wait till upstream channel is empty |
| 375 | for len(s.upstream.events) > 0 { |
| 376 | time.Sleep(time.Millisecond * 500) |
| 377 | } |
| 378 | |
| 379 | // Now we send them to upstream |
| 380 | sendBatch := make([]*FileInformation, 0, initialUpstreamBatchSize) |
| 381 | s.fileIndex.fileMapMutex.Lock() |
| 382 | |
| 383 | for i := j; i < (j+initialUpstreamBatchSize) && i < len(changes); i++ { |
| 384 | if remove { |
| 385 | sendBatch = append(sendBatch, changes[i]) |
| 386 | } else if s.fileIndex.fileMap[changes[i].Name] == nil || !equalFilePermissions(changes[i].Mode, s.fileIndex.fileMap[changes[i].Name].Mode) || changes[i].Mtime != s.fileIndex.fileMap[changes[i].Name].Mtime || changes[i].Size != s.fileIndex.fileMap[changes[i].Name].Size { |
| 387 | sendBatch = append(sendBatch, changes[i]) |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | s.fileIndex.fileMapMutex.Unlock() |
| 392 | |
| 393 | // We do this out of the fileIndex lock, because otherwise this could cause a deadlock |
| 394 | // (Upstream waits in getfileInformationFromEvent and upstream.events buffer is full) |
| 395 | for i := 0; i < len(sendBatch); i++ { |
| 396 | s.upstream.isBusyMutex.Lock() |
| 397 | s.upstream.isBusy = true |
| 398 | s.upstream.events <- sendBatch[i] |
| 399 | s.upstream.isBusyMutex.Unlock() |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func equalFilePermissions(mode os.FileMode, mode2 os.FileMode) bool { |
| 405 | if runtime.GOOS != "linux" && runtime.GOOS != "darwin" { |
nothing calls this directly
no test coverage detected