(changes []*remote.Change, force bool)
| 225 | } |
| 226 | |
| 227 | func (d *downstream) applyChanges(changes []*remote.Change, force bool) error { |
| 228 | d.sync.log.Debugf("Downstream - Start applying %d changes", len(changes)) |
| 229 | defer d.sync.log.Debugf("Downstream - Done applying changes") |
| 230 | |
| 231 | var ( |
| 232 | download = make([]*remote.Change, 0, len(changes)/2) |
| 233 | remove = make([]*remote.Change, 0, len(changes)/2) |
| 234 | ) |
| 235 | |
| 236 | // Skip if there are no changes |
| 237 | if len(changes) == 0 { |
| 238 | return nil |
| 239 | } |
| 240 | |
| 241 | // determine what to delete and what to download |
| 242 | for _, change := range changes { |
| 243 | if change.ChangeType == remote.ChangeType_DELETE { |
| 244 | remove = append(remove, change) |
| 245 | } else { |
| 246 | download = append(download, change) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // Remove all files and folders that should be deleted first and we ignore errors |
| 251 | d.remove(remove, force) |
| 252 | |
| 253 | // Extract downloaded archive |
| 254 | if len(download) > 0 { |
| 255 | for i := 0; i < syncRetries; i++ { |
| 256 | err := d.initDownload(download) |
| 257 | if err == nil { |
| 258 | break |
| 259 | } else if i+1 >= syncRetries { |
| 260 | return err |
| 261 | } |
| 262 | |
| 263 | d.sync.log.Infof("Downstream - Retry download because of error: %v", err) |
| 264 | |
| 265 | download = d.updateDownloadChanges(download) |
| 266 | if len(download) == 0 { |
| 267 | break |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | d.sync.log.Infof("Downstream - Successfully processed %d change(s)", len(changes)) |
| 273 | return nil |
| 274 | } |
| 275 | |
| 276 | func (d *downstream) updateDownloadChanges(download []*remote.Change) []*remote.Change { |
| 277 | d.sync.fileIndex.fileMapMutex.Lock() |
no test coverage detected