Skip to content

Commit

Permalink
Fixes #2048
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Dec 10, 2014
1 parent 2f56d95 commit 00e8c00
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyFileStat.java
Expand Up @@ -117,7 +117,7 @@ private void setup(String filename, boolean lstat) {
file = JRubyFile.createResource(runtime.getPosix(), runtime.getCurrentDirectory(), filename);
stat = lstat ? file.lstat() : file.stat();

if (stat == null) throw runtime.newErrnoFromInt(runtime.getPosix().errno(), filename);
if (stat == null) throw runtime.newErrnoFromInt(file.errno(), filename);
}

@JRubyMethod(name = "initialize", required = 1, visibility = Visibility.PRIVATE, compat = CompatVersion.RUBY1_8)
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/util/AbstractFileResource.java
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import jnr.constants.platform.Errno;

abstract class AbstractFileResource implements FileResource {

Expand All @@ -10,6 +11,10 @@ public boolean canExecute() {
return false;
}

public int errno() {
return Errno.ENOENT.intValue();
}

@Override
public InputStream inputStream() throws ResourceException {
if (!exists()) {
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/util/EmptyFileResource.java
@@ -1,5 +1,6 @@
package org.jruby.util;

import jnr.constants.platform.Errno;
import jnr.posix.FileStat;
import jnr.posix.POSIX;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -32,6 +33,10 @@ public boolean exists() {
return false;
}

public int errno() {
return Errno.ENOENT.intValue();
}

@Override
public boolean isDirectory() {
return false;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/FileResource.java
Expand Up @@ -18,6 +18,7 @@ public interface FileResource {
boolean isDirectory();
boolean isFile();
boolean canExecute();
int errno();

long lastModified();
long length();
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/util/JarResource.java
@@ -1,7 +1,6 @@
package org.jruby.util;

import jnr.posix.FileStat;
import jnr.posix.POSIX;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/util/RegularFileResource.java
Expand Up @@ -72,6 +72,10 @@ public boolean canExecute() {
return file.canExecute();
}

public int errno() {
return posix.errno();
}

@Override
public boolean isFile() {
return file.isFile();
Expand Down

0 comments on commit 00e8c00

Please sign in to comment.