-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix single object cases for sync #740
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tarikozyurtt
requested review from
ilkinulas and
seruman
and removed request for
a team
July 10, 2024 15:31
tarikozyurtt
changed the title
fix: fix nested directory cases for object sync
fix: fix single object cases for object sync
Jul 11, 2024
tarikozyurtt
changed the title
fix: fix single object cases for object sync
fix: fix single object cases for sync
Jul 11, 2024
seruman
reviewed
Jul 11, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the fix.
all my reviews are on the style side.
Fixed styles and naming. |
seruman
approved these changes
Jul 11, 2024
ilkinulas
approved these changes
Jul 12, 2024
tarikozyurtt
added a commit
to tarikozyurtt/s5cmd
that referenced
this pull request
Jul 12, 2024
The problem is mainly caused by the `compareObjects` function inside `command/sync.go`, where `s5cmd` compares source and destination paths and extracts files that are present only in the source or destination path (while also counting nested folders or rather name with its prefixes) along with common objects. If they both are non-objects, like wildcard expression, prefix, or bucket, getting relative paths of files with `src.URL.Relative()` results in compatible and comparable paths. In this case, no problem is present, at least within the scope of this issue. However, when an object is selected as the source, it is not assigned a relative path using `func (u *url.URL) SetRelative(base *url.URL)`, so the `src.URL.Relative()` function returns its absolute path. Let's say the source file has an absolute path of `folder/foo.txt`. The algorithm compares `folder/foo.txt` with `s3://bucket/remoteFolder/` and looks for the item `s3://bucket/remoteFolder/folder/foo.txt`. If it does not match, except for the edge case where there is a duplicate item inside the searched path, the files never match. While copying files, `s5cmd` does not use relative paths, so `foo.txt` is written to the intended path in the remote. However, this happens during every sync operation, as they do not match. Problem solved by taking path of source object as its name. This made algorithm to simply look for matches in destination, a file named `foo.txt` as intended. This PR adds new test cases to the sync command. Previously, tests failed to capture sync command cases where the source is an object in a prefix, not an object directly in a bucket, or not multiple objects like a wildcard or prefix expression. If an object is in the `s3://bucket/` path, its relative path is the same as its absolute path, so they match during comparison. This prevented copying the file every time. The new test cases cover all scenarios. Resolves: peak#676.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem is mainly caused by the
compareObjects
function insidecommand/sync.go
, wheres5cmd
compares source and destination paths and extracts files that are present only in the source or destination path (while also counting nested folders or rather name with its prefixes) along with common objects. If they both are non-objects, like wildcard expression, prefix, or bucket, getting relative paths of files withsrc.URL.Relative()
results in compatible and comparable paths. In this case, no problem is present, at least within the scope of this issue.However, when an object is selected as the source, it is not assigned a relative path using
func (u *url.URL) SetRelative(base *url.URL)
, so thesrc.URL.Relative()
function returns its absolute path.Let's say the source file has an absolute path of
folder/foo.txt
. The algorithm comparesfolder/foo.txt
withs3://bucket/remoteFolder/
and looks for the items3://bucket/remoteFolder/folder/foo.txt
. If it does not match, except for the edge case where there is a duplicate item inside the searched path, the files never match.While copying files,
s5cmd
does not use relative paths, sofoo.txt
is written to the intended path in the remote. However, this happens during every sync operation, as they do not match.Problem solved by taking path of source object as its name. This made algorithm to simply look for matches in destination, a file named
foo.txt
as intended.This PR adds new test cases to the sync command. Previously, tests failed to capture sync command cases where the source is an object in a prefix, not an object directly in a bucket, or not multiple objects like a wildcard or prefix expression.
If an object is in the
s3://bucket/
path, its relative path is the same as its absolute path, so they match during comparison. This prevented copying the file every time. The new test cases cover all scenarios.Resolves: #676.