File.open should throw Errno::EACCES opening non-permitted file
Reported by Jeremy Durham | November 7th, 2007 @ 08:11 PM | in 1.0 preview
sudo touch testfile && sudo chmod 700 testfile
File.open('testfile', 'w')
MRI:
filetest.rb:1:in `initialize': Permission denied - testfile (Errno::EACCES)
from filetest.rb:1:in `open'
from filetest.rb:1
RBX:
(No output)
Also:
File.open('testfile','w') do |f|
f.puts 'test'
end
MRI:
filetest.rb:1:in `initialize': Permission denied - testfile (Errno::EACCES)
from filetest.rb:1:in `open'
from filetest.rb:1
RBX:
test
An exception has occurred:
No method 'closed?' on an instance of NilClass. (NoMethodError)
Backtrace:
Object(NilClass)#closed? (method_missing) at kernel/core/object.rb:93
File.open at kernel/core/file.rb:63
main.__script__ at filetest.rb:1
main.load at kernel/core/compile.rb:78
main.__script__ at kernel/loader.rb:181
I've attached a patch for File.open, but primitives io_open should probably return the error message from the OS so that it can be outputted in the error.
Comments and changes to this ticket
-
Kevin Clark November 11th, 2007 @ 03:24 PM
- → State changed from new to open
The more general solution (which needs some specs) is a call to Errno.handle
-
Kevin Clark November 11th, 2007 @ 03:27 PM
I've got this in a branch locally, but in case someone needs it in the meantime:
diff --git a/spec/core/file/open_spec.rb b/spec/core/file/open_spec.rb
index 64ff7c4..2fcca44 100644
@@ -344,6 +344,14 @@ describe "File.open" do
- it "should throw Errno::EACCES when opening non-permitted file" do
- @fh = File.open(@file, "w")
- @fh.chmod(000)
- should_raise(Errno::EACCES) do
- File.open(@file)
- end
- end
-
Kevin Clark November 11th, 2007 @ 03:49 PM
- → Assigned user changed from to Kevin Clark
-
Kevin Clark November 11th, 2007 @ 07:28 PM
- → State changed from open to resolved
Fixed in 03b7a99f38
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
