Skip to content

Commit

Permalink
fixes JRUBY-4859: File.delete doesn't throw an error when deleting a …
Browse files Browse the repository at this point in the history
…directory
  • Loading branch information
calavera committed Jun 9, 2010
1 parent 8dc285e commit 71aa55d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/org/jruby/Ruby.java
Expand Up @@ -3071,6 +3071,10 @@ public RaiseException newErrnoEISDirError(String message) {
return newRaiseException(getErrno().fastGetClass("EISDIR"), message);
}

public RaiseException newErrnoEPERMError(String name) {
return newRaiseException(getErrno().fastGetClass("EPERM"), "Operation not permitted - " + name);
}

public RaiseException newErrnoEISDirError() {
return newErrnoEISDirError("Is a directory");
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/jruby/RubyFile.java
Expand Up @@ -1653,6 +1653,10 @@ public static IRubyObject unlink(ThreadContext context, IRubyObject recv, IRubyO
throw runtime.newErrnoENOENTError(filename.toString());
}

if (lToDelete.isDirectory()) {
throw runtime.newErrnoEPERMError(filename.toString());
}

if (!lToDelete.delete()) {
throw runtime.newErrnoEACCESError(filename.toString());
}
Expand Down
10 changes: 10 additions & 0 deletions test/test_file.rb
Expand Up @@ -978,4 +978,14 @@ def test_file_stat_with_missing_path
File::Stat.new("file:" + File.expand_path("test/test_jar2.jar") + "!/foo_bar.rb").file?
}
end

# JRUBY-4859
def test_file_delete_directory
Dir.mkdir("dir_tmp")
assert_raise(Errno::EPERM) {
File.delete "dir_tmp"
}
ensure
Dir.rmdir("dir_tmp")
end
end

0 comments on commit 71aa55d

Please sign in to comment.