MCPcopy Index your code
hub / github.com/peak/s5cmd / compareObjects

Function compareObjects

command/sync.go:245–298  ·  view source on GitHub ↗

compareObjects compares source and destination objects. It assumes that sourceObjects and destObjects channels are already sorted in ascending order. Returns objects those in only source, only destination and both.

(sourceObjects, destObjects chan *storage.Object, isSrcBatch bool)

Source from the content-addressed store, hash-verified

243// Returns objects those in only source, only destination
244// and both.
245func compareObjects(sourceObjects, destObjects chan *storage.Object, isSrcBatch bool) (chan *url.URL, chan *url.URL, chan *ObjectPair) {
246 var (
247 srcOnly = make(chan *url.URL, extsortChannelBufferSize)
248 dstOnly = make(chan *url.URL, extsortChannelBufferSize)
249 commonObj = make(chan *ObjectPair, extsortChannelBufferSize)
250 srcName string
251 dstName string
252 )
253
254 go func() {
255 src, srcOk := <-sourceObjects
256 dst, dstOk := <-destObjects
257
258 defer close(srcOnly)
259 defer close(dstOnly)
260 defer close(commonObj)
261
262 for {
263 if srcOk {
264 srcName = filepath.ToSlash(src.URL.Relative())
265 if !isSrcBatch {
266 srcName = src.URL.Base()
267 }
268 }
269 if dstOk {
270 dstName = filepath.ToSlash(dst.URL.Relative())
271 }
272
273 if srcOk && dstOk {
274 if srcName < dstName {
275 srcOnly <- src.URL
276 src, srcOk = <-sourceObjects
277 } else if srcName == dstName { // if there is a match.
278 commonObj <- &ObjectPair{src: src, dst: dst}
279 src, srcOk = <-sourceObjects
280 dst, dstOk = <-destObjects
281 } else {
282 dstOnly <- dst.URL
283 dst, dstOk = <-destObjects
284 }
285 } else if srcOk {
286 srcOnly <- src.URL
287 src, srcOk = <-sourceObjects
288 } else if dstOk {
289 dstOnly <- dst.URL
290 dst, dstOk = <-destObjects
291 } else /* if !srcOK && !dstOk */ {
292 break
293 }
294 }
295 }()
296
297 return srcOnly, dstOnly, commonObj
298}
299
300// getSourceAndDestinationObjects returns source and destination objects from
301// given URLs. The returned channels gives objects sorted in ascending order

Callers 1

RunMethod · 0.85

Calls 2

RelativeMethod · 0.80
BaseMethod · 0.80

Tested by

no test coverage detected