Skip to content
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

context: put quotes around flagvalue incase of whitespaced values #636

Merged
merged 1 commit into from
Aug 7, 2023

Conversation

ataberkgrl
Copy link
Contributor

Resolves #541

While running the sync command it starts to generate cp commands in the generateCommand function and writes it to a pipe where it is read by the Run function of the Run command. In the Run function, there is a line

fields, err := shellquote.Split(line)

to split the generated cp command into its fields.



 For a command



s5cmd sync --cache-control ‘public, max-age=31536000, immutable’ /Users/ataberk/desktop/test s3://s5cmd-test2

We would have expected the generateCommand function to write into the pipe a command



cp --cache-control='public, max-age=31536000, immutable' --raw='true' \"/Users/ataberk/desktop/test/hello.txt\" \"s3://s5cmd-test2/test/hello.txt\"

But instead, it writes the command



cp --cache-control=public, max-age=31536000, immutable --raw=true \"/Users/ataberk/desktop/test/hello.txt\" \"s3://s5cmd-test2/test/hello.txt\"

Screenshot 2023-08-05 at 13 45 52

This causes the shellquote.Split(line) to split fields incorrectly. This causes flagset.Parse(fields) to populate flagset incorrectly and as a result we end up with an error.

Screenshot 2023-08-05 at 05 53 43

The main problem occurs in the generateCommand function while appending flags without quotes. If we add quotes around the flagValue while generating a command. The shellquote.Split(line) acts as intended and successfully sync with the given cache-control metadata in S3

Screenshot 2023-08-05 at 13 58 28

Screenshot 2023-08-05 at 13 59 31

@ataberkgrl ataberkgrl requested a review from a team as a code owner August 5, 2023 11:27
@ataberkgrl ataberkgrl requested review from ilkinulas and sonmezonur and removed request for a team August 5, 2023 11:27
Copy link
Member

@sonmezonur sonmezonur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Could you please add a test for your use case? (example command you shared)

@sonmezonur sonmezonur merged commit 5bb45b6 into peak:master Aug 7, 2023
13 checks passed
@7rulnik
Copy link

7rulnik commented Aug 7, 2023

Thanks, guys ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sync doesn't allow whitspaces in --cache-control
4 participants