Skip to content

Commit

Permalink
fix: sync glacier objects overwrite (#734)
Browse files Browse the repository at this point in the history
This pull request addresses a bug (#712) in the sync command where
objects in Glacier storage at the destination were being overwritten
during synchronization. closes #712

## Bug Details:

During the sync process, if an object exists in both the source and
destination, and the destination object is in Glacier storage, it was
incorrectly being overwritten by the source object.

## Fixes:

- Modified the function that checks which objects to compare. 

Previously, if either the source or destination object was in Glacier
storage, it was skipped. In the new version, only the source object is
skipped, but the destination object is not. If the destination object is
skipped, it will be considered as only in the source during the
comparison phase, leading to it being overwritten by the source object.

- Added tests for this specific case to ensure correctness.

---------

Co-authored-by: İbrahim Güngör <[email protected]>
Co-authored-by: İlkin Balkanay <[email protected]>
Co-authored-by: S.Burak Yaşar <[email protected]>
  • Loading branch information
4 people authored Nov 27, 2024
1 parent 8829d3b commit d72716a
Show file tree
Hide file tree
Showing 15 changed files with 616 additions and 73 deletions.
21 changes: 18 additions & 3 deletions command/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (s Sync) getSourceAndDestinationObjects(ctx context.Context, cancel context
log.Error(msg)
cancel()
}
if s.shouldSkipObject(st, true) {
if s.shouldSkipSrcObject(st, true) {
continue
}
filteredSrcObjectChannel <- *st
Expand Down Expand Up @@ -404,7 +404,7 @@ func (s Sync) getSourceAndDestinationObjects(ctx context.Context, cancel context
log.Error(msg)
cancel()
}
if s.shouldSkipObject(dt, false) {
if s.shouldSkipDstObject(dt, false) {
continue
}
filteredDstObjectChannel <- *dt
Expand Down Expand Up @@ -550,7 +550,7 @@ func generateDestinationURL(srcurl, dsturl *url.URL, isBatch bool) *url.URL {
}

// shouldSkipObject checks is object should be skipped.
func (s Sync) shouldSkipObject(object *storage.Object, verbose bool) bool {
func (s Sync) shouldSkipSrcObject(object *storage.Object, verbose bool) bool {
if object.Type.IsDir() || errorpkg.IsCancelation(object.Err) {
return true
}
Expand All @@ -572,6 +572,21 @@ func (s Sync) shouldSkipObject(object *storage.Object, verbose bool) bool {
return false
}

func (s Sync) shouldSkipDstObject(object *storage.Object, verbose bool) bool {
if object.Type.IsDir() || errorpkg.IsCancelation(object.Err) {
return true
}

if err := object.Err; err != nil {
if verbose {
printError(s.fullCommand, s.op, err)
}
return true
}

return false
}

// shouldStopSync determines whether a sync process should be stopped or not.
func (s Sync) shouldStopSync(err error) bool {
if err == storage.ErrNoObjectFound {
Expand Down
Loading

0 comments on commit d72716a

Please sign in to comment.