| 275 | } |
| 276 | |
| 277 | func (s *Sync) initialSync(onInitUploadDone chan struct{}, onInitDownloadDone chan struct{}) error { |
| 278 | initialSync := newInitialSyncer(&initialSyncOptions{ |
| 279 | LocalPath: s.LocalPath, |
| 280 | Strategy: s.Options.InitialSync, |
| 281 | CompareBy: s.Options.InitialSyncCompareBy, |
| 282 | |
| 283 | IgnoreMatcher: s.ignoreMatcher, |
| 284 | DownloadIgnoreMatcher: s.downloadIgnoreMatcher, |
| 285 | UploadIgnoreMatcher: s.uploadIgnoreMatcher, |
| 286 | |
| 287 | UpstreamDisabled: s.Options.UpstreamDisabled, |
| 288 | DownstreamDisabled: s.Options.DownstreamDisabled, |
| 289 | FileIndex: s.fileIndex, |
| 290 | |
| 291 | ApplyRemote: s.sendChangesToUpstream, |
| 292 | ApplyLocal: s.downstream.applyChanges, |
| 293 | AddSymlink: s.upstream.AddSymlink, |
| 294 | Log: s.log, |
| 295 | |
| 296 | UpstreamDone: func() { |
| 297 | if !s.Options.UpstreamDisabled { |
| 298 | for s.upstream.IsBusy() { |
| 299 | time.Sleep(time.Millisecond * 100) |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | // signal upstream that initial sync is done |
| 304 | s.upstream.initialSyncCompletedMutex.Lock() |
| 305 | s.upstream.initialSyncCompleted = true |
| 306 | s.upstream.initialSyncCompletedMutex.Unlock() |
| 307 | |
| 308 | // wait until initial sync commands were executed |
| 309 | if !s.Options.UpstreamDisabled { |
| 310 | for s.upstream.IsInitialSyncing() { |
| 311 | time.Sleep(time.Millisecond * 100) |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | if onInitUploadDone != nil { |
| 316 | if s.Options.InitialSync == latest.InitialSyncStrategyDisabled { |
| 317 | s.log.Info("Upstream - Initial sync disabled") |
| 318 | } else { |
| 319 | s.log.Info("Upstream - Initial sync completed") |
| 320 | } |
| 321 | close(onInitUploadDone) |
| 322 | } |
| 323 | }, |
| 324 | DownstreamDone: func() { |
| 325 | if onInitDownloadDone != nil { |
| 326 | if s.Options.InitialSync == latest.InitialSyncStrategyDisabled { |
| 327 | s.log.Info("Downstream - Initial sync disabled") |
| 328 | } else { |
| 329 | s.log.Info("Downstream - Initial sync completed") |
| 330 | } |
| 331 | close(onInitDownloadDone) |
| 332 | } |
| 333 | }, |
| 334 | }) |