Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1870 from eregon/file_chown_chmod_errors

File chown chmod errors
  • Loading branch information...
commit af9f288de17d5ad42dc75dd0c8e5c7e800fe0be5 2 parents aa6c225 + 2e1780f
@brixen brixen authored
View
20 kernel/common/file.rb
@@ -176,7 +176,8 @@ def self.chmod(mode, *paths)
mode = clamp_short mode
paths.each do |path|
- POSIX.chmod Rubinius::Type.coerce_to_path(path), mode
+ n = POSIX.chmod Rubinius::Type.coerce_to_path(path), mode
+ Errno.handle if n == -1
end
paths.size
end
@@ -190,7 +191,8 @@ def self.lchmod(mode, *paths)
mode = Rubinius::Type.coerce_to(mode, Integer, :to_int)
paths.each do |path|
- POSIX.lchmod Rubinius::Type.coerce_to_path(path), mode
+ n = POSIX.lchmod Rubinius::Type.coerce_to_path(path), mode
+ Errno.handle if n == -1
end
paths.size
@@ -221,7 +223,8 @@ def self.chown(owner, group, *paths)
end
paths.each do |path|
- POSIX.chown Rubinius::Type.coerce_to_path(path), owner, group
+ n = POSIX.chown Rubinius::Type.coerce_to_path(path), owner, group
+ Errno.handle if n == -1
end
paths.size
@@ -229,7 +232,9 @@ def self.chown(owner, group, *paths)
def chmod(mode)
mode = Rubinius::Type.coerce_to(mode, Integer, :to_int)
- POSIX.fchmod @descriptor, clamp_short(mode)
+ n = POSIX.fchmod @descriptor, clamp_short(mode)
+ Errno.handle if n == -1
+ n
end
def chown(owner, group)
@@ -245,7 +250,9 @@ def chown(owner, group)
group = -1
end
- POSIX.fchown @descriptor, owner, group
+ n = POSIX.fchown @descriptor, owner, group
+ Errno.handle if n == -1
+ n
end
##
@@ -268,7 +275,8 @@ def self.lchown(owner, group, *paths)
end
paths.each do |path|
- POSIX.lchown Rubinius::Type.coerce_to_path(path), owner, group
+ n = POSIX.lchown Rubinius::Type.coerce_to_path(path), owner, group
+ Errno.handle if n == -1
end
paths.size
View
6 spec/ruby/core/file/chmod_spec.rb
@@ -169,6 +169,12 @@
lambda { File.chmod(0, []) }.should raise_error(TypeError)
end
+ it "raises an error for a non existent path" do
+ lambda {
+ File.chmod(0644, "#{@file}.not.existing")
+ }.should raise_error(Errno::ENOENT)
+ end
+
it "invokes to_int on non-integer argument" do
mode = File.stat(@file).mode
(obj = mock('mode')).should_receive(:to_int).and_return(mode)
View
50 spec/ruby/core/file/chown_spec.rb
@@ -1,16 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
-as_superuser do
- describe "File.chown" do
- before :each do
- @fname = tmp('file_chown_test')
- touch @fname
- end
+describe "File.chown" do
+ before :each do
+ @fname = tmp('file_chown_test')
+ touch @fname
+ end
- after :each do
- rm_r @fname
- end
+ after :each do
+ rm_r @fname
+ end
+ as_superuser do
platform_is :windows do
it "does not modify the owner id of the file" do
File.chown 0, nil, @fname
@@ -57,20 +57,27 @@
File.chown nil, -1, @fname
File.stat(@fname).gid.should == 501
end
+ end
+ end
- it "returns the number of files processed" do
- File.chown(nil, nil, @fname, @fname).should == 2
- end
+ it "returns the number of files processed" do
+ File.chown(nil, nil, @fname, @fname).should == 2
+ end
- ruby_version_is "1.9" do
- it "accepts an object that has a #to_path method" do
- File.chown(nil, nil, mock_to_path(@fname)).should == 1
- end
- end
+ it "raises an error for a non existent path" do
+ lambda {
+ File.chown(nil, nil, "#{@fname}.not.existing")
+ }.should raise_error(Errno::ENOENT)
+ end
+
+ ruby_version_is "1.9" do
+ it "accepts an object that has a #to_path method" do
+ File.chown(nil, nil, mock_to_path(@fname)).should == 1
end
end
+end
- describe "File#chown" do
+describe "File#chown" do
before :each do
@fname = tmp('file_chown_test')
@file = File.open(@fname, 'w')
@@ -81,6 +88,7 @@
rm_r @fname
end
+ as_superuser do
platform_is :windows do
it "does not modify the owner id of the file" do
File.chown 0, nil, @fname
@@ -128,10 +136,10 @@
@file.stat.gid.should == 501
end
end
+ end
- it "returns 0" do
- @file.chown(nil, nil).should == 0
- end
+ it "returns 0" do
+ @file.chown(nil, nil).should == 0
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.