getSourceAndDestinationObjects returns source and destination objects from given URLs. The returned channels gives objects sorted in ascending order with respect to their url.Relative path. See also storage.Less.
(ctx context.Context, cancel context.CancelFunc, srcurl, dsturl *url.URL)
| 301 | // given URLs. The returned channels gives objects sorted in ascending order |
| 302 | // with respect to their url.Relative path. See also storage.Less. |
| 303 | func (s Sync) getSourceAndDestinationObjects(ctx context.Context, cancel context.CancelFunc, srcurl, dsturl *url.URL) (chan *storage.Object, chan *storage.Object, error) { |
| 304 | sourceClient, err := storage.NewClient(ctx, srcurl, s.storageOpts) |
| 305 | if err != nil { |
| 306 | return nil, nil, err |
| 307 | } |
| 308 | |
| 309 | destClient, err := storage.NewClient(ctx, dsturl, s.storageOpts) |
| 310 | if err != nil { |
| 311 | return nil, nil, err |
| 312 | } |
| 313 | |
| 314 | // add * to end of destination string, to get all objects recursively. |
| 315 | var destinationURLPath string |
| 316 | if strings.HasSuffix(s.dst, "/") { |
| 317 | destinationURLPath = s.dst + "*" |
| 318 | } else { |
| 319 | destinationURLPath = s.dst + "/*" |
| 320 | } |
| 321 | |
| 322 | destObjectsURL, err := url.New(destinationURLPath) |
| 323 | if err != nil { |
| 324 | return nil, nil, err |
| 325 | } |
| 326 | |
| 327 | var ( |
| 328 | sourceObjects = make(chan *storage.Object, extsortChannelBufferSize) |
| 329 | destObjects = make(chan *storage.Object, extsortChannelBufferSize) |
| 330 | ) |
| 331 | |
| 332 | extsortDefaultConfig := extsort.DefaultConfig() |
| 333 | extsortConfig := &extsort.Config{ |
| 334 | ChunkSize: extsortChunkSize, |
| 335 | NumWorkers: extsortDefaultConfig.NumWorkers, |
| 336 | ChanBuffSize: extsortChannelBufferSize, |
| 337 | SortedChanBuffSize: extsortChannelBufferSize, |
| 338 | } |
| 339 | extsortDefaultConfig = nil |
| 340 | |
| 341 | // get source objects. |
| 342 | go func() { |
| 343 | defer close(sourceObjects) |
| 344 | unfilteredSrcObjectChannel := sourceClient.List(ctx, srcurl, s.followSymlinks) |
| 345 | filteredSrcObjectChannel := make(chan extsort.SortType, extsortChannelBufferSize) |
| 346 | |
| 347 | go func() { |
| 348 | defer close(filteredSrcObjectChannel) |
| 349 | // filter and redirect objects |
| 350 | for st := range unfilteredSrcObjectChannel { |
| 351 | if st.Err != nil && s.shouldStopSync(st.Err) { |
| 352 | msg := log.ErrorMessage{ |
| 353 | Err: cleanupError(st.Err), |
| 354 | Command: s.fullCommand, |
| 355 | Operation: s.op, |
| 356 | } |
| 357 | log.Error(msg) |
| 358 | cancel() |
| 359 | } |
| 360 | if s.shouldSkipSrcObject(st, true) { |
no test coverage detected