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

Add some path checks around user provided paths #1575

Merged
merged 5 commits into from
Oct 27, 2015

Conversation

kyleknap
Copy link
Contributor

This mainly applies to the existence of user provided local paths. If the transfer is an upload and that local path does not exist, this will cause the command to fail instead of skipping. I realize this will cause a change in status code, but I think a hard fail is the correct behavior. Skipping on a specific path that the user specified should not be happening.

Also, If the transfer is a syncing download and the local path does not existent, there should not be warnings.

All integration test pass as well.

Fixes #1082, #1564

cc @jamesls @mtdowling @rayluo @JordonPhillips

# for listing of files in the destination) in a sync command.
# More specifically this if statement will only be hit if it
# is the file generator listing files for a downloading sync.
if self.operation_name == '':
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel that this was sort of hacky when I wrote it as I am relying on the fact in the code when I instantiate the FileGenerator for the reference files in the destination, the operation_name is set to ''. I want some feedback on this part.

The other option I was thinking of was to introduce a new argument to the constructor that specifies the transfer direction. The reason I did not do it was because it would bloat the constructor and may require a bunch of updates to the tests. Note I am not too concerned about coupling to the command being run here because the FileGenerator already requires an operation name.

@kyleknap kyleknap added the pr:needs-review This PR needs a review from a Member. label Oct 20, 2015
@jamesls
Copy link
Member

jamesls commented Oct 21, 2015

Doesn't it seem simpler to just, much higher up the stack before doing an upload, validate that the local source exists? We should be able to do it before even getting into any of the command architecture code paths.

@kyleknap
Copy link
Contributor Author

I think it was because I was concerned with follow_symlinks check right above it. But now that I think about it, I do not think that should be a concern because the if statment is only hit if the --no-follow_symlinks flag is set. If this is set, it will still hit the previous warning about a file not existing because the file will not be a symlink as it does not exist.

The other issue that I was concerned is with regards to #1082. If I add the logic higher up in the stack. The only way to fix this issue is to completely short circuit the reverse filegenerator, which I am not sure how easy it is for syncing. Maybe make a no op filegenerator but that seems messy to me.

I am fine with the first part, but with the second part, I do not have a great idea on how to get around it. Do you have any ideas on how to do that? I could hoist the logic to the call() method of the FileGenerator to prevent bloating the rest of the methods. Is that what you had in mind?

@jamesls
Copy link
Member

jamesls commented Oct 21, 2015

@kyleknap I'm not following how these is a problem. Is your first concern we'd have to duplicate the symlink checking logic somewhere in CommandParams?

Also I'm not quite sure I understand the second point, maybe because I don't know the root cause. Why do we need to possibly short circuit the reverse filegenerator?

@kyleknap
Copy link
Contributor Author

No the first paragraph is no longer an issue. I was just explaining (a little bit too my self as well) a possible issue, but it ended up not being an issue.

The second one is an issue because in order to avoid modifying the should_ignore method and not throw the warning, I need to avoid calling the list_files because currently it will always check the user provided path (which may not exist, but it does not matter because we will still download it and create the appropriate directories) for a downloading sync. So by short circuit, I mean I need to either provide a new reverse file generator that does a no op in the subcommands.CommandArchitecture class or immediately return before the list_files happens to avoid checking whether destination local directory exists. I think I am leaning toward the later option. Does that make sense?

@jamesls
Copy link
Member

jamesls commented Oct 21, 2015

I'm definitely missing something. Can we not just create the directory before doing any transfers? Let me give something more specific. Why doesn't something like this work for your second case?

# in subcommands.py
if dir_op and path_type == 's3local':
  if not os.path.exists(params['dest']):
    os.makedirs(params['dest'])

@kyleknap
Copy link
Contributor Author

Yeah that would be simpler. The only thing is that it is kind of weird that we are making modifications to the file system there as opposed to in s3handler and fileinfo.

@kyleknap kyleknap force-pushed the exist-local-check branch 3 times, most recently from 0549048 to e81ac19 Compare October 21, 2015 23:14
@kyleknap
Copy link
Contributor Author

Alright I updated the PR. Integration tests still pass.

@jamesls
Copy link
Member

jamesls commented Oct 22, 2015

CommandParameters already has has pre-existing validation of parameters. Was there a reason not to add this logic to that class?

@kyleknap
Copy link
Contributor Author

No, I just had forgotten about that class. Had not looked at it for a long time, and it shown. There were methods in the class that we not even used and some tests were using internal methods...

I update the PR. Integration tests still pass.

@jamesls
Copy link
Member

jamesls commented Oct 23, 2015

:shipit:

This mainly applies to the existance of user provided local paths.
If the transfer is an upload and that local path does not exist, this will
cause the command to fail instead of skipping. If the transfer is a
syncing download and the local path does not existant, there should not
be warnings.
Hoisted the user provided local paths to the CommandArchitecture class
kyleknap added a commit that referenced this pull request Oct 27, 2015
Add some path checks around user provided paths
@kyleknap kyleknap merged commit af3a079 into aws:develop Oct 27, 2015
@kyleknap kyleknap deleted the exist-local-check branch October 27, 2015 16:49
thoward-godaddy pushed a commit to thoward-godaddy/aws-cli that referenced this pull request Feb 12, 2022
* test: Verify samconfig is accessible to all CLI commands

* fix cases where comma vs space needs to be delimiter

* adding few more unit tests

* adding unit tests for all commands

* fix linter

* Adding tests for overriding args thru config, CLI args, and envvars

* Fixing a minor UX issue when sam template is invalid

* fixing mock imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:needs-review This PR needs a review from a Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants