-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
knife client create should check file permissions #11241
knife client create should check file permissions #11241
Conversation
2db12b6
to
3b66e32
Compare
lib/chef/knife/client_create.rb
Outdated
if config[:file] | ||
file = config[:file] | ||
unless File.exist?(file) ? File.writable?(file) : File.writable?(File.dirname(file)) | ||
ui.fatal "File #{config[:file]} is not writable. Check permissions." |
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.
This should really be two different conditionals with two different error messages. When the file does not exist and the directory is not writable the error message should be separate and there should really be two different conditionals here for readability.
aad0550
to
e103941
Compare
@snehaldwivedi This will need to get rebased for the recent refactoring we did to knife. |
e103941
to
944aee7
Compare
1a55a98
to
7e46d2a
Compare
exit 1 | ||
end | ||
|
||
unless File.writable?(file) |
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.
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.
yes, if the file is writable then only it will return true else false. You can also go through documentation here. Now as per your example:
File.writable?("does-not-exist")
it has checked if the given file is writable or not and returnsfalse
as it doesn't exist.File.write("does-not-exist", "blah")
it returns 4. Here it will create a new file "does-not-exist" and add a content "blah" can returns length of the content.File.writable?("does-not-exist")
now after 2nd point where the file is not created nowFile.writable?
is returntrue
.
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.
My concern is less functional, and more user experience - it is correct that the directory is not writable and the action should fail.
But in the case where the directory for /tmp/test/afile.out
does not exist, we will report an error that Dir '/tmp/test/' is not writable. Check permissions
. This is misleading, and we could provide more actionable feedback than "check permissions". It would be better to specifically verify that the directory exists and report that error independently of permissions-related errors.
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.
@marcparadise Got your point. I Will update the condition accordingly.
f466976
to
7edc105
Compare
exit 1 | ||
end | ||
else | ||
ui.fatal "#{type} #{file} dose not exist." |
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.
Should be "does not exist."
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.
This good and will be ready to merge once the typo (dose -> does) is fixed.
7cac3b5
to
2bf5fb8
Compare
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
2bf5fb8
to
6ea8158
Compare
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
6ea8158
to
fb087a1
Compare
Description
Support user-friendly error checking on file permissions for
knife client create
knife user create
is already covered in PRRelated Issue
#3514
#3517
Types of changes
Checklist: